La funzione CHAR

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

Syntassi

CHAR(N,... [USING set_di_caratteri])

Spiegazione

CHAR() interpreta ogni argomento N come intero, e restituisce una stringa che consiste di due caratteri ottenuti dal codice di quegli interi. I valori NULL vengono ignorati. Per default, CHAR() restituisce una stringa binaria. Per produrre una stringa di un dato set di caratteri, si può utilizzare la clausola opzionale USING:

MariaDB [(none)]> SELECT CHARSET(CHAR(0x65)), CHARSET(CHAR(0x65 USING utf8));
+---------------------+--------------------------------+
| CHARSET(CHAR(0x65)) | CHARSET(CHAR(0x65 USING utf8)) |
+---------------------+--------------------------------+
| binary              | utf8                           |
+---------------------+--------------------------------+
1 row in set (0.00 sec)

Se USING è specificato e la stringa risultato è illegale per il set di caratteri specificato, si ottiene un warning. Inoltre, se l'SQL mode strict è abilitato, il risultato di CHAR() diventa NULL.

Esempi

MariaDB [(none)]> SELECT CHAR(77,97,114,'105',97,'68',66);
+----------------------------------+
| CHAR(77,97,114,'105',97,'68',66) |
+----------------------------------+
| MariaDB                          |
+----------------------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> SELECT CHAR(77,77.3,'77.3');
+----------------------+
| CHAR(77,77.3,'77.3') |
+----------------------+
| MMM                  |
+----------------------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect INTEGER value: '77.3'

Vedi anche

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.