In MariaDB, POW() è una funzione incorporata che restituisce il valore del suo primo argomento elevato alla potenza del suo secondo argomento.
Sintassi
La sintassi è questa:
POW(X,Y)
Restituisce X elevato al potere di Y .
Il POWER() funzione è sinonimo di POW() , quindi può anche essere fatto in questo modo:
POWER(X,Y) Esempio
Ecco un esempio da dimostrare:
SELECT POW(2, 3); Risultato:
+-----------+ | POW(2, 3) | +-----------+ | 8 | +-----------+
Valori negativi
Ecco alcuni esempi che utilizzano valori negativi:
SELECT
POW(-2, 3),
POW(2, -3),
POW(-2, -3); Risultato:
+------------+------------+-------------+ | POW(-2, 3) | POW(2, -3) | POW(-2, -3) | +------------+------------+-------------+ | -8 | 0.125 | -0.125 | +------------+------------+-------------+
Argomenti non numerici
Ecco un esempio di cosa succede quando forniamo argomenti non numerici:
SELECT POW('Homer', 'Symptom'); Risultato:
+-------------------------+
| POW('Homer', 'Symptom') |
+-------------------------+
| 1 |
+-------------------------+
1 row in set, 2 warnings (0.000 sec) Vediamo l'avviso:
SHOW WARNINGS; Risultato:
+---------+------+---------------------------------------------+ | Level | Code | Message | +---------+------+---------------------------------------------+ | Warning | 1292 | Truncated incorrect DOUBLE value: 'Homer' | | Warning | 1292 | Truncated incorrect DOUBLE value: 'Symptom' | +---------+------+---------------------------------------------+
Argomenti nulli
POW() restituisce null se un argomento è null :
SELECT
POW(2, null),
POW(null, 3),
POW(null, null); Risultato:
+--------------+--------------+-----------------+ | POW(2, null) | POW(null, 3) | POW(null, null) | +--------------+--------------+-----------------+ | NULL | NULL | NULL | +--------------+--------------+-----------------+
Argomenti mancanti
Chiamando POW() con il numero errato di argomenti o senza argomenti genera un errore:
SELECT POW(); Risultato:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'POW'
E:
SELECT POW(10, 2, 3); Risultato:
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'POW'