简体   繁体   中英

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').

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM