If you can really use a virtual column as defined in the CREATE TABLE syntax. This makes it more easily extensible if necessary.
Here is a working example.
SQL> create table tmp_test ( 2 id number(7,0) primary key 3 , col1 number 4 , seq varchar2(8 char) generated always as ( 5 'A' || to_char(id, 'FM0999999')) 6 ); Table created. SQL> SQL> create sequence tmp_test_seq; Sequence created. SQL> SQL> create or replace trigger tmp_test_trigger 2 before insert on tmp_test 3 for each row 4 begin 5 6 :new.id := tmp_test_seq.nextval; 7 end; 8 / Trigger created. SQL> show errors No errors. SQL> SQL> insert into tmp_test (col1) 2 values(1); 1 row created. SQL> SQL> select * from tmp_test; ID COL1 SEQ ---------- ---------- -------------------------------- 1 1 A0000001
Having said that; you would be better off if you hadn’t done this, if you had no incredibly urgent business need. There is little point in making life more difficult for you by adding constant value to a number. Since A will always be A, it does not matter if he is there or not.
source share