We help IT Professionals succeed at work.
Get Started

variable issue in trigger oracle 11gr2

jl66
jl66 asked
on
142 Views
Last Modified: 2015-07-01
Want to write a trigger like below. Is it possible? Definitely it is compiled with errors.

CREATE OR REPLACE TRIGGER SCOTT.T_TRG BEFORE INSERT ON SCOTT.T
FOR EACH ROW
begin
  for i in ( select column_name from all_tab_columns where owner = 'SCOTT' and table_name = 'T')
  loop
     if :new.i is null then
       :new.i := 'N';
     end if;
  end loop;
END;
/

The reason to use the variable i is there are many columns in T in real situation, so if writing the 'if' block, that would be too many. Take an example,  we can assume there are 3 columns in T like below
create table scott.T( c1 varchar2(30), c2 varchar2(10), c3 varchar2(20)); How to use the variable in this case?
Can any gurus shed some light on it?
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 4 Answers and 11 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE