I'm doing some calculation using (+ operations), but i saw that i have some null result, i checked the data base, and i found myself doing something like number+number+nul+number+null+number...=null
. and this a problem for me.
there is any suggestion for my problem? how to solve this king for problems ? thanks
Whenever you perform arithmetic across SQL columns, take care to handle NULL values appropriately.
Oracle Inserts NULL When Empty String is Inserted to a NUMBER Column. Oracle allows you to use a string literal containing a numeric value to insert data into a NUMBER column without explicit data type casting. But if you attempt to insert an empty string ('') to a NUMBER column, Oracle inserts NULL.
NULL in SQL represents a column field in the table with no value. NULL is different from zero value and from "none". NULL can be inserted in any column by using the assignment operator "=".
Answer. You get an error.
My preference is to use ANSI standard constructs:
select coalesce(n1, 0) + coalesce(n2, 0) + coalesce(n3, 0) + . . .
NVL()
is specific to Oracle. COALESCE()
is ANSI standard and available in almost all databases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With