在oracle的同一个表中通过触发器更新新的插入记录。
-------CODE----------
CREATE OR REPLACE TRIGGER Update_CCID
AFTER INSERT
ON XXAW.XXAW_AR_INV_STG_T_TEST
referencing OLD as old NEW as new
FOR EACH ROW
BEGIN
If :new.Account_Name like '%.VAT%'
then
:new.segment2 := '000';
:new.segment4 := '000';
:new.segment5 := '622';
end if;
END ;
-------------------------------
我收到以下错误:
[Error] PLS-00103 (8: 29): PLS-00103: Encountered the symbol "LIKE" when expecting one of the following:
not null of nan infinite dangling a empty
请帮助我。
答案 0 :(得分:0)
首先,您无法修改:AFTER触发器中的新值 - 应该是之前的。此外,"喜欢"没有错。所以 - 你确定你发布了准确的代码吗?
以下是一个例子:
SQL> create table test (account_name varchar2(20), segment2 varchar2(20));
Table created.
SQL> create or replace trigger trg_test
2 after insert on test
3 for each row
4 begin
5 if :new.account_name like '%.VAT%' then
6 :new.segment2 := '000';
7 end if;
8 end;
9 /
create or replace trigger trg_test
*
ERROR at line 1:
ORA-04084: cannot change NEW values for this trigger type
SQL> l2
2* after insert on test
SQL> c/after/before
2* before insert on test
SQL> l
1 create or replace trigger trg_test
2 before insert on test
3 for each row
4 begin
5 if :new.account_name like '%.VAT%' then
6 :new.segment2 := '000';
7 end if;
8* end;
SQL> /
Trigger created.
SQL>
答案 1 :(得分:0)
您还可以在创建表时使用虚拟列。替代表达式用于segment4
,因为表不能具有2个虚拟列的相同表达式
create table XXAW.XXAW_AR_INV_STG_T_TEST
(
Account_Name VARCHAR2(10),
segment2 VARCHAR2(10) AS ( CASE WHEN Account_Name like '%.VAT%' THEN '000' END ),
segment4 VARCHAR2(10) AS ( CASE WHEN INSTR(Account_Name,'.VAT') > 0 THEN '000' END ),
segment5 VARCHAR2(10) AS ( CASE WHEN Account_Name like '%.VAT%' THEN '622' END )
);
唯一的缺点是您不能直接在这些列上插入或更新。否则,它会抛出
ORA-54013
和ORA-54017