<?php
echo "<html><body>";
$conn = OCILogon("scott", "tiger");
$count_cursor = "CURSOR(select count(empno) num_emps from emp " .
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt = OCIParse($conn, "select deptno,dname,$count_cursor");
ociexecute($stmt);
echo "<table border=\"1\">";
echo "<tr>";
echo "<th>DEPT NAME</th>";
echo "<th>DEPT #</th>";
echo "<th># EMPLOYEES</th>";
echo "</tr>";
while (OCIFetchInto($stmt, &$data, OCI_ASSOC)) {
echo "<tr>";
$dname = $data["DNAME"];
$deptno = $data["DEPTNO"];
echo "<td>$dname</td>";
echo "<td>$deptno</td>";
ociexecute($data["EMPCNT"]);
while (OCIFetchInto($data["EMPCNT"], &$subdata, OCI_ASSOC)) {
$num_emps = $subdata["NUM_EMPS"];
echo "<td>$num_emps</td>";
}
echo "</tr>";
}
echo "</table>";
echo "</body></html>";
OCIFreeStatement($stmt);
OCILogoff($conn);
?>