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-04-26MySQL查出时间比实际晚8小时的解决方案
- 2024-04-01JPA不识别MySQL的枚举类型
- 2024-03-30mysql数据库表卡死解决方法
- 2024-03-15MySQL多数据源笔记5-ShardingJDBC实战
- 2024-03-11natural join mysql
- 2024-03-11关于VS2017,VS2015 中利用 EF使用Mysql 不显示数据源问题解决方案
- 2024-02-26mysql 阿里云xb后缀备份文件恢复-icode9专业技术文章分享
- 2024-02-22docker mysql 5.7
- 2024-02-18从 20 多套 MySQL 到 1 套 TiDB丨骏伯网络综合运营管理平台应用实践
- 2024-02-07mysql 外键索引入门介绍,为什么工作中很少有人使用?