Remove punctuation, spaces and capitalization using DB2 SQL Query

Posted on 2004-11-23
Last Modified: 2012-06-27
Hi to all,

I have a question. Can we remove punctuation, spaces and capitalization from the field using DB2 SQL query or not? Actually, I come to the point where I need to compare a field excluding all the punctuation, spaces and capitalization. In other words just including alpha-numeric characters. Is there any DB2 SQL function to return just alpha-numeric characters out of string field?

If there is any confusion or any further question, please feel free to ask me.

Sharad Bajracharya
Question by:sharadrb
    1 Comment
    LVL 50

    Accepted Solution

    you may get a better response in the DB2/UDB topic area

    what particular version and OS of DB2 are you using?

    you can/should be able to achieve what you desire....

    the REPLACE FUNCTION TO replace all the punctuation symbols that are present
    (unfortuantley you have to specify each one)
    and use UPPER to convert everything to the same (upper case (or LOWER) )



    Upper(STRIP(COLUMNNAME,B,' '))          -- remove leading and trailing spaces from the column and convert to upper case...  
    ,',','')                                                    -- convert commas to empty strings
    ,' ','')                                                    -- convert embedded spaces to empty strings
    ,'.','')                  -- fullstops
    ,'''','')                 -- single quotes
    ,'"','')                 -- double quotes may need to use '""',''  

    and so one keep adding replace (.... ,string to replace, emmpty string) until all the puncutation is gone....

    you may want to establish this is a view on the table...

    alternativly you could put this into a stored procedure of function depending on the DB2/UDB version.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    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…

    779 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

    16 Experts available now in Live!

    Get 1:1 Help Now