首批通过分布式安全可靠测评,为关键业务系统打造
Oracle 模式下对触发器中使用 insert all 语句的表进行操作报 ORA-00904 错误
更新时间:2024-01-22 01:56
问题描述
在 OceanBase 数据库 Oracle 租户下创建 insert all 触发器后对表进行操作,报错 ORA-00904,具体报错信息如下。
ORA-00904: invalid identifier 'VIEW1.:NEW.C1' in 'field list' at CHZ.TRI.BEFORE_ROW
表结构及对应的触发器语句如下。
创建测试表 t1,t2,t3。
create table t1 (c1 int, c2 int);create table t2 (c1 int, c2 int);create table t3 (c1 int, c2 int);为表 t1 创建使用
insert all的触发器。create or replace trigger tri before insert or update or delete on t1 for each row begin insert all into t2 into t3 select :new.c1, :new.c2 from dual; end; /
适用版本
OceanBase 数据库 V2.1.x、V2.2.x、V3.1.x、V3.2.x 版本。
问题原因
PL 中未支持 insert all 语句类型。
解决方法
将 insert all 语句拆分成简单 insert 语句进行绕过。
拆分后的 insert 语句如下。
create or replace trigger tri before insert or update or delete on t1 for each row
begin
insert into t2 select :new.c1, :new.c2 from dual;
insert into t3 select :new.c1, :new.c2 from dual;
end;
/