nested_cursor1.htm
Objective: This example is created with PHP Interface
Script":

<?php

// Connects to the XE service (i.e. database) on the "localhost" machine
$conn = oci_connect('hr', 'Son', 'localhost/orcl.gateway.2wire.net');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
echo" DB connected: querying a table <br/>";
$sql ='select department_name,
cursor(select first_name
from employees
where employees.department_id = departments.department_id) as
nc
from departments
where department_id in (10, 20, 30)';
$s = oci_parse($conn, $sql);
$r = oci_execute($s);
while (($row1 = oci_fetch_array($s, OCI_ASSOC)) != false) {
echo "Department: " . $row1['DEPARTMENT_NAME'] . "<br>\n";
$nc = $row1['NC']; // treat as a statement resource
oci_execute($nc);
while (($row2 = oci_fetch_array($nc, OCI_ASSOC+OCI_RETURN_NULLS)) != false) {
echo $row2['FIRST_NAME'] . "<br>\n";
}
oci_free_statement($nc);
echo "<br>\n";
}

?>

Runtime View