Friday, August 7, 2020

How to generate primary key with character and number

 Code:

CREATE OR REPLACE TRIGGER article_trig

before insert on articles

REFERENCING NEW AS NEW OLD AS OLD

for each row

declare

v_id number;

--extra varchar2(26):='p';

begin

select nvl(max(to_number(id)),0)+1 into v_id from articles;

:new.id:='python'||'-'|| LPAD(v_id,2,0);

--:new.id:=v_id;

end;

/

No comments:

Post a Comment