This is a read-only copy of the MariaDB Knowledgebase generated on 2024-05-02. For the latest, interactive version please visit https://mariadb.com/kb/.

Operador de Divisão (/)

Sintaxe

/

Descrição

Operador de divisão. Divisões por zero retornarão NULL. Por default, são retornado 4(quatro) dígitos após a casa decimal. Isto é determinado pela variável de sistema do servidor server-system-variables#div_precision_increment a qual, por default, é 4(quatro). Esta pode ser definida de 0 a 30.

Divisões por zero retornam NULL. Se é definido ERROR_ON_DIVISION_BY_ZERO SQL_MODE (por default é assim a partir da versão 10.2.4 do MariaDB), uma divisão por zero também produz um warning.

Exemplos

SELECT 4/5;
+--------+
| 4/5    |
+--------+
| 0.8000 |
+--------+

SELECT 300/(2-2);
+-----------+
| 300/(2-2) |
+-----------+
|      NULL |
+-----------+

SELECT 300/7;
+---------+
| 300/7   |
+---------+
| 42.8571 |
+---------+

Mudando a variável de sistema div_precision_increment para a sessão atual do default para 6(seis):

SET div_precision_increment = 6;

SELECT 300/7;
+-----------+
| 300/7     |
+-----------+
| 42.857143 |
+-----------+

SELECT 300/7;
+-----------+
| 300/7     |
+-----------+
| 42.857143 |
+-----------+

Veja também

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.