How to insert character in select query values

This is my sample query request:

SELECT item from tbl

And here is the result:

1001
2001

Is there a function in MySQL that allows me to insert characters into a value in my select query? Like this:

1-001
2-002
+4
source share
5 answers

Using the INSERT () function . Your code should look something like this:

SELECT INSERT(item, ,2, 0, '-') item from tbl
+2
source
SELECT CONCAT_WS('-', LEFT(item, 1), SUBSTRING(item, 2)) FROM tbl
+3
source

Try the following: -

SELECT CONCAT_WS('-', LEFT(item, 1), SUBSTRING(item, 2)) FROM tbl

SQL DEMO

+1
source

Try this one

SELECT  
CONCAT(LEFT( `item ` , 1) ,'-' ,`item`)
FROM `tbl`

or

SELECT  
CONCAT(LEFT( `item ` , 1) ,'-' ,SUBSTRING(`item`,2)
FROM `tbl`
0
source

The syntax will be:

INSERT (ori_string, in_pos, length, new_string)
-3
source

All Articles