【发布时间】:2015-02-02 14:52:37
【问题描述】:
我有由大字符串组成的列RESPONSE_XML and REQUEST_XML。我对这个大字符串使用了 substring 函数,以便从 RESPONSE_XML 中获取 SUBSCRIPTION_ID 并从 REQUEST_XML 中获取 orderType。查询工作正常。但现在我想为这个查询设置条件,使其只返回 orderType='NEW' 的 SUBSCRIPTION_ID。我将两个子字符串的结果存储到别名中,并在 where 条件下使用这些别名。但它不起作用并给出错误ORA-01722 Invalid numnber。这是我的查询:
SELECT REPLACE(REPLACE(REGEXP_SUBSTR(RESPONSE_XML, '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>\d+</ax2130:id>'),
'<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>', ''), '</ax2130:id>', '')
AS SUBSCRIPTION_ID ,
REPLACE(REPLACE(REGEXP_SUBSTR(REQUEST_XML, '<ns7:orderType>\d+</ns7:orderType>'), '<ns7:orderType>', ''), '</ns7:orderType>', '')
AS order_type
FROM
SOAP_MONITORING
where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
and order_type='NEW' order by CREATE_DATE desc
我也尝试过以这种方式查询,但结果是错误,即第 10 行的 ORA-00932 数据类型不一致
SELECT REPLACE(REPLACE(REGEXP_SUBSTR(RESPONSE_XML, '<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>\d+</ax2130:id>'),
'<ax2147:subscriptions xsi:type="ax2127:SubscriptionDTO"><ax2130:id>', ''), '</ax2130:id>', '')
AS SUBSCRIPTION_ID from SOAP_MONITORING
where
REQUEST_XML
in
(
REPLACE(REPLACE(REGEXP_SUBSTR(REQUEST_XML, '<ns7:orderType>\d+</ns7:orderType>'), '<ns7:orderType>', ''), '</ns7:orderType>', '')
)
and WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder' and REQUEST_XML='NEW'
【问题讨论】:
-
您不能在
where子句中使用alases。使用子查询或 CTE。 -
因为在定义列别名之前定义(逻辑执行)结果集行。
-
哦,好的,我将尝试使用 nusing 子查询运行查询。
-
请检查我写的另一个查询但结果错误的问题
标签: sql oracle substring alias where-clause