0

我有一张这样的桌子

name Description
VM1  SP L A - WINSVRS #P19  QTY 1
VM2  SPLA - VRSTD #P29-9 9 99 QTY 2 : SPLVRENT #P3 999999 9 QTY 3
VM3  SPLA - WINSVRSTD #P39-9 999 QTY 3
VM4  SPLA - WI NS V R STD #P59- 9 9 99 QTY 2 : S P LA - W IN SV RENT #P39-9999 QTY 3 :   SPLA - WIN S VR SMB # P 3 9- 999 99 QTY 5
VM6  SPLA - WINSVRSQLSERVERaaaaaaaaaSTD #P 6 9-9 9 9 9 QTY 6

我需要这样的输出

name Description                     ponumber
-------------------------------------------------
VM1  SP L A - WINSVRS                   P19 
VM2  SPLA - VRSTD                       P29-9 9 99                      
VM2  SPLVRENT                           P3 999999 9
VM3  SPLA - WINSVRSTD                   P39-9 999
VM4  SPLA - WI NS V R STD               P59- 9 9 99
VM4  S P LA - W IN SV RENT              P39-9999
VM4  SPL A - WIN S VR SMB               P 3 9- 999 99
VM6  SPLA - WINSVRSQLSERVERaaaaaaaaaSTD P 6 9-9 9 9 9

帮助我如何使用子字符串和使用循环的 instr 字符串获取输出

感谢和问候阿南德

4

1 回答 1

2

尝试这个

with CTE as
(
  select name, 
  trim(cast(v.column_value.extract('//text()') as varchar2(50))) description
  from t,
  table( xmlsequence( xmltype(
    '<descriptions><description>' 
     || replace(description, ':', '</description><description>') 
     || '</description></descriptions>'
        ).extract('//descriptions/*'))) v
 )
select 
 name,
 REGEXP_SUBSTR(description,'[^#]+') description,
 --REGEXP_SUBSTR(description,'[^#]+',1,2) phnQty,
 Trim(REGEXP_SUBSTR(REGEXP_SUBSTR(description,'[^#]+',1,2),'[^Q]+')) phn
from cte;

SQL 演示

于 2013-03-21T14:08:10.817 回答