Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL null plus number give a null value

Tags:

sql

oracle10g

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

like image 633
archavin Avatar asked Jun 07 '13 16:06

archavin


People also ask

WHAT IS NULL plus a number in SQL?

Whenever you perform arithmetic across SQL columns, take care to handle NULL values appropriately.

Can we assign NULL to number in Oracle?

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.

How do you give a value to NULL in SQL?

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 "=".

What happens if you add to NULL?

Answer. You get an error.


1 Answers

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.

like image 93
Gordon Linoff Avatar answered Sep 28 '22 15:09

Gordon Linoff