Mysql Division by ZERO, SQL_MODE = 'TRADITIONAL'?

2

I am having SQL_MODE of MySQL as in version is 5.7.18 and according to documentation this mode would make MySQL function equally the other banks such as SQL Server .

But when I do:

select 651/0;

instead of accusing the error of division by zero (% with%) it gives the result as null.

Does anyone know how to solve it?

Documentation:

TRADITIONAL

  

Make MySQL behave like a "traditional" SQL database system. A simple description of this mode is "give an error instead of a warning" when inserting an incorrect value into a column. It is one of the special combination modes listed at the end of this section.

     

Note   The INSERT or UPDATE aborts as soon as the error is noticed. This may not be what you want if you are using a nontransactional storage engine, because data changes made prior to the error may not be rolled back, resulting in a "partially done" update.

    
asked by anonymous 28.04.2017 / 22:04

1 answer

0

To handle the NULL return of this division, just use the MySQL IFNULL () function.

EX: select 651/0; would be select IFNULL(651/0, 0);

So if the result of the first parameter is NULL it will be replaced by the contents of the second parameter.

    
22.05.2017 / 19:05