PHP 8.3.4 Released!

oci_get_implicit_resultset

(PHP 5 >= 5.6.0, PHP 7, PHP 8, PECL OCI8 >= 2.0.0)

oci_get_implicit_resultsetRetourne le fils suivant d'une ressource de requête depuis une ressource de requête parent qui a un jeu de résultat implicite Oracle Database

Description

oci_get_implicit_resultset(resource $statement): resource|false

Utilisé pour récupérer des jeux récursifs de résultats de requêtes après l'exécution d'un bloc stocké ou anonyme Oracle PL/SQL où ce bloc retourne des résultats de requêtes avec la fonction DBMS_SQL.RETURN_RESULT Oracle PL/SQL de la base de donnée Oracle 12 (ou ultérieur). Ceci permet aux blocs PL/SQL de retourner facilement des résultats de requêtes.

La requête fils peut être utilisée avec n'importe laquelle des fonctions de récupération OCI8 : oci_fetch(), oci_fetch_all(), oci_fetch_array(), oci_fetch_object(), oci_fetch_assoc() ou oci_fetch_row()

Les requêtes fils héritent des valeurs pré-récupérées de leurs parents, ou elles peuvent être explicitement définies avec la fonction oci_set_prefetch().

Liste de paramètres

statement

Un identifiant de requête OCI8 valide créé par la fonction oci_parse() et exécutée par la fonction oci_execute(). L'identifiant de requête peut ou non être associé avec une requête OCI8 qui retourne des jeux de résultats implicites.

Valeurs de retour

Retourne un gestionnaire de requête pour la prochaine requête fils disponible sur statement. Retourne false lorsque la requête fils n'existe pas, ou que toutes les requêtes fils ont été retournées par de précédents appels à la fonction oci_get_implicit_resultset().

Exemples

Exemple #1 Récupèration des jeux de résultats implicites via une boucle

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/pdborcl');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$sql = 'DECLARE
c1 SYS_REFCURSOR;
BEGIN
OPEN c1 FOR SELECT city, postal_code FROM locations WHERE ROWNUM < 4 ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
OPEN c1 FOR SELECT country_id FROM locations WHERE ROWNUM < 4 ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
END;'
;

$stid = oci_parse($conn, $sql);
oci_execute($stid);

while ((
$stid_c = oci_get_implicit_resultset($stid))) {
echo
"<h2>Nouveau jeu de résultats implicite :</h2>\n";
echo
"<table>\n";
while ((
$row = oci_fetch_array($stid_c, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo
"<tr>\n";
foreach (
$row as $item) {
echo
" <td>".($item!==null?htmlentities($item, ENT_QUOTES|ENT_SUBSTITUTE):"")."</td>\n";
}
echo
"</tr>\n";
}
echo
"</table>\n";
}

// Affiche :
// Nouveau jeu de résultats implicite :
// Beijing 190518
// Bern 3095
// Bombay 490231
// Nouveau jeu de résultats implicite :
// CN
// CH
// IN

oci_free_statement($stid);
oci_close($conn);

?>

Exemple #2 Récupère individuellement les gestionnaires de requêtes fils

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/pdborcl');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$sql = 'DECLARE
c1 SYS_REFCURSOR;
BEGIN
OPEN c1 FOR SELECT city, postal_code FROM locations WHERE ROWNUM < 4 ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
OPEN c1 FOR SELECT country_id FROM locations WHERE ROWNUM < 4 ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
END;'
;

$stid = oci_parse($conn, $sql);
oci_execute($stid);

$stid_1 = oci_get_implicit_resultset($stid);
$stid_2 = oci_get_implicit_resultset($stid);

$row = oci_fetch_array($stid_1, OCI_ASSOC+OCI_RETURN_NULLS);
var_dump($row);
$row = oci_fetch_array($stid_2, OCI_ASSOC+OCI_RETURN_NULLS);
var_dump($row);
$row = oci_fetch_array($stid_1, OCI_ASSOC+OCI_RETURN_NULLS);
var_dump($row);
$row = oci_fetch_array($stid_2, OCI_ASSOC+OCI_RETURN_NULLS);
var_dump($row);

// Affichage :
// array(2) {
// ["CITY"]=>
// string(7) "Beijing"
// ["POSTAL_CODE"]=>
// string(6) "190518"
// }
// array(1) {
// ["COUNTRY_ID"]=>
// string(2) "CN"
// }
// array(2) {
// ["CITY"]=>
// string(4) "Bern"
// ["POSTAL_CODE"]=>
// string(4) "3095"
// }
// array(1) {
// ["COUNTRY_ID"]=>
// string(2) "CH"
// }

oci_free_statement($stid);
oci_close($conn);

?>

Exemple #3 Définission explicite du compteur de pré-récupération

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/pdborcl');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$sql = 'DECLARE
c1 SYS_REFCURSOR;
BEGIN
OPEN c1 FOR SELECT city, postal_code FROM locations ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
END;'
;

$stid = oci_parse($conn, $sql);
oci_execute($stid);

$stid_c = oci_get_implicit_resultset($stid);
oci_set_prefetch($stid_c, 200); // Set the prefetch before fetching from the child statement
echo "<table>\n";
while ((
$row = oci_fetch_array($stid_c, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo
"<tr>\n";
foreach (
$row as $item) {
echo
" <td>".($item!==null?htmlentities($item, ENT_QUOTES|ENT_SUBSTITUTE):"")."</td>\n";
}
echo
"</tr>\n";
}
echo
"</table>\n";

oci_free_statement($stid);
oci_close($conn);

?>

Exemple #4 Exemple de jeu de résultats implicite sans utiliser la fonction oci_get_implicit_resultset()

Tous les résultats de toutes les requêtes sont retournés consécutivement.

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/pdborcl');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$sql = 'DECLARE
c1 SYS_REFCURSOR;
BEGIN
OPEN c1 FOR SELECT city, postal_code FROM locations WHERE ROWNUM < 4 ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
OPEN c1 FOR SELECT country_id FROM locations WHERE ROWNUM < 4 ORDER BY city;
DBMS_SQL.RETURN_RESULT(c1);
END;'
;

$stid = oci_parse($conn, $sql);
oci_execute($stid);

// Note: oci_fetch_all and oci_fetch() cannot be used in this manner
echo "<table>\n";
while ((
$row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo
"<tr>\n";
foreach (
$row as $item) {
echo
" <td>".($item!==null?htmlentities($item, ENT_QUOTES|ENT_SUBSTITUTE):"")."</td>\n";
}
echo
"</tr>\n";
}
echo
"</table>\n";

// Affichage :
// Beijing 190518
// Bern 3095
// Bombay 490231
// CN
// CH
// IN

oci_free_statement($stid);
oci_close($conn);

?>

Notes

Note:

Pour les requêtes retournant un très grand nombre de lignes, les performances peuvent être très grandement accrues en augmentant la valeur de l'option oci8.default_prefetch ou en utilisant la fonction oci_set_prefetch().

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top