Upper and lowercase in a query

Posted on 2005-04-26
Last Modified: 2013-12-09
I have a table where the users may enter names in upper and/or lowercase. I could have, for example, NAME1 equal to 'ABEL MARY' and NAME2 equal to 'deBlank John'. The query in the code does the following:

select count(*) from table
where upper(name) >= :NAME1
and upper(name) <= :NAME2

but that is obviously resulting in a restricted data set and it does not covers the lowercase names. Considering that the user may type either NAME1 and/or NAME2 with upper or lowercases, how would it be the best way to cover all the data range in the table?

Question by:hcarvajal
    LVL 19

    Accepted Solution

    the usual way is to add an additional field to the table, called, say UPPERNAME

    populate it with triggers that contain

    new.UPPERNAME = UPPER(name)

    then always do your search against UPPERNAME

    there are other ways, such as using specific character sets and collations but this is the simplest

    this way the database doesn't need to convert every record to uppercase everytime the query is run
    LVL 19

    Expert Comment

    by:Gary Benade
    select count(*) from table
    where upper(name) >= upper(:NAME1)
    and upper(name) <= upper(:NAME2)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
    SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now