Oracle Database Update foreign keys with new value in Oracle


Suppose you have a table and you want to change one of this table primary id. you can use the following scrpit. primary ID here is "PK_S"

  for i in (select a.table_name, c.column_name
              from user_constraints a, user_cons_columns c
             where a.CONSTRAINT_TYPE = 'R'
               and a.R_CONSTRAINT_NAME = 'PK_S'
               and c.constraint_name = a.constraint_name) loop
         execute immediate 'update ' || i.table_name || ' set ' || i.column_name ||
                      '=to_number(''1000'' || ' ||  i.column_name || ') ';              
  end loop;