码迷,mamicode.com
首页 > 其他好文 > 详细

batch modify column type

时间:2015-06-05 15:29:58      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:

CREATE OR REPLACE PROCEDURE ModifyColumnType
IS
  sqlRenameColumn CONSTANT VARCHAR2(100) := ‘alter table [tablename] rename column [targetcolumn] to [targetcolumn]_tmp‘;
  sqlAddColumn CONSTANT VARCHAR2(100) :=  ‘alter table [tablename] add [targetcolumn] NUMBER(18,4)‘;
  sqlCopyValue CONSTANT VARCHAR2(100) := ‘update [tablename] set [targetcolumn]=[targetcolumn]_tmp‘;
  sqlDropColumn CONSTANT VARCHAR2(100) := ‘alter table [tablename] drop column [targetcolumn]_tmp‘;
 
  cursor c1 is
   SELECT table_name,column_name
   FROM  all_tab_columns
   WHERE owner =‘VKC2‘ and data_type=‘NUMBER‘ and data_Scale=3;
BEGIN
  FOR row in c1
   LOOP
    EXECUTE IMMEDIATE (replace(replace(sqlRenameColumn, ‘[tablename]‘, row.table_name), ‘[targetcolumn]‘, row.column_name));
    EXECUTE IMMEDIATE (replace(replace(sqlAddColumn, ‘[tablename]‘, row.table_name), ‘[targetcolumn]‘, row.column_name));
    EXECUTE IMMEDIATE (replace(replace(sqlCopyValue, ‘[tablename]‘, row.table_name), ‘[targetcolumn]‘, row.column_name));
    EXECUTE IMMEDIATE (replace(replace(sqlDropColumn, ‘[tablename]‘, row.table_name), ‘[targetcolumn]‘, row.column_name));
   
    commit;
  END LOOP;
END ModifyColumnType;

batch modify column type

标签:

原文地址:http://www.cnblogs.com/cyy1029/p/4554486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!