1. 程式人生 > >SQL 資料特殊符號切割

SQL 資料特殊符號切割

需求SQL 欄位中的字串拆成多行顯示.

實現:MYSQL SUBSTRING_INDEX(COL1,'字串分隔符號',位置)

SQL: select
 t2.help_topic_id as ID
 ,SUBSTRING_INDEX(SUBSTRING_INDEX(RecordIdentifier,' ',t2.help_topic_id+1),' ',-1) as RecordIdentifier 
,RecordIdentifier
,Substring_index(RecordIdentifier,' ',help_topic_id+1)
from
(select
extractvalue(t1.xml_content,'/DSExport/Job/Record/@Identifier') as RecordIdentifier
   from awm_job t1)
t1 left join mysql.help_topic t2
on t2.help_topic_id < LENGTH(t1.RecordIdentifier)-length(replace(t1.RecordIdentifier,' ',''))+1;

Result: