HEBING字段为空的时候id01字段的数在前面字段里,HEBING字段是两位时,出现在前面和中间

image.png

SELECT  ID01, HEBING,  SUBSTR(case when hebing is null then SUBSTR(HEBING,1,INSTR(HEBING,'''')-1)  else HEBING end ) as 前面,   replace(SUBSTR(HEBING,INSTR(HEBING,',')+1, (INSTR(HEBING,',',1,2)-INSTR(HEBING,',')-1)),chr(39),'') as 中间 ,    replace(SUBSTR(HEBING,INSTR(HEBING,',',1,2)+1) ,chr(39),'') as 最后  from QRQC_TRACK_REPORT FOR UPDATE 这条语句是后来修改了一下的语句  但还是不对 报图2的错

SELECT  ID01, HEBING,  SUBSTR(HEBING,1,INSTR(HEBING,'''')-1) as 前面,   replace(SUBSTR(HEBING,INSTR(HEBING,',')+1, (INSTR(HEBING,',',1,2)-INSTR(HEBING,',')-1)),chr(39),'') as 中间 ,    replace(SUBSTR(HEBING,INSTR(HEBING,',',1,2)+1) ,chr(39),'') as 最后  from QRQC_TRACK_REPORT FOR UPDATE

用户DZNws0326467 发布于 2022-2-21 09:52 (编辑于 2022-2-21 09:56)
1min目标场景问卷 立即参与
回答问题
悬赏:3 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
CD20160914Lv8专家互助
发布于2022-2-21 10:03(编辑于 2022-7-23 17:22)

SELECT  

id01,

HEBING,

case when t.HEBING is null then id01 else  SUBSTR(HEBING,1,INSTR(t.HEBING,'''')-1)  end as 前面,

trim(replace(substr(replace(HEBING,',',lpad(' ',40,' ')) ,15,35),chr(39),''))  as 中间,

trim(replace(substr(replace(HEBING,',',lpad(' ',40,' ')) ,70,35),chr(39),''))  as 最后

 from QRQC_TRACK_REPORT FOR UPDATE

---------------------重新补充答案2022-07-23,以前没有写的语句由于没有模拟数据没有做测试现在重新模拟数据做测试参考如下,你报错的语句是oracel,那么oracel的语句参考如下----------------------

模拟的数据类似如下和你图片一样:

image.png

最后生成的语句

SELECT 

id01,

HEBING,

case when t.HEBING is null then to_char(id01) 

when INSTR(t.HEBING,'''')=0 then t.HEBING else  SUBSTR(HEBING,1,INSTR(t.HEBING,'''')-1)  end as 前面,

trim(replace(substr(replace(HEBING,',',lpad(' ',40,' ')) ,15,35),chr(39),''))  as 中间,

trim(replace(substr(replace(HEBING,',',lpad(' ',40,' ')) ,70,35),chr(39),''))  as 最后

from (

select 1 as id01,'5'||''','''||4 as HEBING from dual

union all

select 2 as id01,null as HEBING from dual

union all

select 3 as id01,'5'||''','''||4||''''||','||'6' as HEBING from dual

union all

select 4 as id01,'6' as HEBING from dual

) t

image.png

  • 2关注人数
  • 336浏览人数
  • 最后回答于:2022-7-23 17:22
    请选择关闭问题的原因
    确定 取消
    返回顶部