执行存储过程时,我对错误感到困惑。错误是“无效的关系运算符”:
...
DECLARE
varResult integer;
varFilterString varchar2(1000);
varSampleCode nvarchar2(80);
begin
--debug values
varFilterString := 'auditflag=0' ;
varSampleCode := 's00083';
--this command gives the runtime error:
execute immediate 'select count(*) from samples where samplecode = :samplecode and auditflag = 0 and :filter'
into varResult
using varSampleCode, varFilterString ;
...
PL / SQL不是我经常做的事情,我很困惑。这条线有什么问题?
TIA
答案 0 :(得分:0)
它不喜欢和:filter,你不能将整个条件作为字符串传递,你只能传递参数来绑定。要解决此问题,只需要直接附加字符串,而不是将其作为参数传递。
execute immediate 'select count(*) from samples where samplecode = :samplecode and auditflag = 0 and ' || REPLACE(varFilterString, '''', '''''')
into varResult
using varSampleCode;