Tutorialspoint

1 Answer
Sharon Christine

Use INSERT() function from MySQL. It has the following parameters −

ParameterDescription
strString to be modified
positionPosition where to insert str2
numberNumber of characters to replace
str2String to insert into str

Let us first create a table −

mysql> create table DemoTable
   -> (
   -> Code varchar(100)
   -> );
Query OK, 0 rows affected (0.82 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('958575/98') ;
Query OK, 1 row affected (0.16 sec)

mysql> insert into DemoTable values('765432/99');
Query OK, 1 row affected (0.19 sec)

mysql> insert into DemoTable values('983456/91');
Query OK, 1 row affected (0.15 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-----------+
| Code      |
+-----------+
| 958575/98 |
| 765432/99 |
| 983456/91 |
+-----------+
3 rows in set (0.00 sec)

Here is the query to search on a varchar column using a number −

mysql> select *from DemoTable where Code =INSERT(76543299,7,0,'/');

This will produce the following output −

+-----------+
| Code      |
+-----------+
| 765432/99 |
+-----------+
1 row in set (0.00 sec)

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.