Instance method for splicing mysql strings and setting null values
- 2021-12-12 10:07:08
- OfStack
# String splicing concat (s1, s2); Splice strings in last_name and first_name in the table
select concat(last_name,first_name) as Name from employees;
# Only modifies last_name not first_name
SELECT first_name,last_name AS f FROM employees;
# Separate two columns with commas and name them out_put
SELECT CONCAT(`last_name`,',',`phone_number`) AS out_put FROM employees;
# ifnull determines if it is null, and if it is null, it displays 0 instead of null, and displays the column name as the result
SELECT IFNULL(commission_pct,0) AS Results FROM employees;
Content extension:
Splicing of strings
1.1 CONCAT (s1, s2,...) Functions
Returns the string generated by the join parameter, one or more contents to be spliced, and if any one is NULL, the return value is NULL.
SELECT CONCAT(' Now time: ',NOW()); -- Output: Now time: 2019-01-17 11:27:58
1.2 CONCAT_WS (x, s1, s2,...) Functions
Returns a string after multiple strings are spliced, with 1 x between each string.
SELECT CONCAT_WS(';','pan_junbiao Blog of ','KevinPan','pan_junbiao'); -- Output: pan_junbiao Blog of ;KevinPan;pan_junbiao