号码升位sql,Oracle

电话号码需要升多一位,所以数据库里的数据电话,传真都需要跟着修改。
比如最近像中山2、3字头的号码加2,其余号码加8
company_city  城市的ID
t.company_fox  公司的传真

1。分别查询出需要修改的号码(以t_company_subjoin为例,要更新传真字段)
   需要加‘8’的:
   select t.* from t_company_subjoin t
    where (substr(t.company_fox,1,1) in ('1','4','5','6','7','8','9'))
     and length(trim(t.company_fox))=7
     and t.company_fox is not null
     and t.company_id in
      (select company_id from t_company where company_city='442001')
   需要加‘2’的:   
   select * from t_company_subjoin t
    where (substr(t.company_fox,1,1) in ('2','3'))
     and length(trim(t.company_fox))=7
     and t.company_fox is not null
     and t.company_id in
      (select company_id from t_company where company_city='442001')
    
2。批量修改(以t_company_subjoin为例)
   需要加‘8’的:
   update t_company_subjoin t set t.company_fox='8'||trim(t.company_fox)
    where (substr(t.company_fox,1,1) in ('1','4','5','6','7','8','9'))
     and length(trim(t.company_fox))=7
     and t.company_fox is not null
     and t.company_id in
      (select company_id from t_company where company_city='442001')
    
   需要加‘2’的:   
   update t_company_subjoin t set t.company_fox='2'||trim(t.company_fox)
    where (substr(t.company_fox,1,1) in ('2','3'))
     and length(trim(t.company_fox))=7
     and t.company_fox is not null
     and t.company_id in
      (select company_id from t_company where company_city='442001')

3。个别补漏    
   select t.* from t_company_subjoin t
    where length(t.company_fox)<>8
     and t.company_fox is not null
     and t.company_id in
      (select company_id from t_company where company_city='442001')

你可能感兴趣的:(oracle)