Oracle 错误的绑定变量,忽略的语句和一个错误
Oracle bad bind variable , Statement ignored and one more error
我是 Oracle 的新手,我尝试编写我的第一个真正的触发器,但是有一些错误...:(
这是我的代码:
create or replace TRIGGER CUSTERP_ABILITYVALUECODES_TRG
BEFORE INSERT OR UPDATE OF CODE OR DELETE ON ABILITYVALUECODES
REFERENCING NEW AS newest OLD AS oldest
FOR EACH ROW
declare s varchar2(4096);
BEGIN
if :oldest.CODE <> :newest.CODE then
if :newest.CODE is null then
s := 'NULL';
else
s := ASCIISTR(:newest.CODE);
end if;
s:= utl_url.escape(s);
if :newest.CODE is null then
CUSTERP_TRG('T_ABILITYVALUECODES', concat('C_CODE;KEY: ABILITYVALUE = ', :oldest.ABILITYVALUE, ',OLD:', :oldest.CODE, ',NEW:', s));
else
CUSTERP_TRG('T_ABILITYVALUECODES', concat('C_CODE;KEY: ABILITYVALUE =', :newest.ABILITYVALUE, ',OLD:', :oldest.CODE, ',NEW:', s));
end if;
end if;
END;
我遇到了这些错误:
Error(11,13): PL/SQL: Statement ignored (seems like it refers to s:=...)
错误(11,53):PLS-00306:调用 'CONCAT'
时参数的数量或类型错误
如果我喜欢:
s := 'NULL';
我得到:错误(6,13):PLS-00049:错误的绑定变量'S'
提前致谢!
报错信息中说的很清楚。 Error is in concat function that you are using to call method- CUSTERP_TRG.
CONCAT
函数只接受两个字符串参数。
如果您想连接两个以上的参数,您需要多次使用 CONCAT 函数。
您正在使用 Oracle,所以您应该使用管道 - ||
进行串联。
我假设 ABILITYVALUE 和 CODE 列的类型为 CHAR、VARCHAR 或 VARCHAR2。如果它们是 INT,那么您可能需要使用 TO_CHAR。
将 TRIGGER 中的 if-else 块替换为以下代码。
if :newest.CODE is null then
CUSTERP_TRG( 'T_ABILITYVALUECODES', 'C_CODE;KEY: ABILITYVALUE = ' || :oldest.ABILITYVALUE || ',OLD:' || :oldest.CODE || ',NEW:' || s );
else
CUSTERP_TRG( 'T_ABILITYVALUECODES', 'C_CODE;KEY: ABILITYVALUE =' || :newest.ABILITYVALUE || ',OLD:' || :oldest.CODE || ',NEW:' || s );
end if;
我是 Oracle 的新手,我尝试编写我的第一个真正的触发器,但是有一些错误...:(
这是我的代码:
create or replace TRIGGER CUSTERP_ABILITYVALUECODES_TRG
BEFORE INSERT OR UPDATE OF CODE OR DELETE ON ABILITYVALUECODES
REFERENCING NEW AS newest OLD AS oldest
FOR EACH ROW
declare s varchar2(4096);
BEGIN
if :oldest.CODE <> :newest.CODE then
if :newest.CODE is null then
s := 'NULL';
else
s := ASCIISTR(:newest.CODE);
end if;
s:= utl_url.escape(s);
if :newest.CODE is null then
CUSTERP_TRG('T_ABILITYVALUECODES', concat('C_CODE;KEY: ABILITYVALUE = ', :oldest.ABILITYVALUE, ',OLD:', :oldest.CODE, ',NEW:', s));
else
CUSTERP_TRG('T_ABILITYVALUECODES', concat('C_CODE;KEY: ABILITYVALUE =', :newest.ABILITYVALUE, ',OLD:', :oldest.CODE, ',NEW:', s));
end if;
end if;
END;
我遇到了这些错误: Error(11,13): PL/SQL: Statement ignored (seems like it refers to s:=...) 错误(11,53):PLS-00306:调用 'CONCAT'
时参数的数量或类型错误如果我喜欢:
s := 'NULL';
我得到:错误(6,13):PLS-00049:错误的绑定变量'S'
提前致谢!
报错信息中说的很清楚。 Error is in concat function that you are using to call method- CUSTERP_TRG.
CONCAT
函数只接受两个字符串参数。
如果您想连接两个以上的参数,您需要多次使用 CONCAT 函数。
您正在使用 Oracle,所以您应该使用管道 - ||
进行串联。
我假设 ABILITYVALUE 和 CODE 列的类型为 CHAR、VARCHAR 或 VARCHAR2。如果它们是 INT,那么您可能需要使用 TO_CHAR。
将 TRIGGER 中的 if-else 块替换为以下代码。
if :newest.CODE is null then
CUSTERP_TRG( 'T_ABILITYVALUECODES', 'C_CODE;KEY: ABILITYVALUE = ' || :oldest.ABILITYVALUE || ',OLD:' || :oldest.CODE || ',NEW:' || s );
else
CUSTERP_TRG( 'T_ABILITYVALUECODES', 'C_CODE;KEY: ABILITYVALUE =' || :newest.ABILITYVALUE || ',OLD:' || :oldest.CODE || ',NEW:' || s );
end if;