SQL CONCAT 字串連線函式

2021-09-19 16:06:38 字數 1298 閱讀 6514

有的時候,我們有需要將由不同字段獲得的資料串連在一起。每一種資料庫都有提供方法來達到這個目的:

concat() 的語法如下:

concat(字串1, 字串2, 字串3, ...): 將字串1、字串2、字串3,等字串連在一起。

請注意,oracle的concat()只允許兩個引數;

換言之,一次只能將兩個字串串連起來。不過,在oracle中,我們可以用'||'來一次串連多個字串。

來看幾個例子。假設我們有以下的**:

geography **

region_name

store_name

east

boston

east

new york

west

los angeles

west

san diego

例子1:

mysql/oracle:

select concat(region_name,store_name) from geography

where store_name = 'boston';

結果:'eastboston'

除此之外 你可以自定義新增組合

例子:mysql/oracle:

select concat(store_name,'哈哈') from geography

where store_name = 'boston';

結果:'boston哈哈'

例子2:

oracle:

select region_name || ' ' || store_name from geography

where store_name = 'boston';

結果:'east boston'

例子3:

sql server:

select region_name + ' ' + store_name from geography

where store_name = 'boston';

結果:'east boston'

**:

SQL CONCAT 字串連線函式

有的時候,我們有需要將由不同字段獲得的資料串連在一起。每一種資料庫都有提供方法來達到這個目的 mysql concat oracle concat sql server concat 的語法如下 concat 字串1,字串2,字串3,將字串1 字串2 字串3,等字串連在一起。請注意,oracle的c...

SQL CONCAT 字串連線函式

有的時候,我們有需要將由不同字段獲得的資料串連在一起。每一種資料庫都有提供方法來達到這個目的 concat 的語法如下 concat 字串1,字串2,字串3,將字串1 字串2 字串3,等字串連在一起。請注意,oracle的concat 只允許兩個引數 換言之,一次只能將兩個字串串連起來。不過,在or...

SQL CONCAT 字串連線函式

有的時候,我們有需要將由不同字段獲得的資料串連在一起。每一種資料庫都有提供方法來達到這個目的 concat 的語法如下 concat 字串1,字串2,字串3,將字串1 字串2 字串3,等字串連在一起。請注意,oracle的concat 只允許兩個引數 換言之,一次只能將兩個字串串連起來。不過,在or...