drvpvmz16241016 2018-10-03 09:36
浏览 94

如何使用PHP中的任何方法(oci / pdo)将包含字符串的数组包含到oracle查询(IN子句)中?

I have an array as the described below :

array is $number

array(84) { [0]=> string(0) "" [1]=> string(10) "12345678" [2]=> string(10) "12345679" [3]=> string(10) "12345610" [4]=> string(10) "12345611" [5]=> string(10) "12345612" [6]=> string(10) "12345613" [7]=> string(10) "12345614"}

Now, I want to make the array bind to my sql query as the desribed below :

$sql = " SELECT    id, 
    FROM      cust_data
    WHERE     whatever IN (:number)";

I've tried using the following method :

$stid = oci_parse($conn, $sql); //Query SQL    
$idCollection = oci_new_collection($conn, 'ODCINUMBERLIST', 'SYS');
    foreach ($number as $num) {
        $idCollection->append($num);
    }
    oci_bind_by_name($stid, ':number', $idCollection,-1, SQLT_NTY);
    oci_execute($stid, OCI_DEFAULT);
    oci_fetch_all($stid,$result);
    var_dump( $result);

But it just give me the result

array(0) { }

Thank you.

  • 写回答

1条回答 默认 最新

  • douliao5942 2018-10-30 15:02
    关注

    See "Binding Multiple Values in an IN Clause" p p169 of the free book from Oracle https://www.oracle.com/technetwork/topics/php/underground-php-oracle-manual-098250.html

    In summary, for a small number of values, use a fixed SQL string with bind variables. Bind null if there are fewer data values than actual bind variables in the SQL. For bigger lists you can build up a SQL string: but still use bind variables.

    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致