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!

Get all column names and values in cursor

Pavel_pNov 18 2016 — edited Nov 20 2016

Hello,

I have a cursor for update and I would like to save all original values to the log file before updating them. Is there any way to loop over all the selected columns in cursor and print name-value pairs. Something like

declare

     cursor c_dept is select deptno,dname,loc from dept for update;

begin

  for r_d in c_dept loop

 

    --print here name-value pairs for each column in opened cursor

    for c in c_dept.columns loop

      dbms_output.put_line('Column name' || c.name);

      dbms_output.put_line('Column value' || c.value);

    end loop;

   

    update dept set dname = dname || '' where current of c_dept;

  end loop;

end;

Thanks a lot,

Pavel

edit: also to get a data type of a given column would be nice to eventually skip clobs, blobs, xmltypes...and other similar columns

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2016
Added on Nov 18 2016
19 comments
24,927 views