Instance method for mysql string concatenation and setting null value

Instance method for mysql string concatenation and setting null value

#String concatenation concat(s1,s2); concatenate the strings in last_name and first_name in the table

select concat(last_name,first_name) as name from employees;

#Only last_name will be modified, not first_name

SELECT first_name,last_name AS f FROM employees;

# Separate the two columns with a comma and name them out_put

SELECT CONCAT(`last_name`,',',`phone_number`) AS out_put FROM employees;

#ifnull determines whether it is empty. If it is empty, it will be displayed as 0 instead of null, and the column name will be displayed as the result

SELECT IFNULL(commission_pct,0) AS result FROM employees;

Content extension:

String concatenation

1.1 The CONCAT(s1, s2, ...) function returns the string generated by concatenating the parameters, one or more contents to be concatenated. If any one of them is NULL, the return value is NULL.

SELECT CONCAT('Current time:',NOW()); -- Output result: Current time: 2019-01-17 11:27:58


1.2 CONCAT_WS(x,s1,s2,...) function

Returns a string consisting of multiple strings concatenated together, with an x ​​between each string.

SELECT CONCAT_WS(';','pan_junbiao's blog','KevinPan','pan_junbiao'); -- Output: pan_junbiao's blog;KevinPan;pan_junbiao

I hope the above content can help everyone. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Tutorial on understanding and using NULL values ​​in MySQL
  • Detailed explanation of NULL values ​​in MySQL
  • Mysql implements null value first/last method example
  • Distinguish between null value and empty character ('''') in MySQL
  • MySQL NULL value processing example detailed explanation
  • Do you know the difference between empty value and null value in mysql
  • This article takes you to explore NULL in MySQL

<<:  Vue component encapsulates sample code for uploading pictures and videos

>>:  How to build a K8S cluster and install docker under Hyper-V

Recommend

MySQL constraint types and examples

constraint Constraints ensure data integrity and ...

A detailed introduction to the basics of Linux scripting

Table of contents 1. Script vim environment 2. Ho...

Summary of flex layout compatibility issues

1. W3C versions of flex 2009 version Flag: displa...

Detailed explanation of Javascript basics loop

Table of contents cycle for for-in for-of while d...

Install MySQL 5.7.17 in win10 system

Operating system win10 MySQL is the 64-bit zip de...

What to do after installing Ubuntu 20.04 (beginner's guide)

Ubuntu 20.04 has been released, bringing many new...

Mysql transaction isolation level principle example analysis

introduction You must have encountered this in an...

Vue implements a simple marquee effect

This article shares the specific code of Vue to a...

Detailed explanation of mysql backup and recovery

Preface: The previous articles introduced the usa...

Rounding operation of datetime field in MySQL

Table of contents Preface 1. Background 2. Simula...

uniapp project optimization methods and suggestions

Table of contents 1. Encapsulate complex page dat...

Vue implements a shopping cart that can change the shopping quantity

This article shares with you how to use Vue to ch...

Vue+thinkphp5.1+axios to realize file upload

This article shares with you how to use thinkphp5...