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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容