sql:查出某字段,并分割成多个列

需求:实现把out分割成O1、O2;A分割成A1,A2,即:

1、sql如下:

SELECT distinct REGEXP_SUBSTR(q.bin, '[^,]+', 1, LEVEL, 'i') AS STR  
  FROM  (
  select distinct 
    case bin 
    when 'out' then 'O1,O2'
     when 'A' then 'A1,A2'
    end bin
    from  wms_blc_current_detail
  ) q   where bin is not null
CONNECT BY LEVEL <= LENGTH(q.bin) - LENGTH(REGEXP_REPLACE(q.bin, ',', '')) + 1; 

2、运用到的知识点:
regexp_substr函数 [String] :使用正则表达式从字符串中抽取子串。

REGEXP_REPLACE:正则替换

猜你喜欢

转载自blog.csdn.net/qq_37986863/article/details/85061070