Home » SQL & PL/SQL » SQL & PL/SQL » Replace multiple value in single column. (oracle 10g r2)
Replace multiple value in single column. [message #510786] Tue, 07 June 2011 14:34 Go to next message
dkdms2124
Messages: 369
Registered: April 2010
Location: INDIA
Senior Member

Hi All,

I am facing some problem, while fetching the result that I want to. Let me first explain the situation to you.

I have a table with name "test", there are two columns
"id" type int
"text_data" type varchar2(2000)

Sample Data:

ID        TEXT_DATA
-------   ------------
10        Hi Deepak, My designation id is dsha21. Thanks Rohit



Now I tried to replace the value for "Deepak","dsha21" and "Rohit" using nested replace function and I succeded but that was for static.

Now I want the help of my seniors while creating SQL procedure where I am going to make the values of "Deepak","dsha21" and "Rohit" some static variables. I want to pass the values to be replaced with static parameter.

If I give you simple example of my requirement that would be example of a sms send to all customers by a telephone company.
Content is same only the Name of customer is replaced everytime.

Hope I have made my requirement clear to all my senior expertise.

Thanks in advance.

Regards
Deepak
Re: Replace multiple value in single column. [message #510790 is a reply to message #510786] Tue, 07 June 2011 14:44 Go to previous messageGo to next message
knight
Messages: 111
Registered: January 2009
Senior Member
please post the procedure you are trying to create
Re: Replace multiple value in single column. [message #510791 is a reply to message #510790] Tue, 07 June 2011 14:47 Go to previous messageGo to next message
dkdms2124
Messages: 369
Registered: April 2010
Location: INDIA
Senior Member

This is the procedure I created but it is only for two variables.

create procedure test_p (out a text, out b text,in p1 text, in p2 text)
select replace(replace(text_data,'p1','a'),'p2','b') from test_tb where id=10;


Thanks
Deepak
Re: Replace multiple value in single column. [message #510792 is a reply to message #510791] Tue, 07 June 2011 14:50 Go to previous messageGo to next message
knight
Messages: 111
Registered: January 2009
Senior Member
and this piece of code compiles successfully??!!
Re: Replace multiple value in single column. [message #510793 is a reply to message #510792] Tue, 07 June 2011 14:53 Go to previous messageGo to next message
dkdms2124
Messages: 369
Registered: April 2010
Location: INDIA
Senior Member

the procedure was created successfully but it didnot run.
Please correct me if something my approach is wrong Sir.

Thanks
Deepak
Re: Replace multiple value in single column. [message #510796 is a reply to message #510793] Tue, 07 June 2011 15:19 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
dsharma wrote on Tue, 07 June 2011 15:53
the procedure was created successfully but it didnot run.


SQL> create procedure test_p (out a text, out b text,in p1 text, in p2 text)
  2  select replace(replace(text_data,'p1','a'),'p2','b') from test_tb where id=10;
  3  /

Warning: Procedure created with compilation errors.

SQL> show err
Errors for PROCEDURE TEST_P:

LINE/COL ERROR
-------- -----------------------------------------------------------------
1/25     PLS-00103: Encountered the symbol "TEXT" when expecting one of
         the following:
         := . ) , @ % default character

Re: Replace multiple value in single column. [message #510797 is a reply to message #510796] Tue, 07 June 2011 15:27 Go to previous messageGo to next message
dkdms2124
Messages: 369
Registered: April 2010
Location: INDIA
Senior Member

sorry it was by mistake, actually I tried the same for mysql as well so the tex type is used in mysql, we can replace that with varchar here.

Can you provide me the solution how this can be achived.

Thanks
Deepak
Re: Replace multiple value in single column. [message #510808 is a reply to message #510797] Tue, 07 June 2011 22:40 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
1/ Declare a variableto get the query value
2/ Add an INTO clause to get the query value
3/ Remove ' around variable names in the query
4/ Transform your procedure into a function to get the query value
5/ Read the following books as these are basic syntax questions:
PL/SQL User's Guide and Reference
Application Developer's Guide - Fundamentals

Regards
Michel

Re: Replace multiple value in single column. [message #510817 is a reply to message #510808] Tue, 07 June 2011 23:05 Go to previous messageGo to next message
dkdms2124
Messages: 369
Registered: April 2010
Location: INDIA
Senior Member

Thanks a lot Michel Sir, I was wondering if you can help me for that by looking into the situation which I had explained in the very first post.

It will be great help from your side.

Regards
Deepak
Re: Replace multiple value in single column. [message #510820 is a reply to message #510817] Tue, 07 June 2011 23:13 Go to previous messageGo to next message
Michel Cadot
Messages: 68770
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Your approach is correct. Use keywords in the place you want variable parts of the message and replace the keywords by the given value.
Depending on how you want to do it (custom program, script, SQL*Plus...) the best way to do it (SQL or PL/SQL function or other) will change.

Regards
Michel
Re: Replace multiple value in single column. [message #510839 is a reply to message #510820] Wed, 08 June 2011 01:02 Go to previous message
dkdms2124
Messages: 369
Registered: April 2010
Location: INDIA
Senior Member

Thanks alot for help Sir, its working now.

Regards
Deepak
Previous Topic: Procedure coding help
Next Topic: ORA-08007error
Goto Forum:
  


Current Time: Fri Sep 26 15:02:06 CDT 2025