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!

Dynamically select a complete resultset into a CLOB

user6336927Jan 26 2016 — edited Jan 27 2016

Hi,

Oracle 11g R2 11.2.0.3

IBM AIX

A developer has come to me with a requirement to query a table based on an ID and have the entire row read into a clob.

He needs it to be dynamic since this ID is an FK and can appear in many child tables. I have seen similar questions asked in the forum but none quite addressed my scenario.

A simple example is:

create table t1 (col1 number, col2 varchar2(50));

insert into t1 values (1,'Test record');

commit;

Here's where I need help.

i) I select from user_tab_columns where table_name = T1.

...but in reality I will pass the table name as a parameter.

select column_name

from user_tab_columns

where table_name = 'T1';

select *

from t1 where id=1;

ii) I need the output to be:

<col_name1>=<col1_value>;<col_name2>=<col2_value> etc...

e.g.

COL1=1;COL2='Test Record'

And I need that stored in the contents of a CLOB for insertion into a CLOB field in an audit table.

Any help or pointers much appreciated. The key is it needs to be dynamic in that I don't know the composition of the table where the ID will be found, so I have to consult the DD.

Phil

This post has been answered by Paulzip on Jan 26 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 24 2016
Added on Jan 26 2016
14 comments
3,839 views