您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Oracle SQL将包含数据的列类型从数字更改为varchar2

Oracle SQL将包含数据的列类型从数字更改为varchar2

create table temp_uda1 (test1 integer);
insert into temp_uda1 values (1);

alter table temp_uda1 add (test1_new varchar2(3));

update temp_uda1 
   set test1_new = to_char(test1);

alter table temp_uda1 drop column test1 cascade constraints;
alter table temp_uda1 rename column test1_new to test1;

如果列上有索引,则需要重新创建它。

请注意,如果旧列中的数字大于999,则更新将失败。如果这样做,则需要调整该varchar列的最大值

SQLServer 2022/1/1 18:29:19 有463人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶