Use INSERT() function from MySQL. It has the following parameters −
Parameter | Description |
---|---|
str | String to be modified |
position | Position where to insert str2 |
number | Number of characters to replace |
str2 | String 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;
Output
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,'/');
Output
This will produce the following output −
+-----------+ | Code | +-----------+ | 765432/99 | +-----------+ 1 row in set (0.00 sec)