ALIAS 在 where 子句中不起作用
ALIAS in where clause not working
我有包含大字符串的列 RESPONSE_XML and REQUEST_XML
。为了从 RESPONSE_XML 获取 SUBSCRIPTION_ID 和从 REQUEST_XML 获取 orderType,我对这个大字符串使用了 substring 函数。查询工作正常。但是现在我想为这个查询设置条件,这样它应该只 return SUBSCRIPTION_ID where orderType='NEW'
。我将 Substring 的结果都存储到别名中,并在 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),您可以使用 内联视图(也称为子查询,尽管子查询实际上更常用于不同的事情)或常见的 table 表达式(也称为 CTE 或 "with" 子句)。
内联视图你可以这样做:
select iw.order_type
from (
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,
CREATE_DATE
FROM
SOAP_MONITORING
where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
) iw
where iw.order_type='NEW'
order by iw.CREATE_DATE desc
常见的table表达式你可以这样做:
with cte as (
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,
CREATE_DATE
FROM
SOAP_MONITORING
where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
)
select cte.order_type
from cte
where cte.order_type='NEW'
order by cte.CREATE_DATE desc
我有包含大字符串的列 RESPONSE_XML and REQUEST_XML
。为了从 RESPONSE_XML 获取 SUBSCRIPTION_ID 和从 REQUEST_XML 获取 orderType,我对这个大字符串使用了 substring 函数。查询工作正常。但是现在我想为这个查询设置条件,这样它应该只 return SUBSCRIPTION_ID where orderType='NEW'
。我将 Substring 的结果都存储到别名中,并在 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),您可以使用 内联视图(也称为子查询,尽管子查询实际上更常用于不同的事情)或常见的 table 表达式(也称为 CTE 或 "with" 子句)。
内联视图你可以这样做:
select iw.order_type
from (
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,
CREATE_DATE
FROM
SOAP_MONITORING
where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
) iw
where iw.order_type='NEW'
order by iw.CREATE_DATE desc
常见的table表达式你可以这样做:
with cte as (
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,
CREATE_DATE
FROM
SOAP_MONITORING
where WEB_SERVICE_NAME='RatorWebShopService' and WEB_METHOD_NAME='placeShopOrder'
)
select cte.order_type
from cte
where cte.order_type='NEW'
order by cte.CREATE_DATE desc