
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How do I search and replace specific chars at the beginning of a string in MySQL?
For this, you can use INSERT(). Let us first create a table −
mysql> create table DemoTable -> ( -> ZipCode varchar(200) -> ); Query OK, 0 rows affected (0.47 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('9030'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('3902'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('9083'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('9089'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+---------+ | ZipCode | +---------+ | 9030 | | 3902 | | 9083 | | 9089 | +---------+ 4 rows in set (0.00 sec)
Following is the query to search and replace chars at the beginning of a string. Here, we are working only on the records with ZipCode beginning from 90 −
mysql> update DemoTable set ZipCode=INSERT(ZipCode, 1, 2, 'Country-AUS-') -> where ZipCode LIKE '90%'; Query OK, 3 rows affected (0.26 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check table records once again −
mysql> select *from DemoTable;
Output
+----------------+ | ZipCode | +----------------+ | Country-AUS-30 | | 3902 | | Country-AUS-83 | | Country-AUS-89 | +----------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to search a MySQL table for a specific string?
- How do I exclude a specific record in MySQL?
- How to search and replace texts in a string in Golang?
- How do I replace a character at a particular index in JavaScript?
- Search for specific characters within a string with MySQL?
- How do I search for names starting with A in MySQL?
- How do I replace “+”(plus sign) with SPACE in MySQL?
- MySQL search and replace record from a list of records
- Get beginning and end date from a specific year in MySQL
- MySQL REGEXP to fetch string + number records beginning with specific numbers?
- How do I insert elements at a specific index in Java list?
- How can we replace specific part of String and StringBuffer in Java?
- How do I begin auto increment from a specific point in MySQL?
- How do I search a list in Java?
- How do I get the average string length in MySQL?

Advertisements