oracle 基于字符的PL/SQL中断列[重复]

piztneat  于 2023-11-17  发布在  Oracle
关注(0)|答案(1)|浏览(189)

此问题在此处已有答案

oracle split comma delimited string into columns [duplicate](2个答案)
Split comma separated values to columns in Oracle [duplicate](4个答案)
Split varchar into separate columns in Oracle(3个答案)
上个月关门了。
列名:Full_address

"B230 E Campus; 3405; Mail Code: 600 W 110th Street; Dallas NY 10027; United States"

字符串
你好,我有上面的例子,我想打破它成不同的列的基础上的字符或只是半列(;)
我尝试了各种行,但都不起作用。左/右和CHARINDEX不适用于我的PL/SQL Oracle版本。

regexp_substr(Full_address,'[^[:print:]]|,/')
  SUBSTR (t.address_one_line, INSTR('_', Full_address)-10),
  regexp_substr(upper(Full_address), '(^\w+)-', ,, 10, 'i', 10)


I want 5 columns 
B230 E Campus
3405  
Mail Code: 600 W 110th Street
Dallas NY 10027
United States

vx6bjr1n

vx6bjr1n1#

这里有一种方法。with子句只是设置测试数据。基本上选择一组字符的第n个示例,后面跟着一个分号,然后是零个或多个空格(消耗空格,从而节省了对TRIM()的调用)或行尾。

with tbl(str) as (
  select 'B230 E Campus; 3405; Mail Code: 600 W 110th Street; Dallas NY 10027; United States'
    from dual
)
select regexp_substr(str, '(.*?)(; *|$)', 1, 1, null, 1) as col_1,
       regexp_substr(str, '(.*?)(; *|$)', 1, 2, null, 1) as col_2,
       regexp_substr(str, '(.*?)(; *|$)', 1, 3, null, 1) as col_3,
       regexp_substr(str, '(.*?)(; *|$)', 1, 4, null, 1) as col_4,
       regexp_substr(str, '(.*?)(; *|$)', 1, 5, null, 1) as col_5
from tbl;

COL_1         COL_2 COL_3                         COL_4           COL_5        
------------- ----- ----------------------------- --------------- -------------
B230 E Campus 3405  Mail Code: 600 W 110th Street Dallas NY 10027 United States

字符串

相关问题