In MariaDB, COS() è una funzione numerica incorporata che restituisce il coseno del suo argomento, dove l'argomento è fornito in radianti.
Sintassi
La sintassi è questa:
COS(X)
Dove X è il numero, fornito in radianti.
Esempio
Ecco un esempio:
SELECT COS(3); Risultato:
+---------------------+ | COS(3) | +---------------------+ | -0.9899924966004454 | +---------------------+
Ecco cosa succede quando forniamo π (pi):
SELECT
PI(),
COS(PI()); Risultato:
+----------+-----------+ | PI() | COS(PI()) | +----------+-----------+ | 3.141593 | -1 | +----------+-----------+
Argomenti non numerici
Ecco un esempio di cosa succede quando forniamo un argomento non numerico:
SELECT COS('Cat'); Risultato:
+------------+
| COS('Cat') |
+------------+
| 1 |
+------------+
1 row in set, 1 warning (0.010 sec) Controlliamo l'avviso:
SHOW WARNINGS; Risultato:
+---------+------+-----------------------------------------+ | Level | Code | Message | +---------+------+-----------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Cat' | +---------+------+-----------------------------------------+
Argomenti nulli
COS() restituisce null se l'argomento è null :
SELECT COS(null); Risultato:
+-----------+ | COS(null) | +-----------+ | NULL | +-----------+
Argomenti mancanti
Chiamando COS() con il numero errato di argomenti o senza argomenti genera un errore:
SELECT COS(); Risultato:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'COS'
E:
SELECT COS(10, 2); Risultato:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'COS'