17,377
社区成员
发帖
与我相关
我的任务
分享
create or replace trigger insert_user --创建一个触发器
before insert on user_t
for each row
declare
v_sql varchar2(1000) ;
keyFieldName varchar2(50) ;
BEGIN
select c.column_name into keyFieldName from user_cons_columns c
where c.table_name ='USER_T' and c.position is not null and rownum = 1;
if inserting and keyFieldName is not null then
v_sql := 'insert into u_t(key_name) values(:new.'||keyFieldName||')';
EXECUTE IMMEDIATE v_sql;
end if;
end insert_user;
select a.column_name
into v_pk_column_name
from user_cons_columns a, user_constraints b
where a.constraint_name = b.constraint_name
and b.constraint_type = 'P'
and a.table_name =''