oracle得char类型长度,oracle 数据库缩减char类型 字段长度

不小心把数据库好几张表的char类型的字段原长度1、2、3的都改为4了

0818b9ca8b590ca3270a3433284dd417.png。增加长度后,数据库会自动填充空格,结果项目出问题了

0818b9ca8b590ca3270a3433284dd417.png。老老实实找方法改回来。

这里只贴出我的解决方法:

--如果要缩减长度的字段中含有 not null 的,需要进行步骤1、2、3、4、10,否则跳过。 --1导出表数据   略去。。。 --2清空表数据 truncate table tbl_cust_if_seller; --3将not null 字段  设为null  alter table tbl_cust_if_seller modify is_signed_protocal    char(4) null; --4导入表数据 略去。。。 --5添加表字段 alter table tbl_cust_if_seller add    is_signed_protocal_bak    char(4); alter table tbl_cust_if_seller add    curcd1_bak                char(4); alter table tbl_cust_if_seller add    curcd2_bak                char(4); alter table tbl_cust_if_seller add    curcd3_bak                char(4); alter table tbl_cust_if_seller add    curcd4_bak                char(4); alter table tbl_cust_if_seller add    curcd5_bak                char(4); alter table tbl_cust_if_seller add    short_section_curcd_bak   char(4); --6为新增字段赋值 update tbl_cust_if_seller set  is_signed_protocal_bak =  is_signed_protocal ,  curcd1_bak             =  curcd1             ,  curcd2_bak             =  curcd2             ,  curcd3_bak             =  curcd3             ,  curcd4_bak             =  curcd4             ,  curcd5_bak             =  curcd5             ,  short_section_curcd_bak=  short_section_curcd;    --7修改原字段值为空  update tbl_cust_if_seller set is_signed_protocal =  '', curcd1             =  '', curcd2             =  '', curcd3             =  '', curcd4             =  '', curcd5             =  '', short_section_curcd=  '';    --8修改原字段长度 alter table tbl_cust_if_seller modify  is_signed_protocal    char(1); alter table tbl_cust_if_seller modify  curcd1                char(3); alter table tbl_cust_if_seller modify  curcd2                char(3); alter table tbl_cust_if_seller modify  curcd3                char(3); alter table tbl_cust_if_seller modify  curcd4                char(3); alter table tbl_cust_if_seller modify  curcd5                char(3); alter table tbl_cust_if_seller modify  short_section_curcd   char(3); --9原字段赋值 update tbl_cust_if_seller set  is_signed_protocal =  substr(is_signed_protocal_bak ,1,1),  curcd1             =  substr(curcd1_bak             ,1,3),  curcd2             =  substr(curcd2_bak             ,1,3),  curcd3             =  substr(curcd3_bak             ,1,3),  curcd4             =  substr(curcd4_bak             ,1,3),  curcd5             =  substr(curcd5_bak             ,1,3),  short_section_curcd=  substr(short_section_curcd_bak,1,3);  --10恢复not null  alter table tbl_cust_if_seller modify is_signed_protocal    char(1) not null;   --11删除新增字段 alter table tbl_cust_if_seller drop (is_signed_protocal_bak   ); alter table tbl_cust_if_seller drop (curcd1_bak             ); alter table tbl_cust_if_seller drop (curcd2_bak             ); alter table tbl_cust_if_seller drop (curcd3_bak             ); alter table tbl_cust_if_seller drop (curcd4_bak               ); alter table tbl_cust_if_seller drop (curcd5_bak               ); alter table tbl_cust_if_seller drop (short_section_curcd_bak);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值