mysql字符串拼接
2022/9/14 2:17:03
本文主要是介绍mysql字符串拼接,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Mysql数据库中的字符串
CONCAT()
CONCAT_WS()
GROUP_CONCAT()
CONCAT()
CONCAT(string1,string2)
最常用的字符串拼接方法,但遇到拼接中的字符串出现null的情况会返回null
root@((none))11:33:50>select CONCAT(TABLE_SCHEMA,TABLE_NAME) from information_schema.TABLES limit 3;
+---------------------------------------------------------+
| CONCAT(TABLE_SCHEMA,TABLE_NAME) |
+---------------------------------------------------------+
| information_schemaCHARACTER_SETS |
| information_schemaCOLLATIONS |
| information_schemaCOLLATION_CHARACTER_SET_APPLICABILITY |
+---------------------------------------------------------+
3 rows in set (0.01 sec)
CONCAT_WS()
CONCAT_WS(separator,str1,str2,…)
多了分隔符功能
root@((none))11:33:53>select CONCAT_WS(".",TABLE_SCHEMA,TABLE_NAME) from information_schema.TABLES limit 3;
+----------------------------------------------------------+
| CONCAT_WS(".",TABLE_SCHEMA,TABLE_NAME) |
+----------------------------------------------------------+
| information_schema.CHARACTER_SETS |
| information_schema.COLLATIONS |
| information_schema.COLLATION_CHARACTER_SET_APPLICABILITY |
+----------------------------------------------------------+
3 rows in set (0.00 sec)
GROUP_CONCAT()
group_concat( [DISTINCT] 连接的字段 [Order BY 排序字段 ASC/DESC] [Separator ‘分隔符’] )
连接字段,多个值显示为一行.连接的可以是多个字段,也可以对连接字段进行排序
root@((none))11:44:27>select GROUP_CONCAT(TABLE_SCHEMA,TABLE_NAME) from information_schema.TABLES limit 3 \G;
*************************** 1. row ***************************
GROUP_CONCAT(TABLE_SCHEMA,TABLE_NAME): information_schemaCHARACTER_SETS,information_schemaCOLLATIONS,information_schemaCOLLATION_CHARACTER_SET_APPLICABILITY,information_schemaCOLUMNS,information_schemaCOLUMN_PRIVILEGES,information_schemaENGINES,information_schemaEVENTS,information_schemaFILES,information_schemaGLOBAL_STATUS,information_schemaGLOBAL_VARIABLES,information_schemaKEY_COLUMN_USAGE,information_schemaOPTIMIZER_TRACE,information_schemaPARAMETERS,information_schemaPARTITIONS,information_schemaPLUGINS,information_schemaPROCESSLIST,information_schemaPROFILING,information_schemaREFERENTIAL_CONSTRAINTS,information_schemaROUTINES,information_schemaSCHEMATA,information_schemaSCHEMA_PRIVILEGES,information_schemaSESSION_STATUS,information_schemaSESSION_VARIABLES,information_schemaRDS_INDEX_HINTS_INFO,information_schemaSTATISTICS,information_schemaTABLES,information_schemaTABLESPACES,information_schemaTABLE_CONSTRAINTS,information_schemaTABLE_PRIVILEGES,information_schemaTRIGGERS,information_schemaUSER_PRIVILEGES,information_schemaVIEWS,information
这篇关于mysql字符串拼接的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-25如何部署MySQL集群资料:新手入门教程
- 2024-12-24MySQL集群部署资料:新手入门教程
- 2024-12-24MySQL集群资料详解:新手入门教程
- 2024-12-24MySQL集群部署入门教程
- 2024-12-24部署MySQL集群学习:新手入门教程
- 2024-12-24部署MySQL集群入门:一步一步搭建指南
- 2024-12-07MySQL读写分离入门:轻松掌握数据库读写分离技术
- 2024-12-07MySQL读写分离入门教程
- 2024-12-07MySQL分库分表入门详解
- 2024-12-07MySQL分库分表入门指南