donglian5309 2019-04-03 07:33
浏览 48

如何使用codeigniter调用具有in和out参数的oracle存储过程?

I already setup the codeigniter dbdriver to "oci8".

For reference, here's my stored procedure. This is just my sample stored procedure.

CREATE OR REPLACE STORED PROCEDURE sp_sample(
in_id IN VARCHAR2, 
out_code OUT varchar, 
out_desc OUT varchar) IS

var_result VARCHAR2(100);

CURSOR GetStatus (my_id IN NUMBER) IS
SELECT status
FROM tbl_sample
WHERE id= my_id;

BEGIN
     OPEN GetStatus(in_id);
           LOOP
     FETCH GetStatus into var_result;
     EXIT WHEN GetStatus%NOTFOUND;
           END LOOP;
     CLOSE GetStatus;

     IF(result != 'A')
          UPDATE tbl_sample SET status = 'A'
          WHERE id = in_id;

          COMMIT;

          out_code := '00';
          out_desc := 'Success';
     ELSE
          out_code := '01';
          out_desc := 'Already active';
     END IF;
END sp_sample;

And this is how I call the stored proc in codeigniter:

$id = '10';
$params = array($id);
$result = $this->db->query("CALL sp_sample(?, @out_code, @out_desc)", $params);

exit($result);

Then I get this error message:

Query error: ORA-00936: missing expression - Invalid query: CALL sp_sample('10', @out_code, @out_code)

My question now is how can I call the oracle stored procedure using codeigniter? How to bind the parameters correctly?

Thanks, Irvin

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教