473,618 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 18053

"C. Lo" <st********@hot mail.com> wrote in message
news:71******** *************** ***@posting.goo gle.com...
| 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...henc e replace all null values with zeros and
perform a sort.
"C. Lo" <st********@hot mail.com> wrote in message
news:71******** *************** ***@posting.goo gle.com...
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
5961
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" ( i am talking of unix machine ) while trying to read that location. Then how can i distinguish between a NULL pointer and an invalid location ? Is this essential that NULL pointer should not point to any of the location in the virtual address...
25
4400
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 not a practice I follow, there are no doubt millions of lines of open source libraries and applications that do things like: p = malloc(...);
64
3894
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")? - AFAIK C allows "null pointers" to be represented differently then "all bits 0". Is this correct? - AFAIK I can't `#define NULL 0x10000' since `void* p=0;' should work just like `void* p=NULL'. Is this correct?
17
4515
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 selected into 2 different SP variables and compared for equal. They are both NULL, but do not compare as equal. When the Not NULL columns (SALARY) are compared, they do compare as equal.
1
6472
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" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
3
2865
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 cloum will have zero
3
12278
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 (0) length string, an empty Field, or no value at all - so exactly what is Null? The purpose of this Topic is hopefully to explain what a Null Value is, discuss some peculiarities about Nulls, show how we can detect them, and finally, how to convert...
6
3557
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." http://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_thread/thread/6732ea8e7016bd24/70608745c29d048b?lnk=gst&q=can%27t+set+enum+to+nothing#70608745c29d048b Just to expand the understanding of the problems this behavior can cause, because a typical enumeration (enum) is...
1
335
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 possible to set the database treat the null values as zero? Thanks
0
8212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8595
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8304
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7126
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5552
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4065
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2587
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.