create table T_ORDER_test
(
ORDERIDENTITY NUMBER(19) not null,
MODALITYS VARCHAR2(256),
BODYPARTS VARCHAR2(1024)
)
create table T_PROCEDURE_test
(
PROCEDUREIDENTITY NUMBER(19) not null,
ORDERIDENTITY NUMBER(19) not null,
BODYPART VARCHAR2(512) not null
)
insert into T_ORDER_test values(101,'ZKDR','胸部正位;');
insert into T_ORDER_test values(102,'ZKDR','胸部正位; 胸部侧位;');
insert into T_ORDER_test values(103,'DR','腹部立位;');
insert into T_ORDER_test values(104,'ZKDR','胸部立位;');
select * From T_ORDER_test
insert into T_PROCEDURE_test values(1001,101,'胸部正位;');
insert into T_PROCEDURE_test values(1002,102,'胸部正位; 胸部侧位;');
insert into T_PROCEDURE_test values(1003,103,'腹部立位;');
insert into T_PROCEDURE_test values(1004,104,'胸部立位;');
select * From T_PROCEDURE_test
以上为测试代码,现在我想实现在T_PROCEDURE_test表中插入或更新数据时,如果插入记录的ORDERIDENTITY字段
在T_ORDER_test表中对应的MODALITYS='ZKDR'时,去自动更新T_PROCEDURE_test表中的bodypart字段
更新规则 如果一个部位时,将部位名称后的分号去掉 效果为:胸部正位
如果为多个部位时,将最后面的一个分号去掉,其他的分号改为加号 效果为 胸部正位+胸部侧位
哪位大哥可以帮忙写个触发器,十分感谢
------解决思路----------------------
CREATE OR REPLACE TRIGGER test
before UPDATE OR INSERT OF BODYPART ON T_PROCEDURE_test
FOR EACH ROW
declare
PRAGMA AUTONOMOUS_TRANSACTION;
a varchar2(256);
BEGIN
select min(MODALITYS) into a from t_order_test where orderidentity=:new.ORDERIDENTITY;
if a='ZKDR' then
:new.bodypart:=replace(rtrim(:new.bodypart,';'),';','+')
;
end if;
exception when others then
null;
END;
/
------解决思路----------------------
CREATE OR REPLACE TRIGGER test
before UPDATE OR INSERT OF BODYPART ON T_PROCEDURE_test
FOR EACH ROW
declare
a varchar2(256);
BEGIN
select min(MODALITYS) into a from t_order_test where orderidentity=:new.ORDERIDENTITY;
if a='ZKDR' then
:new.bodypart:=replace(rtrim(:new.bodypart,';'),';','+')
;
end if;
exception when others then
null;
END;
/