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

Detailed analysis and testing of SSD performance issues in MySQL servers

【question】 We have an HP server. When the SSD wri...

Install Mininet from source code on Ubuntu 16.04

Mininet Mininet is a lightweight software defined...

Security considerations for Windows server management

Web Server 1. The web server turns off unnecessar...

Mini Program to Implement Simple List Function

This article example shares the specific code of ...

How to turn local variables into global variables in JavaScript

First we need to know the self-calling of the fun...

Differences between MySQL CHAR and VARCHAR when storing and reading

Introduction Do you really know the difference be...

How to change mysql password under Centos

1. Modify MySQL login settings: # vim /etc/my.cnf...

Common structural tags in XHTML

structure body, head, html, title text abbr, acro...

How to use Vue3 to achieve a magnifying glass effect example

Table of contents Preface 1. The significance of ...

vite2.x implements on-demand loading of ant-design-vue@next components

1. Use version vite:2.0 ant-design-vue: 2.0.0-rc....

Tips for writing concise React components

Table of contents Avoid using the spread operator...

Tomcat common exceptions and solution code examples

The company project was developed in Java and the...

JS implements dragging the progress bar to change the transparency of elements

What I want to share today is to use native JS to...

Detailed explanation of MySQL InnoDB secondary index sorting example

Sorting Problem I recently read "45 Lectures...