In MariaDB, COLLATION() è una funzione incorporata secondaria che restituisce le regole di confronto di una determinata stringa.
Forniamo la stringa quando chiamiamo la funzione.
Sintassi
La sintassi è questa:
COLLATION(str)
Dove str è la stringa.
Esempio
Ecco un semplice esempio:
SELECT COLLATION('Maria'); Risultato:
+--------------------+
| COLLATION('Maria') |
+--------------------+
| utf8_general_ci |
+--------------------+ Ed ecco un altro esempio che utilizza caratteri tailandesi:
SELECT COLLATION(_tis620'ไม้เมือง'); Risultato:
+----------------------------------------------+ | COLLATION(_tis620'ไม้เมือง') | +----------------------------------------------+ | tis620_thai_ci | +----------------------------------------------+
Tipo di argomento errato
Passando un argomento che non è una stringa si ottiene la parola binary in fase di restituzione.
SELECT COLLATION(123); Risultato:
+----------------+ | COLLATION(123) | +----------------+ | binary | +----------------+
Argomenti nulli
Passaggio null risulta nella parola binary in fase di restituzione.
SELECT COLLATION(null); Risultato:
+-----------------+ | COLLATION(null) | +-----------------+ | binary | +-----------------+
Argomento mancante
Chiamando COLLATION() senza passare un argomento si ottiene un errore:
SELECT COLLATION(); Risultato:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1