create or replace trigger sy befor insert on 表4 for each row
begin
select classNeme into :new.className1 from 表2
where classid =
(select classid from 表3
where addressid = :new.addressid and rownum <= 1); select classNeme into :new.className2 from 表2
where classid =
(select classid from 表3
where addressid = :new.addressid and rownum <= 1
and classid <> :new.className1); EXCEPTION
WHEN OTHERS THEN
null;
end;
begin
select classNeme into :new.className1 from 表2
where classid =
(select classid from 表3
where addressid = :new.addressid and rownum <= 1); select classNeme into :new.className2 from 表2
where classid =
(select classid from 表3
where addressid = :new.addressid and rownum <= 1
and classid <> :new.className1); EXCEPTION
WHEN OTHERS THEN
null;
end;
before insert on 表4
for each row
begin
select ClassName into
select (select ClassName from 表2 b where b.ClassID=C.ClassID) INTO :new.ClassName1 from 表3 c where AddressID=:new.AddressID;
end;
/
good luck!DECLARE
n_temp number;
class_name1 YourType;
class_name2 YourType;
CURSOR class_name IS
SELECT a.ClassName FROM 表2 a,表3 b
WHERE a.ClassId=b.ClassId and b.AddressId=:new.AddressId;
begin
if inserting then
n_temp:=1
for RC in class_name loop
if n_temp=3 then
exit;
end if;
if n_temp=1 then
class_name1:=RC.ClassName;
end if;
if n_temp=2 then
class_name2:=RC.ClassName;
end if; n_temp:=n_temp+1;
end loop;
ClassName1:=class_name1;
ClassName2:=class_name2;
end if;
end;