Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

Rewriting case statement so that indexes can be used

NikJunejaFeb 7 2024

Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production

Hi All,

I am trying to rewrite a query so that index can be used, but when we use use an OR condition, it goes for full table scan:

select  *    FROM  account c
   INNER JOIN xref x ON ltrim(c.acct_no, '0') = ltrim(x.acct_no,'0') 
                         WHERE 
                           AND (
                             :str_branch = 'ALL'
                             or 
                             c.branch_id in 
                                       (
                                          select regexp_substr(:str_branch,'[^,]+', 1, level) from dual
                                          connect by regexp_substr(:str_branch, '[^,]+', 1, level) is not null
                                          )
                           );
Comments
Post Details
Added on Feb 7 2024
3 comments
95 views