使用Like with In选择查询

时间:2016-08-01 15:36:51

标签: java sql oracle select

我有以下查询,搜索匹配字符串的xml列请求。

$("#btnSave5").click(function (e) {
            e.preventDefault();
            var form = $(this).closest("form");

            $.ajax({
                type: "POST",
                url: form.attr("Edit"),
                data: form.serialize(),
                success: function (response) {

                    alert("Informations are successfully changed");
                    window.location.href = "/InspekcijskeKontrole/Index";

                },

                error: function (error) {
                    alert(error);
                }

            });
        });

但是我收到select * from Customer where access like '%USR' and status = 'SUCCESS' and request like '%' || (SELECT REGEXP_SUBSTR(request, '<paes:IdName>PurchaseId</paes:IdName><paes:IdValue>\d+</paes:IdValue>') FROM Customer where request like '%Add%SUB%PRIME%') || '%';

的错误消息

我想要的是搜索与添加具有相同ID的请求,但它不是添加请求。例如....取消订单请求,其中包含用于取消订单的ID号。

如何更改上述使用请求,以便ORA-01427: single-row subquery returns more than one row like'%'|| ...... || '%'

或上述查询的替代方案?

in

将返回多行ID

我想要的是搜索匹配ID的所有请求列。如果我将SELECT REGEXP_SUBSTR(request, '<paes:IdName>PurchaseId</paes:IdName><paes:IdValue>\d+</paes:IdValue>') FROM Customer where request like '%Add%SUB%PRIME%' 替换为like,我会收到in错误。我该如何解决这个问题?

编辑: 示例请求列

ORA-00932: inconsistent datatypes: expected - got CLOB

如果我双击HUGECLOB,我会得到完整的请求,如下所示......

Request
(HUGECLOB)
(HUGECLOB)
(HUGECLOB)
...

以下是取消请求的示例

<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header>
        <wsse:Security
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            SOAP-ENV:mustUnderstand="1">
            <wsse:UsernameToken
                xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                wsu:Id="uuid_86c8ee4f-b6e6-4e07-9fa6-e2f9f2695c01">
                <wsse:Username>admin</wsse:Username>
                <wsse:Password
                    Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">mx9483</wsse:Password>
            </wsse:UsernameToken>
        </wsse:Security>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
     ....
    <paes:IdName>PurchaseId</paes:IdName>
    <paes:IdValue>2786872</paes:IdValue>
     ....
    <paes:IdName>MailAddressId</paes:IdName>
    <paes:IdValue>2786622</paes:IdValue>
     ....
    </SOAP-ENV:Body>

1 个答案:

答案 0 :(得分:0)

因为sopa消息是正常的xml文档。它可以通过更加结构化的方式处理。

准备测试数据库;

create table rr (id number, requext clob) ;

短信息版本。

insert into rr values(1, '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body xmlns:paes="emvin.atl/schema/v1">
      <paes:IdName>PurchaseId</paes:IdName>
      <paes:IdValue>2786872</paes:IdValue>
      <paes:IdName>MailAddressId</paes:IdName>
      <paes:IdValue>2786622</paes:IdValue>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>');
insert into rr values(2, '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body  xmlns:paes="emvin.atl/schema/v1">
    <paes:IdName>CancelId</paes:IdName>
    <paes:IdValue>2786872</paes:IdValue>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>');

使用xmltable函数,我们可以提取paes:IdValue。

select * from rr,xmltable( xmlnamespaces('emvin.atl/schema/v1' as "paes"), '$doc//paes:IdValue' passing xmltype(rr.requext) as "doc" 
columns  IdValue  number path './text()'
) ;

现在,您可以从之前的查询创建视图,或者只在with语句中使用它。

with test as (
select * from rr,xmltable( xmlnamespaces('emvin.atl/schema/v1' as "paes"), '$doc//paes:IdValue' passing xmltype(rr.requext) as "doc" 
columns  IdValue  number path './text()'
)) 
select * from test where IdValue in (select IdValue from test where id =1) 
 and id != 1;

xquery

xmltable

相关问题