我有两个表inp_bill_detail还有一个orders_group_rec,
我希望每次在插入inp_bill_detail的时候能将orders_group_rec中的group_id 字段插到inp_bill_detail表中,
两个表的唯一索引patient_id这个触发器应该怎么写啊?
我希望每次在插入inp_bill_detail的时候能将orders_group_rec中的group_id 字段插到inp_bill_detail表中,
两个表的唯一索引patient_id这个触发器应该怎么写啊?
但是写出了你就不去思考了,提供一个思路吧定义变量
从orders_group_rec表中取值 group_id where patient_id = :new.patient_id更新值到 inp_bill_detaildeclare
ld_id number;
begin
if inserting then
select group_id into ld_id from orders_group_rec where patient_id = :new.patient_id;
update inp_bill_detail
set group_id = ld_id
where patient_id = :new.patient_id ;
end if;
create or replace trigger inp_bill_detail_insert
before insert
on inp_bill_detail
for each row
begin
:new.group_id = select group_id from orders_group_rec where patient_id=:new.patinet_id;
end;
/
这样写有什么问题呢、?
before insert
on inp_bill_detail
for each row
declare
ld_id varchar2;
begin
if inserting then
select group_id into :ld_id from orders_group_rec where patient_id= :new.patient_id;
update inp_bill_detail
set group_id = ld_id
where patient_id = :new.patient_id ;
end if;
end;
/还是编译出错啊
before insert
on inp_bill_detail
for each row
begin
select group_id into :new.group_id from orders_group_rec where patient_id=:new.patinet_id;
end;