dbTalk Databases Forums  

Oracle Trigger Late binding

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Oracle Trigger Late binding in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Vabs
 
Posts: n/a

Default Oracle Trigger Late binding - 04-17-2008 , 07:32 AM






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...

Reply With Quote
  #2  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 07:48 AM






On Apr 17, 7:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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...
Why do you 'need' this? It seems like a bad idea to me; the :new
and ld 'blocks' aren't available outside of a trigger which is
written against a specific table (and you should know the columns for
that table if you're writing a trigger against it).

I really see no purpose in what you're asking.


David Fitzjarrell


Reply With Quote
  #3  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 07:48 AM



On Apr 17, 7:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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...
Why do you 'need' this? It seems like a bad idea to me; the :new
and ld 'blocks' aren't available outside of a trigger which is
written against a specific table (and you should know the columns for
that table if you're writing a trigger against it).

I really see no purpose in what you're asking.


David Fitzjarrell


Reply With Quote
  #4  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 07:48 AM



On Apr 17, 7:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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...
Why do you 'need' this? It seems like a bad idea to me; the :new
and ld 'blocks' aren't available outside of a trigger which is
written against a specific table (and you should know the columns for
that table if you're writing a trigger against it).

I really see no purpose in what you're asking.


David Fitzjarrell


Reply With Quote
  #5  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 07:48 AM



On Apr 17, 7:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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...
Why do you 'need' this? It seems like a bad idea to me; the :new
and ld 'blocks' aren't available outside of a trigger which is
written against a specific table (and you should know the columns for
that table if you're writing a trigger against it).

I really see no purpose in what you're asking.


David Fitzjarrell


Reply With Quote
  #6  
Old   
Ken Denny
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 01:01 PM



On Apr 17, 8:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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 := 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.


Reply With Quote
  #7  
Old   
Ken Denny
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 01:01 PM



On Apr 17, 8:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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 := 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.


Reply With Quote
  #8  
Old   
Ken Denny
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 01:01 PM



On Apr 17, 8:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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 := 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.


Reply With Quote
  #9  
Old   
Ken Denny
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 01:01 PM



On Apr 17, 8:32*am, Vabs <rajat... (AT) gmail (DOT) com> wrote:
Quote:
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 := 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.


Reply With Quote
  #10  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: Oracle Trigger Late binding - 04-17-2008 , 01:33 PM



fitzjarrell (AT) cox (DOT) net wrote:
Quote:
On Apr 17, 7:32 am, Vabs <rajat... (AT) gmail (DOT) com> 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...

Why do you 'need' this? It seems like a bad idea to me; the :new
and ld 'blocks' aren't available outside of a trigger which is
written against a specific table (and you should know the columns for
that table if you're writing a trigger against it).

I really see no purpose in what you're asking.


David Fitzjarrell
The Quest for the Universal Application?


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.