Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Oracle Miscellaneous > Re: Oracle Trig...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 6840 of 7201
Post > Topic >>

Re: Oracle Trigger Late binding

by Ken Denny <ken@[EMAIL PROTECTED] > Apr 17, 2008 at 11:01 AM

On Apr 17, 8:32=A0am, Vabs <rajat...@[EMAIL PROTECTED]
> wrote:
> i want to use if(:new.column_name is not null) which works perfect...
> however my problem is that i want to set this column_name as a run
> time variable (as the table columns are not known to me)
>
> I tried using a variable but oracle throws a PLS-00049 bad bind
> variable error.
>
> Please help...

I agree with David about not understanding the usefulness of this but
I'll attempt anyway. Since this will be in a trigger then the name of
the column that needs to be checked will be in one of the :new column
values. You will have to hard code all possible column names no way
around that.

DECLARE
  v_column_val  VARCHAR2(32767);
BEGIN
  v_column_value :=3D CASE :new.col_to_check
                      WHEN 'COL1' THEN :new.col1
                      WHEN 'COL2' THEN :new.col2
                      WHEN 'COL3' THEN :new.col3
                      WHEN 'COL4' THEN :new.col4
                      -- repeat for every possible column name
                    END;
  IF v_column_value IS NOT NULL
  THEN

OK. That's the simplest most straightforward way to do it but in case
you have 3000 columns in this table and don't want to have to hard
code every one of them there is another way.

DECLARE
  v_column_value  VARCHAR2(32767);
BEGIN
  EXECUTE IMMEDIATE 'select to_char(:new.'||:new.col_to_check||') from
dual'
    INTO v_column_value;
  IF v_column_value IS NOT NULL
  THEN

I don't know if this second one will work or not. I've never used
dynamic SQL in a trigger before so I don't know if using ':new' in the
dynamic SQL will work.
 




 4 Posts in Topic:
Oracle Trigger Late binding
Vabs <rajatbsr@[EMAIL   2008-04-17 05:32:01 
Re: Oracle Trigger Late binding
"fitzjarrell@[EMAIL   2008-04-17 05:48:42 
Re: Oracle Trigger Late binding
Frank van Bortel <fran  2008-04-17 20:33:56 
Re: Oracle Trigger Late binding
Ken Denny <ken@[EMAIL   2008-04-17 11:01:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 13:36:17 CDT 2008.