Oracle SQL-ORA-04079:无效的触发器插入

问题描述 投票:0回答:1

[我试图创建一个触发器,当我在表'cuenta'中插入并在表'cuenta_log'中进行插入时运行,此插入的值之一是通过接受输入获得的。

create or replace trigger trigger_new_account                
    AFTER INSERT ON cuenta  FOR EACH ROW
    accept vstring prompt "Please enter your name: ";
    declare v_line varchar2(50);
    begin
        v_line:= 'Hello '||'&vstring';
        insert into cuentas_log (fecha,cuenta,cliente)
        values (now(),:new.idcuenta,v_line);

    end;

cuenta_log结构是这样的:

cuenta_log 
 ("FECHA"   DATE DEFAULT (sysdate), 
  "CUENTA"  NUMBER(38,0),   
  "CLIENTE" VARCHAR2(50 BYTE)
 )    
plsql oracle11g
1个回答
0
投票

触发某些事件时触发;您的,插入到名为cuenta的表中之后。与最终用户interactively不起作用。您不能期望它会提示任何人输入任何内容。此外,accept是SQL * Plus命令,在PL / SQL中不起作用。

所以,这就是您可能要做的事情:首先采样表:

SQL> create table cuenta (fecha date, cuenta number);

Table created.

SQL> create table cuenta_log (fecha date, cuenta number, cliente varchar2(30));

Table created.

触发器:

SQL> create or replace trigger trigger_new_account
  2    after insert on cuenta
  3    for each row
  4  begin
  5    insert into cuenta_log(fecha, cuenta, cliente)
  6    values
  7    (sysdate, :new.cuenta, 'Hello ' || user);
  8  end;
  9  /

Trigger created.

测试:

SQL> insert into cuenta (fecha, cuenta) values (sysdate, 100);

1 row created.

SQL> select * From cuenta;

FECHA                   CUENTA
------------------- ----------
11.05.2020 12:31:17        100

SQL> select * From cuenta_log;

FECHA                   CUENTA CLIENTE
------------------- ---------- ------------------------------
11.05.2020 12:31:17        100 Hello SCOTT

SQL>
© www.soinside.com 2019 - 2024. All rights reserved.