oci_execute返回错误的count(*)值

时间:2016-10-15 11:30:55

标签: php oracle

我正在尝试计算包含特定数据的行数。在这种情况下,我使用绑定变量来执行任务。

<?php

$aid = 1;
$shortName = "TroubleMgt";
$description = "Trouble Management";
$type = "TroubleMgt";

# Lets assume I have already successfully connected to my database
$stid = oci_parse($cnx,"select count(*) TOTAL from aradmin.activities where aid = :aid and shortName = :shortName and description = :description and type = :type");

oci_bind_by_name($stid, ':aid', $aid);
oci_bind_by_name($stid, ':shortName', $shortName);
oci_bind_by_name($stid, ':description', $description);
oci_bind_by_name($stid, ':type', $type);

oci_execute($stid);

$total = oci_fetch_assoc($stid)['TOTAL'];

print $total."\n";
?>

打印4(错误)

有趣的是,当我在同一个表中的同一个数据库中使用Oracle时,我按预期得到1(只有一行应该匹配)。

SQL> var aid number
SQL> var shortName varchar2(254)
SQL> var description varchar2(4000)
SQL> var type varchar2(254)
SQL> begin
  2  select 1,'TroubleMgt','Trouble Management','TroubleMgt' into :aid,:shortName,:description,:type from dual;
  3  end;
  4  /

PL/SQL procedure successfully completed.

SQL> select count(*) TOTAL from aradmin.activities where aid = :aid and shortName = :shortName and description = :description and type = :type;

     TOTAL
----------
         1

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:-1)

尚未在sqlplus窗口中提交删除命令。生活和学习。