Q
Problem solve Get help with specific problems with your technologies, process and projects.

Using NDS or dynamic SQL in update trigger

I am trying to use NDS or dynamic SQL in an update trigger to extract the value of the :new and the value of :old for a given column.

I am trying to use NDS or dynamic SQL in an update trigger to extract the value of the :new and the value of :old for a given column.

Consider the following example. I have a table T with these 20 fields:

x1 varchar2(32)
x2 number (16)
x3 date
......

The column names are in a dynamic array called colnameList. When the trigger fires, for each record, I want to call a stored procedure with column name, value of the old and new for the column :new.X1, :old.X1:

Procedure (colnameList(i),:new.||'colnameList(i),:old.||colnameList(i))
I tried to extract the value like this:
execute immediate 'select '||':new'||'.'||colmnames(i)||' from dual'
into tmpVarn;
but it won't work.
Try this:
execute immediate 'begin select '':new.'||colmnames(i)||''' into :out from dual; end;'
   using out  tmpVarn;
Make sure you leave in "begin" and "end," else you will receive an invalid character error.
This was last published in November 2006

Dig Deeper on Using Oracle PL-SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close