在线急等

Sprit_lc 2018-02-01 10:16:27


表中的CustomerCode排序是错乱的,我们要处理这批数据,
1.写SQL语句取CustomerCode列中后五位的数字结构的最大值

2.生成新的编码方式插入到NewCode,编码方式要求采用C00001的形式,
其中C是固定的,后面五位按照CustomerCode列后五位的升序,从1开始
...全文
1281 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcs_zzh 2018-02-13
  • 打赏
  • 举报
回复
查询可以用这个语句:
SELECT id, customercode, to_number(regexp_substr(customercode, '(\d)+$', 1, 1)),
       'C' ||
        to_char(row_number() over(ORDER BY to_number(regexp_substr(customercode, '(\d)+$', 1, 1))),
                'fm09999') newcode
  FROM crm_customerinfo;
zcs_zzh 2018-02-13
  • 打赏
  • 举报
回复
更新Newcode字段可以用这个语句:
UPDATE crm_customerinfo a
   SET a.newcode =
        (SELECT newcode
           FROM (SELECT id, customercode, to_number(regexp_substr(customercode, '(\d)+$', 1, 1)),
                         'C' ||
                          to_char(row_number()
                                  over(ORDER BY to_number(regexp_substr(customercode, '(\d)+$', 1, 1))),
                                  'fm09999') newcode
                    FROM crm_customerinfo) b
          WHERE b.id = a.id);
孙庆新 2018-02-12
  • 打赏
  • 举报
回复
substr函数
liu志坚 2018-02-01
  • 打赏
  • 举报
回复
哥们,你那个帖子不是回你了么

3,492

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧