我有两张表A.dec_bill_status和B.ep_dec_bill_list
create table A.dec_bill_status
(
list_no varchar2(20) primary key, --清单编号
list_status varchar2(10), --状态标志
ems_list_no varchar2(20) --存储清单编号没有改变前的编号
)
create table B.ep_dec_bill_list
(
list_no varchar2(20) primary key,
tag varchar2(20),
list_g_no varchar2(20)
)第一张表中list_no是以B开头的,当更新了状态标志为2后,list_no变成以0开头
ems_list_no中存储的是没有改变的list_no。现在我想建一个触发器,当状态改变时B.ep_dec_bill_list.list_no相应的改变为以0开头的A.dec_bill_status.list_no中的数据,该怎么写?问题主要集中在我如何获得状态已改变的那一行数据。我自己写了一个如下:
我用A用户创建的
create or replace trigger DEC_BILL_STAT_CHECK
after update on dec_bill_status for each row
declare
v varchar2(70);
x varchar2(20);
begin
if :new.status!=:old.status then
select ems_list_no into v from dec_bill_status where status='2';
select list_no into x from dec_bill_status where status='2';
update B.ep_dec_bill_list set list_no=x
where list_no=v;
end if;
end;
报错: 函数/触发器不可读
create table A.dec_bill_status
(
list_no varchar2(20) primary key, --清单编号
list_status varchar2(10), --状态标志
ems_list_no varchar2(20) --存储清单编号没有改变前的编号
)
create table B.ep_dec_bill_list
(
list_no varchar2(20) primary key,
tag varchar2(20),
list_g_no varchar2(20)
)第一张表中list_no是以B开头的,当更新了状态标志为2后,list_no变成以0开头
ems_list_no中存储的是没有改变的list_no。现在我想建一个触发器,当状态改变时B.ep_dec_bill_list.list_no相应的改变为以0开头的A.dec_bill_status.list_no中的数据,该怎么写?问题主要集中在我如何获得状态已改变的那一行数据。我自己写了一个如下:
我用A用户创建的
create or replace trigger DEC_BILL_STAT_CHECK
after update on dec_bill_status for each row
declare
v varchar2(70);
x varchar2(20);
begin
if :new.status!=:old.status then
select ems_list_no into v from dec_bill_status where status='2';
select list_no into x from dec_bill_status where status='2';
update B.ep_dec_bill_list set list_no=x
where list_no=v;
end if;
end;
报错: 函数/触发器不可读
如果是,建议你的这个触发器写成:
create or replace trigger DEC_BILL_STAT_CHECK
after update on dec_bill_status for each row
begin
if :new.status!=:old.status and :new.status='2' then
update B.ep_dec_bill_list set list_no=:new.list_no
where list_no=:new.ems_list_no;
end if;
end;
CREATE OR REPLACE TRIGGER dec_bill_stat_check
AFTER UPDATE
ON dec_bill_status
FOR EACH ROW
BEGIN
IF :NEW.status != :OLD.status AND :NEW.status = '2'
THEN
UPDATE b.ep_dec_bill_list
SET list_no = :NEW.list_no
WHERE list_no = :NEW.ems_list_no;
END IF;
END;