SQL ALIAS不在select语句中工作

时间:2015-01-29 16:02:42

标签: sql oracle alias

我有2个select语句,其中我想在Select查询中使用此语句的结果作为ALIAS以获得结果。但我在查询的最后一行收到错误ORA-00933: SQL command not properly ended。我不知道我错过了什么。 这是我的疑问:

Select(SELECT xt.id
FROM SOAP_MONITORING sm
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
      'http://service.soap.CDRator.com' as "ns",
      'http://core.data.soap.CDRator.com/xsd' as "ax2130",
      'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147"
    ),
    'for $i in /soapenv:Envelope/soapenv:Body/ns:placeShopOrderResponse/ns:return/ax2147:subscriptions
      return $i/ax2130:id'
    passing XMLType(sm.RESPONSE_XML)
    columns "ID" number path '/')) AS xt,
    (SELECT xx.id
FROM SOAP_MONITORING sm
CROSS JOIN XMLTable(XMLNAMESPACES (
       'http://webshop.data.soap.CDRator.com/xsd' as "ns7"
    ),
    'for $i in //ns7:orderType return $i'
    passing XMLType(sm.REQUEST_XML)
    columns "ID" VARCHAR2(30) path '/')) AS xx
    FROM SOAP_MONITORING
where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder' and xx.id = 'NEW' ;

1 个答案:

答案 0 :(得分:0)

您不需要执行子查询,您可以从同一passing目标中获得两个XMLTable子句:

SELECT xt_res.id
FROM SOAP_MONITORING sm
CROSS JOIN XMLTable(XMLNAMESPACES (
      'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
      'http://service.soap.CDRator.com' as "ns",
      'http://core.data.soap.CDRator.com/xsd' as "ax2130",
      'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147"
    ),
    'for $i in /soapenv:Envelope/soapenv:Body/ns:placeShopOrderResponse/ns:return/ax2147:subscriptions
      return $i/ax2130:id'
    passing XMLType(sm.RESPONSE_XML)
    columns "ID" number path '/') xt_res
CROSS JOIN XMLTable(XMLNAMESPACES (
       'http://webshop.data.soap.CDRator.com/xsd' as "ns7"
    ),
    'for $i in //ns7:orderType return $i'
    passing XMLType(sm.REQUEST_XML)
    columns "ORDER_TYPE" VARCHAR2(30) path '/') xt_req
where sm.WEB_SERVICE_NAME='RatorWebShopService'
and sm.WEB_METHOD_NAME='placeShopOrder'
and xt_req.order_type = 'NEW' ;  


                   ID
---------------------
   201501070917439804 
   201501070917439804 

使用上一个问题中的示例XML,包括来自回滚编辑的请求,这些请求都已清理为有效...


根据continued in chat的讨论,要从wf_workflow表中获取与此匹配的ID的数据,您可以使用join

SELECT wf.* from 
SOAP_MONITORING sm 
CROSS JOIN XMLTable(XMLNAMESPACES ( 
      'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
      'http://service.soap.CDRator.com' as "ns",
      'http://core.data.soap.CDRator.com/xsd' as "ax2130",
      'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147"
), 
'for $i in /soapenv:Envelope/soapenv:Body/ns:placeShopOrderResponse/ns:return/ax2147:subscriptions 
return $i/ax2130:id' 
passing XMLType(sm.RESPONSE_XML) 
columns "ID" number path '/') xt_res 
CROSS JOIN XMLTable(XMLNAMESPACES ( 
       'http://webshop.data.soap.CDRator.com/xsd' as "ns7"
), 
'for $i in //ns7:orderType return $i' 
passing XMLType(sm.REQUEST_XML) 
columns "ORDER_TYPE" VARCHAR2(30) path '/') xt_req 
JOIN WF_WORKFLOW wf 
on wf.SUBSCRIPTION_ID = xt_res.id 
where sm.WEB_SERVICE_NAME='RatorWebShopService' 
and sm.WEB_METHOD_NAME='placeShopOrder' 
and xt_req.order_type = 'NEW'
and WF.NAME='INITIATE_MANDATE' 
and WF.STATUS_ID=0;

或者将早期查询包含为in子句;这可能更容易理解,但在功能上是等效的(除了压缩重复,你说你不会有),并且可能与join版本有不同的性能:

SELECT wf.* 
from WF_WORKFLOW wf 
where wf.SUBSCRIPTION_ID in ( 
  select xt_res.id 
  from SOAP_MONITORING sm 
  CROSS JOIN XMLTable(XMLNAMESPACES ( 
        'http://schemas.xmlsoap.org/soap/envelope/' AS "soapenv",
        'http://service.soap.CDRator.com' as "ns",
        'http://core.data.soap.CDRator.com/xsd' as "ax2130",
        'http://webshop.result.service.soap.CDRator.com/xsd' as "ax2147"
  ), 
  'for $i in /soapenv:Envelope/soapenv:Body/ns:placeShopOrderResponse/ns:return/ax2147:subscriptions 
  return $i/ax2130:id' 
  passing XMLType(sm.RESPONSE_XML) 
  columns "ID" number path '/') xt_res 
  CROSS JOIN XMLTable(XMLNAMESPACES ( 
         'http://webshop.data.soap.CDRator.com/xsd' as "ns7"
  ), 
  'for $i in //ns7:orderType return $i' 
  passing XMLType(sm.REQUEST_XML) 
  columns "ORDER_TYPE" VARCHAR2(30) path '/') xt_req 
  where sm.WEB_SERVICE_NAME='RatorWebShopService' 
  and sm.WEB_METHOD_NAME='placeShopOrder' 
  and xt_req.order_type = 'NEW'
) 
and WF.NAME='INITIATE_MANDATE' 
and WF.STATUS_ID=0;