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

What are the advantages of MySQL MGR?

MGR (MySQL Group Replication) is a new feature ad...

WeChat applet realizes the function of uploading pictures

This article example shares the specific code for...

Detailed explanation of the principle of Vue monitoring data

Table of contents 1. Introduction II. Monitoring ...

MySQL View Principle Analysis

Table of contents Updatable Views Performance of ...

Docker installation and configuration steps for MySQL

Table of contents Preface environment Install Cre...

MySQL Server 8.0.3 Installation and Configuration Methods Graphic Tutorial

This document records the installation and config...

A detailed introduction to the use of block comments in HTML

Common comments in HTML: <!--XXXXXXXX-->, wh...

Web componentd component internal event callback and pain point analysis

Table of contents Written in front What exactly i...

Briefly understand the two common methods of creating files in Linux terminal

We all know that we can use the mkdir command to ...

When to use table and when to use CSS (experience sharing)

The main text page of TW used to have a width of 8...

iframe src assignment problem (server side)

I encountered this problem today. I reassigned the...

Detailed explanation of the definition and function of delimiter in MySQL

When you first learn MySQL, you may not understan...

Detailed analysis of the blocking problem of js and css

Table of contents DOMContentLoaded and load What ...

Detailed explanation of three solutions to the website footer sinking effect

Background Many website designs generally consist...