plsql - PL/SQL Oracle Trigger Before Insert Can't get New Unique Primary ID -
whats wrong...?? please check trigger
create or replace trigger tbl_ae_bi before update on tbl_ae referencing new new old old each row declare kd_ae varchar2 (6); begin select ae_id kd_ae ( select kdmax,(select to_char('ae')kd dual)|| (case when kdmax>=0 , kdmax<10 '000'||kdmax when kdmax>=10 , kdmax<100 '00'||kdmax when kdmax>=100 , kdmax<1000 '0'||kdmax else to_char(kdmax) end)ae_id (select (nvl(max(to_number(substr(ae_id,3,4))),0)+1)kdmax tbl_ae) ); :new.ae_id:=kd_ae; :new.insert_date:= sysdate; end;
when insert new record table, result error cannot insert null ae_id.
but when execute in sql window following code
select ae_id kd_ae ( select kdmax,(select to_char('ae')kd dual)|| (case when kdmax>=0 , kdmax<10 '000'||kdmax when kdmax>=10 , kdmax<100 '00'||kdmax when kdmax>=100 , kdmax<1000 '0'||kdmax else to_char(kdmax) end)ae_id (select (nvl(max(to_number(substr(ae_id,3,4))),0)+1)kdmax tbl_ae) )
result no error, , new unique id.
like
change before upate before insert
create or replace trigger tbl_ae_bi before insert --changed on tbl_ae referencing new new old old each row declare kd_ae varchar2 (6); begin select ae_id kd_ae ( select kdmax,(select to_char('ae')kd dual)|| (case when kdmax>=0 , kdmax<10 '000'||kdmax when kdmax>=10 , kdmax<100 '00'||kdmax when kdmax>=100 , kdmax<1000 '0'||kdmax else to_char(kdmax) end)ae_id (select (nvl(max(to_number(substr(ae_id,3,4))),0)+1)kdmax tbl_ae) ); :new.ae_id:=kd_ae; :new.insert_date:= sysdate; end;
Comments
Post a Comment