[英]Getting ORA-01427 error and ORA-00907 error in subquery
I got this in a query which works normally: 我在正常工作的查询中得到了这个:
decode(substr(X_AV_ID,1,3)
,'ECU','eCom'
, decode(aven.lib, 'eCom', 'eCom','Autre')) flag,
Then I want to add a new parameter (aven.lib Like '%Extra%' and to decode it as 'extra'). 然后,我想添加一个新参数(像'%Extra%'这样的aven.lib并将其解码为'额外')。
So I create a subquery with a case to do it: 所以我创建一个带有案例的子查询来做到这一点:
decode(substr(X_AV_ID,1,3),
'ECU', 'eCom',
(select Case
When aven.lib = 'eCom' Then 'eCom'
When aven.lib Like '%Extra%' Then 'extra'
Else 'Autre'
End
From table_x aven
Limit 1
)
) flag
I limit the result to 1 to evit the ORA-01427 error, but now I got the ORA-00907 error. 我将结果限制为1以引发ORA-01427错误,但是现在我收到了ORA-00907错误。
I wanted to use the like in the decode command but it is not available. 我想在解码命令中使用like,但是它不可用。
Thanks for helping. 感谢您的帮助。
First, rewrite your decode
as a case
: 首先,将您的decode
重写为一个case
:
(case when substr(X_AV_ID, 1, 3) = 'ECU' then 'eCom'
when aven.lib = 'eCom' then 'eCom'
then 'Autre'
end) as flag
Presumably, aven
is already in the query. 据推测, aven
已经在查询中。 So, you can just do: 因此,您可以执行以下操作:
(case when substr(X_AV_ID, 1, 3) = 'ECU' then 'eCom'
when aven.lib = 'eCom' then 'eCom'
when aven.lib like '%Extra%' then 'extra'
then 'Autre'
end) as flag
Note: I would consistently use like
for the first comparison as well and would probably combine the first two: 注意:我也会一如既往地将like
用作第一个比较,并且可能会合并前两个:
(case when X_AV_ID like 'ECU%' or aven.lib = 'eCom'
then 'eCom'
when aven.lib like '%Extra%'
then 'extra'
then 'Autre'
end) as flag
Using the regexp_like in the case works great, and I get the result excepted. 在这种情况下使用regexp_like效果很好,但得到的结果除外。
Case
When substr(X_AV_ID,1,3) = 'ECU' Then 'eCom'
When aven.lib= 'eCom' Then 'eCom'
When REGEXP_LIKE (aven.X_AV_LIBELLE, 'extra', 'i') Then 'extra'
Else 'Autre'
End
Thank you for your help 谢谢您的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.