create function get(p_id in varchar2) return varchar2 as v_col varchar2(10); begin select col_name into v_col from a where id=p_id; return v_col; end; / create trigger a_tri before insert on a for each row begin if get(:new.id)=:new.col_name then ... end if; end; /以上提供一个利用函数例子,也可使用过程实现需要的功能
楼上的这个例子有局限,只有是before insert并且insert语句不是insert ... select ...时能起作用,对于其他类型的行级触发器或者用了insert ... select ...都会引起ORA-04091错。如: insert into a select '1','aaa' from dualORA-04091: 表 OPER_112.A 发生了变化,触发器/函数不能读 ORA-06512: 在"OPER_112.GET", line 6 ORA-06512: 在"OPER_112.A_TRI", line 2 ORA-04088: 触发器 'OPER_112.A_TRI' 执行过程中出错而insert into a values('1','aaa')就可以。
return varchar2
as
v_col varchar2(10);
begin
select col_name into v_col from a where id=p_id;
return v_col;
end;
/
create trigger a_tri
before insert on a
for each row
begin
if get(:new.id)=:new.col_name then
...
end if;
end;
/以上提供一个利用函数例子,也可使用过程实现需要的功能
insert into a select '1','aaa' from dualORA-04091: 表 OPER_112.A 发生了变化,触发器/函数不能读
ORA-06512: 在"OPER_112.GET", line 6
ORA-06512: 在"OPER_112.A_TRI", line 2
ORA-04088: 触发器 'OPER_112.A_TRI' 执行过程中出错而insert into a values('1','aaa')就可以。
世人都说ORALCE好,怎么这点就不如SQL SERVER ??????