oci_new_cursor

from http://www.iteedu.com/webtech/php/phpmanual/function.oci-new-cursor.php

oci_new_cursor

(PHP 5)

oci_new_cursor -- 分配并返回一个新的游标(语句句柄)

说明

resource oci_new_cursor ( resource connection )

oci_new_cursor() 在指定的连接上分配一个新的语句句柄。

例子 1. 在 Oracle 的存储过程中使用 REF CURSOR

<?php
// suppose your stored procedure info.output returns a ref cursor in :data

$conn = oci_connect("scott", "tiger");
$curs = oci_new_cursor($conn);
$stmt = oci_parse($conn, "begin info.output(:data); end;");

oci_bind_by_name($stmt, "data", $curs, -1, OCI_B_CURSOR);
oci_execute($stmt);
oci_execute($curs);

while (
$data = oci_fetch_row($curs)) {
    
var_dump($data);
}

oci_free_statement($stmt);
oci_free_statement($curs);
oci_close($conn);
?>

例子 2. 在 Oracle 的 select 语句中使用 REF CURSOR

<?php
echo "<html><body>";
$conn = oci_connect("scott", "tiger");
$count_cursor = "CURSOR(select count(empno) num_emps from emp " .
                
"where emp.deptno = dept.deptno) as EMPCNT from dept";
$stmt = oci_parse($conn, "select deptno,dname,$count_cursor");

oci_execute($stmt);
echo
"<table border=\"1\">";
echo
"<tr>";
echo
"<th>DEPT NAME</th>";
echo
"<th>DEPT #</th>";
echo
"<th># EMPLOYEES</th>";
echo
"</tr>";

while (
$data = oci_fetch_assoc($stmt)) {
    echo
"<tr>";
    
$dname  = $data["DNAME"];
    
$deptno = $data["DEPTNO"];
    echo
"<td>$dname</td>";
    echo
"<td>$deptno</td>";
    
oci_execute($data["EMPCNT"]);
    while (
$subdata = oci_fetch_assoc($data["EMPCNT"])) {
        
$num_emps = $subdata["NUM_EMPS"];
        echo  
"<td>$num_emps</td>";
    }
    echo
"</tr>";
}
echo
"</table>";
echo
"</body></html>";
oci_free_statement($stmt);
oci_close($conn);
?>

oci_new_cursor() 如果出错返回 FALSE

注: 在 PHP 5.0.0 之前的版本必须使用 ocinewcursor() 替代本函数。该函数名仍然可用,为向下兼容作为 oci_new_cursor() 的别名。不过其已被废弃,不推荐使用。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值