O
otqsoft
Unregistered / Unconfirmed
GUEST, unregistred user!
create or replace trigger tri_base_ware <br> after insert or delete or update on base_ware for each row<br>declare<br> -- insert 状态 [0]<br> tSql varchar2(500):= '';<br> Area1 varchar2(10) := '';<br> Area2 varchar2(10) := ''; <br> arows varchar2(10) := '';<br> statu varchar2(2) := '';<br> trows integer(10) := 0;<br> ticket varchar2(20) := '';<br> <br> cursor c_base is<br> select lower(table_name) as table_name,lower(column_name) as column_name,lower(data_type) as data_type<br> from cols where lower(table_name)='base_ware';<br>begin<br> select tvalue into Area1 from send_area where id='01';<br> select tvalue into Area1 from send_area where id='02';<br> select count(*) into trows from send_data;<br> if trows = 0 then<br> trows := 1;<br> else<br> select max(substr(ticket_no,15,6)) as tick into trows from send_data;<br> trows := trows + 1;<br> end if; <br> select to_char(sysdate,'yyyymmddhh24miss') as tcik into ticket from dual;<br> arows := to_char(trows);<br> if length(arows) = 1 then arows := '00000' + arows;<br> elsif length(arows) = 2 then arows := '0000' + arows;<br> elsif length(arows) = 3 then arows := '000' + arows;<br> elsif length(arows) = 4 then arows := '00' + arows;<br> elsif length(arows) = 5 then arows := '0' + arows;<br> end if;<br> ticket := ticket||arows;<br> if inserting then statu := '0';<br> elsif updating then statu := '1';<br> elsif deleting then statu := '2'; <br> end if;<br> for r_add in c_base loop<br> tSql := 'insert into send_data(ticket_no,t_name,t_field,t_type,t_value,opt_statu,opt_while,opt_server) values('||<br> ticket,<br> r_add.table_name,<br> r_add.column_name,<br> r_add.data_type,<br> :new.r_add.column_name, -- 此处字段名能不能用变量代替<br> statu,<br> '',<br> Area1);<br> execute immediate tsql;<br> end loop;<br> commit; <br>exception <br> when others then <br> rollback; <br> raise_application_error(-20800,'触发器向发送表发送数据错误!'); <br>end tri_base_ware;<br>上面注释部分的字段字能不能用变量代替?哪位朋友若知道,告诉俺一声吧?帮帮忙嘛...