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!

loop through dynamic sql

BIAPMay 12 2016 — edited May 12 2016

Hi, Are we able to loop through dynamic sql? code below doesn't work. Oracle cursor doesn't support dynamic sql? If that's the case, how to achieve what I am trying to do as below. DECLARE     CURSOR c_stmt IS       SELECT '''ALTER TABLE '||table_name||' MODIFY '|| column_name ||' VARCHAR2('||data_length||' CHAR)'''  ddl_stmt       FROM user_tab_columns       WHERE data_type = 'VARCHAR2'       AND table_name = 'AA_TEST'       AND char_used = 'B';     r_emp c_stmt%rowtype;     BEGIN     OPEN c_stmt;     LOOP         FETCH c_stmt INTO r_emp;         EXIT WHEN c_stmt%notfound;         dbms_output.put_line(r_emp.ddl_stmt);         EXECUTE IMMEDIATE r_emp.ddl_stmt;     END LOOP;     CLOSE c_stmt;     END; / show error

This post has been answered by KayK on May 12 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2016
Added on May 12 2016
11 comments
1,771 views