有2个表 他们是 组合关系 即 主子关系A
aid name
1 特殊
2 nullB
bid aid mingxi
a 1 好
b 1 强
c 2 主要我现在想写 一段触发器
如果在 添加 修改前 mingxi = 主要 并且 aid=2 里 的name =null 就抛一个异常
不知道咋写create or replace trigger t_xxx
before insert or update on B
for each row
begin if :new.mingxi = '主要' and :new.name is null --关键就是这个 and 不会写。。
then
raise_application_error(-222,'!!!出错了! 明细为 “主要” 的主表的Name为null了!');
end if;
end t_xxx;
aid name
1 特殊
2 nullB
bid aid mingxi
a 1 好
b 1 强
c 2 主要我现在想写 一段触发器
如果在 添加 修改前 mingxi = 主要 并且 aid=2 里 的name =null 就抛一个异常
不知道咋写create or replace trigger t_xxx
before insert or update on B
for each row
begin if :new.mingxi = '主要' and :new.name is null --关键就是这个 and 不会写。。
then
raise_application_error(-222,'!!!出错了! 明细为 “主要” 的主表的Name为null了!');
end if;
end t_xxx;
是不是跑错地方了
new里面的东西都是B表里面的
对!1Oracle 怎么接变量值 我给忘记 。。
select name into aname from A where aid=:new.aid
create or replace trigger t_xxxx
before insert or update on B
for each row
declare dtzyx10 varchar2(20);
begin
select name into aname from A where aid=:new.aid
if :new.mingxi = '主要' and :aname is null
then
raise_application_error(-222,'!!!出错了! 明细为 “主要” 的主表的Name为null了!');
end if;
end t_xxx;?这样?
create or replace trigger t_xxxx
before insert or update on B
for each row
declare aname varchar2(20);
begin
select name into aname from A where aid=:new.aid
if :new.mingxi = '主要' and aname is null
then
raise_application_error(-222,'!!!出错了! 明细为 “主要” 的主表的Name为null了!');
end if;
end t_xxx;
create or replace trigger t_xxxx
before insert or update on B
for each row
declare aname varchar2(20);
begin
select name into aname from A where aid=:new.aid;
if :new.mingxi = '主要' and aname is null
then
raise_application_error(-222,'!!!出错了! 明细为 “主要” 的主表的Name为null了!');
end if;
end t_xxx;
select name into aname from A where aid=:new.aid;变量出错。。
create or replace trigger t_xxxx
before insert or update on B
for each row
declare aname varchar2(64);
begin
select name into aname from A where aid=:new.aid;
if :new.mingxi = '主要' and aname is null
then
raise_application_error(-20200,'!!!出错了! 明细为 “主要” 的主表的Name为null了!');
end if;
end;怎么可能错 你的 name 是什么类型的
自己加一个no_date_found的异常处理
TRIGGER EEDZKY.T_XXX 编译错误错误:PLS-00049: 错误的赋值变量 'aname'
行:7
文本:if :new.mingxi = '1103A110000000003MHW' and :aname is null应该是Varchar2(200)把