执行过程时出现 Oracle PLS-00357 错误

Oracle PLS-00357 error when executing procedure

这是我的程序代码:

drop procedure CREATE_SEQUENTIAL_TR;
CREATE OR REPLACE procedure CREATE_SEQUENTIAL_TR(table_name_pr VARCHAR)
is
    coluna_cod varchar(100 char);
begin
    select 
        COLUMN_NAME 
    into
        coluna_cod
    from 
        ALL_TAB_COLUMNS 
    where 
        TABLE_NAME = table_name_pr 
        and COLUMN_NAME like 'PK_CD%';

    execute immediate '
    drop sequence cod_' || table_name_pr ||';
    create sequence cod_' || table_name_pr ||';';

    execute immediate '
    drop trigger cod_' || table_name_pr || '_tr;
    create or replace trigger cod_' || table_name_pr || '_tr            
    before 
        UPDATE or INSERT on ' || table_name_pr || '
    for each row
    begin
        if UPDATING then
            if :new.' || coluna_cod ||' != :old.' || coluna_cod ||' then
                :new.' || coluna_cod ||' := :old.' || coluna_cod ||';
            end if;
        else -- inserting
            :new.' || coluna_cod ||' := cod_' || table_name_pr || '.nextval();
        end if; 
    end;';
end;

错误是我执行的时候:

--test_trigger_cod is a table name
execute create_sequential_tr(test_trigger_cod)

错误是

PLS-00357: Table, View Or Sequence reference 'test_trigger_cod' not allowed in this context

where里面的参数好像不能用?解决方法是什么?

完全错误(人工翻译):

Error starting from line : 1 on the command -
BEGIN create_sequential_tr(teste_trigger_cod); END;
Error report: -
ORA-06550: line 1, column 28:
PLS-00357: Reference 'TESTE_TRIGGER_COD' to Table, View ou Sequence not allowed in this context
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

EXECUTE IMMEDIATE 运行单个 SQL 语句。您试图在每次调用时执行多个语句。所以你需要把这个...

execute immediate '
    drop sequence cod_' || table_name_pr ||';
    create sequence cod_' || table_name_pr ||';'; 

...进入这个:

execute immediate 'drop sequence cod_' || table_name_pr ;
execute immediate 'create sequence cod_' || table_name_pr ;

对触发器语句执行相同的操作。

一般来说,动态 SQL 很难,因为编译错误会变成运行时错误。让自己轻松一点,并使用变量来 assemble 语句;这种方法为您提供了一些支持调试的东西,例如:

l_stmt := 'drop sequence cod_' || table_name_pr ;
dbms_output.put_line('about to execute :: ' || l_stmt);
execute immediate l_stmt ;