Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6843085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:12:13+00:00 2026-05-27T00:12:13+00:00

I am working on Oracle 10gR2 I have a MERGE statement for a table,

  • 0

I am working on Oracle 10gR2

I have a MERGE statement for a table, TBL_CUSTOMER. TBL_CUSTOMER contains a column USERNAME, which contains email addresses. The data stored in this table is case insensitive, as in, the incoming data can be in upper case, lower case or any combination of cases.

While merging the data, I have to ensure that I compare data without considering case. I have created a function bases index on USERNAME column as UPPER(USERNAME).

MERGE INTO tbl_customer t
      USING (SELECT /*+ dynamic_sampling(a 2) */  NVL(
                                                      (x.username||decode((x.cnt+x.rn-1),0,null,(x.cnt+x.rn-1))),
                                                      t1.cust_username
                                                     ) community_id
                               ,DECODE (source_system_name,'SYS1', t1.cust_firstname,t1.cust_username) display_name
                               ,t1.cust_username
                              ,t1.cust_id cust_id
                              ,t1.cust_account_no cust_account_no
                              ,t1.cust_creation_date
                              ,t1.source_system_name
                              ,t1.seq_no
                              ,nvl(t1.cust_email,'NULLEMAIL') cust_email
                              ,t1.file_name
                              ,t1.diakey
                              ,t1.sourcetupleidcustmer
                              ,DECODE (source_system_name,'SYS1','DefaultPassword',t1.cust_password) cust_password
             FROM   gtt_customer_data t1,
                    (SELECT a.username,
                            cust_id,
                            row_number() over(partition by lower(a.username) order by  seq_no) rn,
                            (SELECT count(community_id)FROM TBL_customer where regexp_like (lower(community_id) ,'^'||lower(a.username)||'[0-9]*$'))cnt
                     FROM   gtt_cust_count_name a  
                    ) x
             WHERE  t1.cust_status = 'A'
             AND    x.cust_id(+)  = t1.cust_id
             AND    nvl(t1.op_code,'X') <> 'D'
             AND    t1.cust_id is not null
             AND    cust_email is not null
            ) a
      ON    ( 
             (a.sourcetupleidcustmer = t.source_tuple_id AND a.source_system_name =t.created_by)
             OR 
             ( upper(a.cust_email) = upper(t.username) AND a.source_system_name ='SYS2' )
            )

When I check the explain plan, the function based index on USERNAME is not being used. I noticed that if I remove the OR condition, the index is used, but I cannot remove that, due to complex business logic.

How can I force that index to be used?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:12:13+00:00Added an answer on May 27, 2026 at 12:12 am

    Oracle lets you create function-based index, in your case on upper(username). You can also try INDEX hint in the query , but I think in your case function based index is a much better solution.

    BTree indexes are not normally used if the index field is an argument of a function (assuming the function in WHERE and it’s not a covering index). For instance, WHERE trunc(date_field) = trunc(sysdate()) will not use index on date_field, but will use index on (trunc(date_field)).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on Oracle 10g.One of the column's of my table stores data, as
I have SQL query, which is working nice on Oracle and MSSQL. Now I'm
I'm working on Oracle and Perl. I have three fields in a table (A,
I'm working on oracle 9i. I have a table with 135,000,000 records, partitioned where
I am working on Oracle. I have this large property-indexer table ( THE_TABLE ),
I have an existing table in an Oracle 10gR2 that I added a XMLTYPE
What does operation column in plan table do?? I am working on Oracle 10g
We are working with an oracle database in which the person that set it
I am working with a oracle database and Jython. I can get data pulled
I'm Working with a new Oracle DB, with one table having the following indexes:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.