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