Link to home
Start Free TrialLog in
Avatar of mukeshkt
mukeshkt

asked on

DB2 stored procedure for removing the special character from db

hi all,
 i want to have one stored procedure to remove special characters from dbase and print the report
 and after that it will concatenate the other string and update the db.
i am using db2.
ex-- ASDBH&WE -----> ASDBHWE
 
        ASDB_EW ----->ASDBEW

       ASEDE%DV---->ASEDEDV
       
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

what do you mean - remove from db?
do you need to remove from a specific table or from all tables ?
basically this can be done using a single sql statement

update table_name
set column_name = case when posstr(column_name, '&') > 0 then replace(columns_name, '&', '')
   when posstr(column_name, '_') > 0 then replace(columns_name, '_', '')
   when posstr(column_name, '%') > 0 then replace(columns_name, '%', '')
 end
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Here's the way I usually accomplish that kind of thing:

upda
set text = translate(text,' ','&_%', ' ');

I find that much simpler than multiple levels of REPLACE functions.

HTH,
DaveSlash

Hi, Dave!

Great idea, except that I think the poster wants the character(s) removed from the name, not replaced with a blank.


Kent


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Excellent point, Momi.

How about this:
replace(translate(avarchar25,'~','abc', '~'),'~', '')

As long as you can ensure that there are no tildes in the string, then that should work.

-- DaveSlash

or more accurately:

replace(translate(avarchar25,'~','&_%', '~'),'~', '')
Hi Dave.

Just change all of the questionable characters to the same questionable character with translate, then delete it with a call to replace.  No hunting for an unused character is necessary.

  replace(translate(avarchar25,'&','_%', '&'),'&', '')


Speaking of questionable characters...

Well, never mind.  :)


Kent

> Speaking of questionable characters

Hey, I resemble that remark!  :-)  :-)
Avatar of mukeshkt
mukeshkt

ASKER

please close this question
was your problem solved?