mysql 多個欄位拼接,mysql欄位拼接

來源:互聯網
上載者:User

mysql 多個欄位拼接,mysql欄位拼接

Mysql的查詢結果列欄位拼接,可以用下面兩個函數實現:

1. concat函數

mysql> select concat('1','2','3') from test ;+---------------------+| concat('1','2','3') |+---------------------+| 123 |+---------------------+
如果串連串中存在NULL,則返回結果為NULL:
mysql> select concat('1','2',NULL,'3') from test ;+--------------------------+| concat('1','2',NULL,'3') |+--------------------------+| NULL |+--------------------------+

2. concat_ws函數

concat(separator,str1,str2,...) 代表 concat with separator ,是concat()的特殊形式。第一個參數是其它參數的分隔字元。分隔字元的位置放在要串連的兩個字串之間。分隔字元可以是一個字串,也可以是其它參數。

mysql> select concat_ws(':','1','2','3') from test ;+----------------------------+| concat_ws(':','1','2','3') |+----------------------------+| 1:2:3 |+----------------------------+
分隔字元為NULL,則返回結果為NULL:

mysql> select concat_ws(NULL,'1','2','3') from test; +-----------------------------+| concat_ws(NULL,'1','2','3') |+-----------------------------+| NULL | +-----------------------------+


如果參數中存在NULL,則會被忽略:

mysql> select concat_ws(':','1','2',NULL,NULL,NULL,'3') from test ;+-------------------------------------------+| concat_ws(':','1','2',NULL,NULL,NULL,'3') |+-------------------------------------------+| 1:2:3 |+-------------------------------------------+

可以對NULL進行判斷,並用其它值進行替換:

mysql>  select concat_ws(':','1','2',ifNULL(NULL,'0'),'3') from bank limit 1;  +---------------------------------------------+| concat_ws(':','1','2',ifNULL(NULL,'0'),'3') |+---------------------------------------------+| 1:2:0:3                                     | +---------------------------------------------+





mysql 怎給一個表一次增加多個欄位?

應該這樣增加

ALTER TABLE MYTABLE ADD FIELD1 VARCHAR(10),ADD FIELD2 INT,ADD FIELD3 VARCHAR(1)
 
mysql中更新多個欄位的值怎做

update 表名 set name=?,password=?.... where id=?
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.