Reputation: 11
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').
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.
I wanted to use the like in the decode command but it is not available.
Thanks for helping.
Upvotes: 0
Views: 105
Reputation: 11
Using the regexp_like in the case works great, and I get the result excepted.
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
Upvotes: 0
Reputation: 1269803
First, rewrite your decode
as a 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. 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:
(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
Upvotes: 1