Oracle ORA-06502:PL/SQL:ORA\u SQL\u txt(ORA\u name\u list\t)导致的数字或值错误

Oracle ORA-06502:PL/SQL:ORA\u SQL\u txt(ORA\u name\u list\t)导致的数字或值错误,oracle,plsql,triggers,Oracle,Plsql,Triggers,表: 触发: create table EMPLOYEES_LOG ( who VARCHAR2(300), when DATE, action VARCHAR2(2000) ) 执行: create or replace trigger aiud_employees_copy after insert or update or delete on employees_copy declare l_action employees_log.action%

表:

触发:

create table EMPLOYEES_LOG
(
  who    VARCHAR2(300),
  when   DATE,
  action VARCHAR2(2000)
)
执行:

create or replace trigger aiud_employees_copy
  after insert or update or delete
  on employees_copy 
declare
    l_action employees_log.action%type;
    l_sql_text ora_name_list_t;
begin
    l_action := 'The statement that causes the change was:' || chr(10);

    for i in 1..ora_sql_txt(l_sql_text) loop
        l_action := l_action || l_sql_text(i);
    end loop;
    insert into employees_log(who, action, when)
        values(user, l_action, sysdate);
end aiud_employees_copy;
给我一个错误:

ORA-06502:PL/SQL:1..ORA_SQL_txt(l_SQL_text)循环中的i在处出现数字或值错误

谢谢。

它有一个OUT参数并返回pls\u整数个元素。该文档显示它被分配给一个变量:

update employees_copy set salary=salary*1.05 where department_id=20;
因此:

。。。尽管直接引用它应该是可行的

但是
ora\u sql\u txt()
用于系统事件触发器;对于DML触发器,它将返回null(除了某些版本的9i,这似乎是无意的;请参阅错误4230721)。该函数在文档的第二部分中有描述,它清楚地表明它们仅适用于某些数据库和客户端事件

通过调用表9-4中系统定义的事件属性函数,触发器可以检索触发事件的某些属性。并非所有触发器都可以调用所有事件属性函数,有关详细信息,请参阅和


因此,
ora\u sql\u txt(l\u sql\u text)
将为空,这是您得到的值错误。如果你先把它分配给一个变量,你仍然会得到一个错误。您可以
nvl()
将其设置为零,但由于它将始终为空(因此一旦设置为零行),这有点毫无意义。

向我们展示oracle中ora_name_list_tIt的系统定义事件属性的声明。感谢您的回答。它给了我一个错误:
ORA-06531:引用未初始化的集合
@zhanzezhu-您将无法获得用于更新的语句;它用于系统事件,而不是DML。
    l_n := ora_sql_txt(l_sql_text);
    for i in 1..l_sql_text.count loop
create or replace trigger aiud_employees_copy
  after insert or update or delete
  on employees_copy 
declare
    l_action employees_log.action%type;
    l_sql_text ora_name_list_t;
    l_n pls_integer;
begin
    l_action := 'The statement that causes the change was:' || chr(10);

    l_n := ora_sql_txt(l_sql_text);
    for i in 1..l_sql_text.count loop
        l_action := l_action || l_sql_text(i);
    end loop;
    insert into employees_log(who, action, when)
        values(user, l_action, sysdate);
end aiud_employees_copy;
/