1

如果逗号分隔符是字符串的一部分,如何修改以下查询以获得正确的值?

SELECT REGEXP_SUBSTR('141001,update PRDTBL set a10=''141001'' where A03=''62'' and FIX_FLT=''1'' AND SUBSTR(TXN_ID,1,2)=''LN'' AND A05=''N'',62,1,LN,,,,N,FXL BUSINESS (M),FIXED LOANS - OTHERS,,DBA,2013-09-25,DBA,2013-09-25', 
'([^,]*)(,|$)', 1,2, 'i', 1)
FROM DUAL

上面的查询将返回值:

update portfldb set a10='141001' where A03='62' and FIX_FLT='1' AND  SUBSTR(TXN_ID  

期望值应该是:

update portfldb set a10='141001' where A03='62' and FIX_FLT='1' AND SUBSTR(TXN_ID,1,2)='LN' AND A05='N'
4

1 回答 1

0

只要您的语句中没有嵌套括号,您就可以尝试使用以下内容:

SELECT REGEXP_SUBSTR('141001,update PRDTBL set a10=''141001'' where A03=''62'' and FIX_FLT=''1'' AND SUBSTR(TXN_ID,1,2)=''LN'' AND A05=''N'',62,1,LN,,,,N,FXL BUSINESS (M),FIXED LOANS - OTHERS,,DBA,2013-09-25,DBA,2013-09-25', 
'([^,\(]*(\([^\)]*\)[^,\(]*)*)(,|$)', 1,2, 'i', 1)
FROM DUAL;

如果可能有嵌套括号,那么您将无法使用正则表达式获得任何结果-那么您就不走运了:-(

于 2013-09-26T08:25:42.760 回答