Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
MySQL Replace 
 

MySQL Replace function finds and replaces the occurrences of specified string with the other string.

 

MySQL Replace

                         

MySQL Replace function finds and replaces the occurrences of specified string with the other string.

 

 

 

 

 

Syntax:

REPLACE( String_Text, String_FROM, String_TO);

where String_Text is the original string where replacement is to be performed and returned as a result, String_FROM is the string which is to be replaced and String_To is the string which would be replaced to the occurrences of String_FROM.

For example: In the query given below,  "Roseindia.net" is the original string and all occurrences of "i" string will be replaced by the string "I". The query gives output as RoseIndIa.net.

Query  :   SELECT REPLACE('Roseindia.net','i','I');
Output :   RoseIndIa.net

We can also apply this Replace function on the tables data while inserting or updating table's data. We are explaining you this with one more example. Create a table "mca" in MySQL and fill some data.

Query   CREATE TABLE `mca` (
`id` bigint(11) NOT NULL auto_increment,
`name` varchar(255) default NULL,
`subject` varchar(255) default NULL,
PRIMARY KEY (`id`)
);

/*Data for the table `mca` */

insert into `mca`(`id`,`name`,`subject`) values (1,'Amit','computer'),(2,'Ramesh','computer'),(3,'Suman','computer'),
(4,'Vineet','Java'),(5,'Sandeep','c++');
 

Output

 

When we execute the following update query on the table "mca". The REPLACE() function will replace every occurrence of "c" in the subject column to "C".

Query  UPDATE `mca` SET `subject` = REPLACE(`subject`,"c","C");
 

Output

 

 

                         

» View all related tutorials
Related Tags: sql mysql c sed type column exec state name set exe define if execute statement to modify proc e alter

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.