batch modify column type

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;

时间: 2024-11-09 00:04:02

batch modify column type的相关文章

mysql modify column

alter table yourtable modify column yourcolumn varchar( 2000 );

mysql之ALTER COLUMN、CHANGE COLUMN、MODIFY COLUMN的区别

ALTER COLUMN:设置或删除列的默认值(操作速度非常快) 例子: alter table film alter column rental_duration set default 5; alter table film alter column rental_duration drop default; CHANGE COLUMN:列的重命名.列类型的变更以及列位置的移动 例子: ALTER TABLE MyTable CHANGE COLUMN foo bar VARCHAR(32)

alter column和modify column

5.6中,发现其实alter column 和更改modify column 步骤是一样的 mysql> create table xs(name varchar(12),age int default 5);Query OK, 0 rows affected (0.34 sec) mysql> insert into xs values('a',4);Query OK, 1 row affected (0.05 sec) mysql> set profiling=1;Query OK,

dashDB - Creating a table with CLOB column type

In order to create a table with clob column type, the table has to be created with "ORGANIZE BY ROW"; DROP TABLE m_pi_error; CREATE TABLE m_pi_error ( id INTEGER NOT NULL, customer_id VARCHAR(15), twitter_id VARCHAR(255), err_msg clob(5M), creat

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [others] in table [auth_user]; found [varchar (Types#VARCHAR)], but expec

Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [others] in table [auth_user]; found [varchar (Types#VARCHAR)], but expecting [integer (Types#INTEGER)] 这个错误是由于使用springdata

MySQL:ALTER COLUMN、MODIFY COLUMN 和 CHANGE COLUMN

ALTER COLUMN.MODIFY COLUMN 和 CHANGE COLUMN 语句修改列: ALTER COLUMN:改变.删除列的默认值. 这个语句会直接修改 .frm 文件而不涉及表数据,所以操作很快. -- 改变列的默认值 ALTER TABLE test ALTER COLUMN age SET DEFAULT 17; -- 删除列的默认值 ALTER TABLE test ALTER COLUMN age DROP DEFAULT; MODIFY COLUMN:修改列数据类型:

org.hibernate.HibernateException: Wrong column type

这个问题一般出现在我们使用定长的字符串作为主键(其它字段也可能)的时候,如数据库中的ID为char(16).虽然很多资料上都说不推荐这样做,但实际上我们在做很多小case的时候自己为了方便也顾不得那么多,随心所欲地设计.其实我们就用INT的主键,只是对你原有的ID(char(16))增加一个Unique Check或者是像在MySQL中增加一个Unique索引又费得了多少事呢. 如果使用char()做为主键时出现如题错误,其很可能的原因在于你的hibernate.cfg.xml文件中的关于Hib

自我提升mysql

1.某字段更新 自增 1 update table set a=a+1 2.修改某一字段的数据类型 alter table "tablename" modify  "column"  "type" 3.更改字段名 alter table "tablename" change column col_old col_new "type"

run commands in linux shell using batch file

adb shell as root after device rooted once device rooted, we must perform "su" before we get root permission in adb shell,this is not convenient in some situations,so there have a method to get permission without perform "su". adb shel