PLS-00103:预期以下情况之一时遇到符号“ EXECUTE”:

时间:2019-09-24 06:59:39

标签: oracle

有人可以让我知道代码中的问题在哪里吗?

SET SERVEROUTPUT ON;
    daclare 
    sql_stmt varchar(500);
    n number(3);
    n :=0;
    begin
    FOR vori IN (select ri from voucher_p1 where vchstate=chr(4))
    LOOP
        sql_stmt := 'select count(sernum) from voucher_p1 where ENCPIN in ( select ENCPIN from voucher_p1 where ri=' || vori.ri || ')'
        EXECUTE immediate sql_stmt into n;
        DBMS_OUTPUT.PUT_LINE( 'Column Variable: ' || n );
    END LOOP;
    end;
    /

我在oracle 9.2.0中运行它,并重新调整此消息,如下所示:

EXECUTE immediate sql_stmt into n;
*
ERROR at line 5:
ORA-06550: line 5, column 1:
PLS-00103: Encountered the symbol "EXECUTE" when expecting one of the
following:
. ( * @ % & = - + ; < / > at in is mod not rem
<an exponent (**)> <> or != or ~= >= <= <> and or like
between ||

1 个答案:

答案 0 :(得分:0)

我运行起来。谢谢大家。

SET SERVEROUTPUT ON;
declare 
sql_stmt varchar2(500);
n number(3);
begin
FOR vori IN (select ri from voucher_p1 where vchstate=chr(4))
LOOP
    DBMS_OUTPUT.PUT_LINE('select count(*) from voucher_p1 where ENCPIN in ( select ENCPIN from voucher_p1 where ri=' || vori.ri || ')');
    sql_stmt := 'select count(*) from voucher_p1 where ENCPIN in ( select ENCPIN from voucher_p1 where ri=' || vori.ri || ')';
    EXECUTE immediate sql_stmt into n;
    DBMS_OUTPUT.PUT_LINE(n);
END LOOP;
end;
/