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 update many tables in PL/SQL

630673Mar 27 2008 — edited Apr 7 2008
Hi all,

I'm beginer to PL/SQL. I have to update many tables using PL/SQL. I can find all the table names that I have to update using
this query.

select table_name from all_tab_cols where table_name like 'TBL%' and column_name like 'EMPNIC%';

I want to update EMPNIC colum in all the tables that select from above query.I have one static table. According to that table
I have to update all the tables.

From this PL/SQL statement I can update one table. But here I'm hardcoding the table name.

PROCEDURE UPDATE_EMP_NIC IS
v_column VARCHAR2(30);
sql_stmt VARCHAR2(200);

BEGIN
DECLARE
CURSOR C IS

select s.EMPID,s.NEWEMPNIC,m.EMPNIC from PERSONALINFORMATION s,TBLPERSONALINFORMATION m where s.EMPID=m.EMPID;
REC C%ROWTYPE;
BEGIN
OPEN C ;
LOOP
FETCH C INTO REC;
EXIT WHEN C%NOTFOUND;
sql_stmt :='UPDATE PERSONALINFORMATION SET PERSONALINFORMATION.NEWEMPNIC ='''|| REC.EMPNIC
||''' WHERE PERSONALINFORMATION.EMPID ='''|| REC.EMPNIC||'''';
DBMS_OUTPUT.PUT_LINE(sql_stmt);
EXECUTE IMMEDIATE sql_stmt ;
commit;
END LOOP;
CLOSE C;
END;
END update_emp_nic;


But I have to update more than 700 tables.
So I can't hardcode the table name. I have to get the table name dynamically. But I don't know how to combine these two codes.
Let me know anyone know to do this.

Thankyou all
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 5 2008
Added on Mar 27 2008
11 comments
2,545 views