plsql - How to write a delete trigger in Oracle PL/SQL - stuck on identifying "matching rows" -
plsql - How to write a delete trigger in Oracle PL/SQL - stuck on identifying "matching rows" -
i have trigger i'm writing whereby , 1 time delete row, want delete corresponding row in table (which common_cis.security_function
).
and source table party.security_function
here columns in common_cis.security_function
:
url scrty_func_name scrty_func_desc idn create_tmstmp cncrcy_user_idn
here columns in party.security_function
:
update_user_src_sys_cd update_user_id update_ts scrt_func_nm scrt_func_desc creat_user_src_sys_cd creat_user_id creat_ts
what have far :
delete common_cis.security_function ccsf ccsf.scrty_func_name = :new.scrt_func_nm;
is right idea? or utilize kind of row-id ?
thanks
i think should utilize integrity constraints that, namely foreign key constraint "on delete cascade" condition. here example, check first there tables in schema names used:
-- create tables: create table master_table( url varchar2(1000), scrty_func_name varchar2(100), scrty_func_desc varchar2(1000)); create table detail_table( scrt_func_nm varchar2(100), scrt_func_desc varchar2(1000), update_user_id number, update_ts varchar2(100)); -- add together primary key , foreign key constraints: alter table master_table add together constraint function_pk primary key (scrty_func_name); alter table detail_table add together constraint function_fk foreign key (scrt_func_nm) references master_table (scrty_func_name) on delete cascade; -- fill tables data: insert master_table values ('url number 1', 'sec function #1', 'description of function #1'); insert detail_table values('sec function #1', 'description', 1, '123abc'); insert detail_table values('sec function #1', 'description', 2, '456xyz'); -- check tables: first contains 1 row , sec - 2 rows select count(*) master_table; select count(*) detail_table; -- delete rows first table only: delete master_table; -- check tables 1 time 1 time again - both empty: select count(*) master_table; select count(*) detail_table; -- clear test tables: drop table detail_table; drop table master_table;
plsql triggers
Comments
Post a Comment