使用INSTR查找分隔符的位置,然后使用SUBSTR提取子字符串:
Oracle 设置:
CREATE TABLE test_data ( value ) AS
SELECT 'APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow^^^APP_APX_PLM_Promo~~~skola2
~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow^^^APP_APX_PLM_Santosh~~~skola2~~~2019-09-30 14:39:26@@@MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow***MF_PKMS_DA_TransferPickInboundPreProcessor.msgflow' FROM DUAL;
查询:
SELECT SUBSTR( value, 1, first_position - 1 ) AS first_substr,
SUBSTR( value, first_position + 3, second_position - first_position - 3 ) AS second_substr
FROM (
SELECT value,
INSTR( value, '^^^', 1, 1 ) AS first_position,
INSTR( value, '^^^', 1, 2 ) AS second_position
FROM test_data
)
输出:
FIRST_SUBSTR | SECOND_SUBSTR
:------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------- | :------------------------------------------------- -------------------------------------------------- --------
APP_APX_PLM_PostCategory~~~pavan anand~~~2019-09-26 15:03:39@@@MF_APX_PLM_PostBuyProgram.msgflow***MF_APX_PLM_PostBuyProgram1.msgflow***MF_APX_PLM_PostBuyProgram2.msgflow | APP_APX_PLM_Promo~~~skola2
~~~2019-09-30 14:34:11@@@MF_APX_PLM_Promo1.msgflow***MF_APX_PLM_Promo2.msgflow
db小提琴here