1--TEST-- 2Oracle Database 12c Implicit Result Sets: oci_get_implicit_resultset: nested cursor 3--EXTENSIONS-- 4oci8 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8$target_dbs = array('oracledb' => true, 'timesten' => false); // test runs on these DBs 9require __DIR__.'/skipif.inc'; 10preg_match('/.*Release ([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)*/', oci_server_version($c), $matches); 11if (!(isset($matches[0]) && $matches[1] >= 12)) { 12 die("skip expected output only valid when using Oracle Database 12c or greater"); 13} 14preg_match('/^[[:digit:]]+/', oci_client_version(), $matches); 15if (!(isset($matches[0]) && $matches[0] >= 12)) { 16 die("skip works only with Oracle 12c or greater version of Oracle client libraries"); 17} 18?> 19--FILE-- 20<?php 21 22require __DIR__.'/connect.inc'; 23 24// Initialization 25 26$stmtarray = array( 27 "drop table imp_res_get_cursor_tab_1", 28 "create table imp_res_get_cursor_tab_1 (c1 number, c2 varchar2(10))", 29 "insert into imp_res_get_cursor_tab_1 values (1, 'abcde')", 30 "insert into imp_res_get_cursor_tab_1 values (2, 'fghij')", 31 "insert into imp_res_get_cursor_tab_1 values (3, 'klmno')", 32 33 "drop table imp_res_get_cursor_tab_2", 34 "create table imp_res_get_cursor_tab_2 (c3 varchar2(1))", 35 "insert into imp_res_get_cursor_tab_2 values ('t')", 36 "insert into imp_res_get_cursor_tab_2 values ('u')", 37 "insert into imp_res_get_cursor_tab_2 values ('v')", 38 39 "create or replace procedure imp_res_get_cursor_proc as 40 c1 sys_refcursor; 41 begin 42 open c1 for select cursor(select c1, c2 from imp_res_get_cursor_tab_1 order by 1) as curs from dual; 43 dbms_sql.return_result(c1); 44 45 open c1 for select * from imp_res_get_cursor_tab_2 where rownum < 3 order by 1; 46 dbms_sql.return_result(c1); 47 48 open c1 for select * from dual; 49 dbms_sql.return_result (c1); 50 end;" 51); 52 53oci8_test_sql_execute($c, $stmtarray); 54 55function do_fetch($s) 56{ 57 while (($row = oci_fetch_assoc($s)) != false) { 58 foreach ($row as $item) { 59 if (is_resource($item)) { // Nested cursor 60 oci_execute($item); 61 do_fetch($item); 62 } else { 63 echo " ".$item; 64 } 65 } 66 echo "\n"; 67 } 68} 69 70// Run Test 71 72echo "Test 1\n"; 73 74$s = oci_parse($c, "begin imp_res_get_cursor_proc(); end;"); 75oci_execute($s); 76 77while (($s1 = oci_get_implicit_resultset($s))) { 78 do_fetch($s1); 79} 80 81// Clean up 82 83$stmtarray = array( 84 "drop procedure imp_res_get_cursor_proc", 85 "drop table imp_res_get_cursor_tab_1", 86 "drop table imp_res_get_cursor_tab_2" 87); 88 89oci8_test_sql_execute($c, $stmtarray); 90 91?> 92--EXPECT-- 93Test 1 94 1 abcde 95 2 fghij 96 3 klmno 97 98 t 99 u 100 X 101