代码1:
OPEN P_CURSOR FOR V_STR_SQL2
USING P_USER_ID, P_USER_ID, V_NODEID, V_PROCID, V_ADDRESSE;
输出:0,0,0,0
当我将此代码更改为:
V_STR_SQL2 := replace(V_STR_SQL2,':P_USER_ID',P_USER_ID);
V_STR_SQL2 := replace(V_STR_SQL2,':V_NODEID',V_NODEID);
V_STR_SQL2 := replace(V_STR_SQL2,':V_PROCID',V_PROCID);
V_STR_SQL2 := replace(V_STR_SQL2,':V_ADDRESSE',V_ADDRESSE);
OPEN P_CURSOR FOR V_STR_SQL2;
输出:1,0,0,0
第二个输出是正确的。可能是什么原因?任何想法?绑定变量的数据类型如下。
- 用户 ID varchar2,输入
- nodeid,procid,数字(10)
- 地址 varchar2(250);
-- 编辑
当我调试我的存储过程时,这是执行打开游标之前 v_str_sql2 的值。当我通过在 sqldeveloper 中给出它的值来运行这个查询时,它给了我正确的结果。但开放使用的错误结果。
SELECT COUNT(DECODE(ZC.STATUS, NULL, 1)) "NEW",
COUNT(DECODE(ZC.STATUS, 'KEEP', 1)) "KEEP",
COUNT(DECODE(ZC.STATUS, 'LOCK', 1)) "LOCK",
COUNT(DECODE(ZC.STATUS,
'KEEP',
DECODE(UPPER(ZC.STATUS_BY), UPPER(:P_USER_ID), 1))) "PKEEP",
COUNT(DECODE(ZC.STATUS,
'LOCK',
DECODE(UPPER(ZC.STATUS_BY), UPPER(:P_USER_ID), 1))) "PLOCK"
FROM tab1 PARTITION(DCL_OTHERS) DCL,
tab2 ZC,
tab3 TC
WHERE DCL.NODE_ID = TC.NODE_ID
AND DCL.PROC_ID = TC.PROC_ID
AND DCL.CASE_REF_NO = TC.CLAIM_REF_NO
AND DCL.NODE_ID = ZC.NODE_ID(+)
AND DCL.PROC_ID = ZC.PROC_ID(+)
AND DCL.CASE_NAME = ZC.CASENUM(+)
AND DCL.USER_NAME = ZC.USERNAME(+)
AND DCL.NODE_ID = :V_NODEID
AND (DCL.PROC_ID = :V_PROCID)
AND (1 = 1)
AND DCL.USER_NAME = :V_ADDRESSE
编辑 2
我正在使用这种语法。这种语法有问题吗?
CREATE OR REPLACE PROCEDURE USP_HTH_QUEUEPAGE(P_QUEUENAME VARCHAR2,
P_CURSOR OUT SYS_REFCURSOR,
P_REC_CNT OUT NUMBER) IS
BEGIN
-- CODE TO GENERATE DYNAMIC SQL
OPEN P_CURSOR FOR V_STR_SQL1
USING V_ADDRESSE, V_NODEID, V_PROCID, V_STATUS, V_USER_ID, P_EP, P_SP;
/*END IF;*/
EXECUTE IMMEDIATE V_STR_SQL2
INTO P_REC_CNT
USING V_NODEID, V_PROCID, V_USER_ID, V_STATUS, V_ADDRESSE;
END;