标签:
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;
标签:
原文地址:http://www.cnblogs.com/cyy1029/p/4554486.html