我有一个SOAP_MONITORING表,它有一个RESPONSE_XML列,它是
CLOB
数据类型,由大字符串组成。我需要获取并显示隐藏在此字符串中的所有SUBSCRIPTION_ID。 SUBSCRIPTION_ID位于此字符串中:<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>201411211617575057</ax2130:id>
。我必须得到所有ID,这只是我的SUBSCRIPTION_ID,它位于<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id> and </ax2130:id> string
之间。我尝试了以下查询:
SELECT REPLACE(REPLACE(MatchedId, '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>', ''), '</ax2130:id>', '')
FROM
(
SELECT REGEXP_SUBSTR(RESPONSE_XML, '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>\d+</ax2130:id>')
FROM SOAP_MONITORING
)
WHERE
WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
但收到了空洞的结果。
答案 0 :(得分:2)
我认为这是正则表达式可以帮助您的情况。 here是oracle文档的参考。
正则表达式可能类似于:
<ax2130:id>\d+</ax2130:id>
如果您的ID仅为数字。
以下是您可以使用的示例查询:
SELECT REPLACE(REPLACE(MatchedId, '<ax2130:id>', ''), '</ax2130:id>', '') AS CleanMatch
FROM
(
SELECT REGEXP_SUBSTR(RESPONSE_XML, '<ax2130:id>\d+</ax2130:id>') AS MatchedId
FROM SOAP_MONITORING
)
WHERE
MatchedId is not null
答案 1 :(得分:0)
CLOB
无法像varchar
那样以多种方式处理如果您的列包含XML,则应考虑使用Oracles xmltype
数据类型。在这种情况下,您可以使用XML-Tools查询您的数据:即
select extractvalue(response_xml, '/response_xml/id/text()')
from soap_monitoring
order by extractvalue(response_xml, '/response_xml/id/text()') desc
答案 2 :(得分:0)
请检查下面的编辑问题
with unique_data as (select '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO">' data from dual)
select SUBSTR(MatchedId,instr(MatchedId,'>')+1 , instr(MatchedId,'</') - length('</ax2130:id>')) from
(
SELECT replace(dbms_lob.substr(RESPONSE_XML,length(response_xml),dbms_lob.instr(response_xml,data)),data,'') AS MatchedId
FROM SOAP_MONITORING,unique_data
)
WHERE
MatchedId is not null;