|
A volte, può essere necessario combinare insieme, ovvero concatenare, i risultati restituiti da più campi diversi. Per realizzare questa operazione, ciascun database fornisce una modalità distinta:
- MySQL: CONCAT( )
- Oracle: CONCAT( ), ||
- SQL Server: +
La sintassi per CONCAT( ) è la seguente:
CONCAT(str1, str2, str3, ...): concatenare str1, str2, str3 e qualsiasi altra stringa insieme. Si noti che la funzione CONCAT( ) di Oracle consente solo due argomenti; mediante questa funzione è possibile mettere insieme solo due stringhe per volta. In Oracle, è comunque possibile concatenare più di due stringhe alla volta utilizzando '||'.
Si vedano i seguenti esempi. Si supponga di avere la seguente tabella:
Tabella Geography
| region_name |
store_name |
| East |
Boston |
| East |
New York |
| West |
Los Angeles |
| West |
San Diego |
Esempio 1:
MySQL/Oracle:
SELECT CONCAT(region_name,store_name) FROM Geography
WHERE store_name = 'Boston';
Risultato :
'EastBoston'
Esempio 2:
Oracle:
SELECT region_name || ' ' || store_name FROM Geography
WHERE store_name = 'Boston';
Risultato :
'East Boston'
Esempio 3:
SQL Server:
SELECT region_name + ' ' + store_name FROM Geography
WHERE store_name = 'Boston';
Risultato :
'East Boston'
SQL SUBSTRING >>
Copyright © 2013 1keydata.com Tutti i diritti riservati.
|