0

Is it possible, and how, to do a Oracle trigger "to see" some default value in column even if it´s not inserted yet? Mean, if :old is for update and :new is for insert and in this case I need to "cheat" trigger to believe something was inserted (:new) though I just want to update (:old) record.

Oracle version is so new, that even exotic ideas are welcome. Also it can be a combination of different mechanism if it's required to achieve this.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

1

Not so exotic; user_tab_columns is what you might be using.

SQL> create table car
  2    (name  varchar2(20),
  3     color varchar2(10) default 'RED');

Table created.

SQL> select data_default
  2  from user_tab_columns
  3  where table_name = 'CAR'
  4    and column_name = 'COLOR';

DATA_DEFAULT
--------------------------------------------------------
'RED'

SQL> create or replace trigger trg_biu_car
  2    before insert or update on car
  3    for each row
  4  declare
  5    l_def_color car.color%type;
  6  begin
  7    select data_default
  8      into l_def_color
  9      from user_tab_columns
 10      where table_name = 'CAR'
 11        and column_name = 'COLOR';
 12
 13    -- your code now goes here
 14  end;
 15  /

Trigger created.

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57