如何使用Execute Immediate填充输出变量

时间:2014-12-03 13:34:46

标签: oracle plsql

我将存储过程从Transact-SQL移植到Oracle,我有以下构造,必须在游标循环中使用动态SQL:

open curRBL
--iterate over cursor rows of interest, and execute a query to evaluate a rule for each row.
fetch next from curRBL into varLimitNumber, varComponentRow, varComponentColumn, varFilterString
while curRBL%FOUND
begin
     --count the matching current sample records
    set varRBLSqlQuery = 'select count(*) into :1 from samples where samplecode= :2  and auditflag=0 and :3 ';

    execute immediate varRBLSqlQuery using varResult, varSampleCode, varFilterString; <--doesn't work as I need

    if varResult>0
    --do something with the current cursor row...
    begin
      --some code goes here
    end;
fetch next from curRBL into varLimitNumber, varComponentRow, varComponentColumn, varFilterString;
end; --cursor loop

我的问题是,我不知道如何从动态查询中将 count()*转换为我的本地变量 varResult (我的第5行&amp; 6以上不在这方面工作)。有人可以建议吗?

2 个答案:

答案 0 :(得分:0)

set varRBLSqlQuery = 'select count(*) into varResult from samples where samplecode= :1  and auditflag=0 and :2 ';

execute immediate varRBLSqlQuery using varSampleCode, varFilterString;

试试这个..顺便说一下最后的输入是什么?您正在发送参数但是将其与什么进行比较?

答案 1 :(得分:0)

试试这个:

...
varRBLSqlQuery := 'select count(*) from samples where samplecode= :1  and auditflag=0 and :2 ';
execute immediate varRBLSqlQuery into varResult using varSampleCode, varFilterString;
...