mysql concat函数使用方法

mysql concat函数使用方法

𝓓𝓸𝓷 Lv6

mysql拼接字符串函数

1.concat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
mysql> select concat('drop table `', table_name, '`;') from information_schema.tables where table_schema not in ('mysql','sys') and engine='MyISAM';
+--------------------------------------------+
| concat('drop table `', table_name, '`;') |
+--------------------------------------------+
| drop table `act_de_databasechangeloglock`; |
| drop table `act_de_model`; |
| drop table `act_de_model_history`; |
| drop table `act_de_model_relation`; |
| drop table `act_my_variable`; |
| drop table `cnt_agent`; |
| drop table `cnt_audit_dept`; |
| drop table `cnt_auditdept_config`; |
| drop table `cnt_auditinfo`; |
| drop table `cnt_auditsubdept_config`; |
| drop table `cnt_common_audit`; |
| drop table `cnt_flow_config`; |
| drop table `cnt_partner_attach`; |
| drop table `cnt_workflow`; |
| drop table `girl`; |
| drop table `hibernate_sequence`; |
| drop table `mat_invoice_address`; |
| drop table `mat_repertory`; |
| drop table `mat_repertory_supplier`; |
| drop table `oa_car`; |
| drop table `oa_car_maintain`; |
| drop table `oa_car_use`; |
| drop table `oa_carpply`; |
| drop table `oa_leave`; |
| drop table `oa_meeting_apply`; |
| drop table `oa_meeting_meno`; |
| drop table `oa_meeting_room`; |
| drop table `oa_scheduler`; |
| drop table `oa_topic_reply`; |
| drop table `sys_logger_info`; |
+--------------------------------------------+
30 rows in set (0.01 sec)



---不显示表格及不显示字段名
# mysql -uroot -p --silent -N -D platform-cssd
Enter password:
mysql> select concat('drop table ', table_name, ';') from information_schema.tables where table_schema not in ('mysql','sys') and engine='MyISAM';

drop table act_de_databasechangeloglock;
drop table act_de_model;
drop table act_de_model_history;
drop table act_de_model_relation;
drop table act_my_variable;
drop table cnt_agent;
drop table cnt_audit_dept;
drop table cnt_auditdept_config;
drop table cnt_auditinfo;
drop table cnt_auditsubdept_config;
drop table cnt_common_audit;
drop table cnt_flow_config;
drop table cnt_partner_attach;
drop table cnt_workflow;
drop table girl;
drop table hibernate_sequence;
drop table mat_invoice_address;
drop table mat_repertory;
drop table mat_repertory_supplier;
drop table oa_car;
drop table oa_car_maintain;
drop table oa_car_use;
drop table oa_carpply;
drop table oa_leave;
drop table oa_meeting_apply;
drop table oa_meeting_meno;
drop table oa_meeting_room;
drop table oa_scheduler;
drop table oa_topic_reply;
drop table sys_logger_info;

2.concat_ws

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mysql> select concat_ws(' ', 'Hello', user, '!') as greeting from mysql.user;
+--------------------------+
| greeting |
+--------------------------+
| Hello cloudimage ! |
| Hello imageuser ! |
| Hello nacos ! |
| Hello root ! |
| Hello root ! |
| Hello repl ! |
| Hello backup ! |
| Hello mysql.infoschema ! |
| Hello mysql.session ! |
| Hello mysql.sys ! |
| Hello nacos ! |
| Hello root ! |
+--------------------------+
12 rows in set (0.00 sec)
  • Title: mysql concat函数使用方法
  • Author: 𝓓𝓸𝓷
  • Created at : 2025-02-20 09:20:27
  • Updated at : 2025-02-20 09:59:19
  • Link: https://www.zhangdong.me/mysql-concat.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论