Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to convert string which is a column name into a variable

praveenwinsallNov 7 2013 — edited Nov 8 2013

I have a requirement like this:

In table Ticket_detail, I have 2 compare last 2 rows. If there is any change in values between 2 rows, then I have to log the change into another table.

To explain in detail, Say table Ticket_detail has following columns:

Say it has 6 rows, Version 1,2 and 3 with 2 rows each. (Always 2 rows, wont change)

TICKET_NOENTRY_VERSN_NOTEST_DTL_NODESTINATIONROUTETEST_NUMBER
10111ABCDXYZ12345
10112efghqwe4567
10121ABCDXYZ12345
10122efghqwe4321
10131ABCDXYZ67890
10132ASDFqwe4321

My requirement is to compare last 2 versions, i.e, version 2 and 3 and log the changes which i have highlighted above into a log table with below structure:

TICKET_NOTICKET_VERSN_NOTABLE_NAMECOL_NM COL_IDOLD_VALUENEW_VALUE
1013Ticket_detailTEST_NUMBER11234567890
1013Ticket_detailDESTINATION2efghASDF

Now problem is I have 14 tables with 30 to 40 columns in each for which I have to do this. So I am looking for a common solution to compare columns of the table. I am thinking about using data dictionary ALL_TAB_COLUMNS and fetch the columns for the table and compare them. But problem is the output I get from data dictionary is a string. I am not able to use them as variable. Is there any possibility that we can convert these string into variables so that comparison is possible. Please suggest some idea.

Different solution is also welcome. All i need is to log the changes into the LOG table.

Thanks in advance.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 6 2013
Added on Nov 7 2013
5 comments
2,870 views