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