473,383 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Setting Null values to Zero

Hi

I have a situtation where a query returns a table in which some of the
values are null. When I sort the results, the null values are treated
as greater than the other numerical results. Is it possible to set the
database treat the null values as zero?

Thanks
Jul 19 '05 #1
2 18010

"C. Lo" <st********@hotmail.com> wrote in message
news:71**************************@posting.google.c om...
| Hi
|
| I have a situtation where a query returns a table in which some of the
| values are null. When I sort the results, the null values are treated
| as greater than the other numerical results. Is it possible to set the
| database treat the null values as zero?
|
| Thanks

no, and you wouldn't want a database-wide (or even a session-wide) setting,
since NULL is a much different value from 0

what you need to use though is either the NULLS FIRST keywords on the order
by (NULLS LAST is the default), or, if you really want the nulls converted
to 0's in the results, use the nvl() function

SQL> select ename, sal, comm
2 from emp
3 order by comm nulls first, sal;
....

ENAME SAL COMM
---------- ---------- ----------
SMITH -1
Adams 1100
MILLER 1300
CLARK 2450
JONES 2975
FORD 3000
SCOTT 4000
KING 5000
TURNER 1500 0
JAMES 950 22
ALLEN 16 300
WARD 1250 500
MARTIN 1250 1400

SQL> select ename, sal, nvl(comm,0) as commission
2 from emp
3 order by nvl(comm,0), sal;
....

ENAME SAL COMMISSION
---------- ---------- ----------
SMITH -1 0
Adams 1100 0
MILLER 1300 0
TURNER 1500 0
CLARK 2450 0
JONES 2975 0
FORD 3000 0
SCOTT 4000 0
KING 5000 0
JAMES 950 22
ALLEN 16 300
WARD 1250 500
MARTIN 1250 1400

;-{ mcs
Jul 19 '05 #2
try using NVL function...hence replace all null values with zeros and
perform a sort.
"C. Lo" <st********@hotmail.com> wrote in message
news:71**************************@posting.google.c om...
Hi

I have a situtation where a query returns a table in which some of the
values are null. When I sort the results, the null values are treated
as greater than the other numerical results. Is it possible to set the
database treat the null values as zero?

Thanks

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
25
by: pm940 | last post by:
Hello. I've been reading some past discussions on the NULL vs. zero. References are always made to systems or machienes that use values other than zero to represent the NULL pointer. Although...
64
by: yossi.kreinin | last post by:
Hi! There is a system where 0x0 is a valid address, but 0xffffffff isn't. How can null pointers be treated by a compiler (besides the typical "solution" of still using 0x0 for "null")? -...
17
by: Mark A | last post by:
DB2 8.2 for Linux, FP 10 (also performs the same on DB2 8.2 for Windoes, FP 11). Using the SAMPLE database, tables EMP and EMLOYEE. In the followng stored procedure, 2 NULL columns (COMM) are...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: Kangwa | last post by:
Am trying to update a table with values from another table but not all cloums are supposed to be updated so am ending up with null values how do i change these null values to zero so that the empty...
3
ADezii
by: ADezii | last post by:
Null as it relates to database development is one of life's little mysteries and a topic of total confusion for novices who venture out into the database world. A Null Value is not zero (0), a zero...
6
by: DippyDog | last post by:
This is an old old post that I'm referencing regarding what happens when you set an integer variable to Nothing. It gets set to zero, not "Nothing." ...
1
by: C. Lo | last post by:
Hi I have a situtation where a query returns a table in which some of the values are null. When I sort the results, the null values are treated as greater than the other numerical results. Is it...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.