Solved

null value

Posted on 2016-11-04
15
70 Views
Last Modified: 2016-12-05
hi i have this sqql select empno,hire_date from employee where hire_date is null am geting 0 rows bust when i do select * from employee i can see empty value in hire_date column
hire_date date datatype
0
Comment
Question by:chalie001
  • 3
  • 3
  • 2
  • +3
15 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 41873568
select empno, nvl(hire_date,'01-jan-2005') hiredate_with_nvl. hiredate from employee;

Can you provide the output of this in excel or screenshot ?
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 41873570
you are seeing that issue in sql*plus or toad or any other app/tool ?
0
 
LVL 18

Expert Comment

by:Pawan Kumar Khowal
ID: 41873571
Try 1

--

select empno,hire_date from employee where hire_date is null OR hire_date = ''

--

Open in new window



Try 2

--

select empno,hire_date from employee where LENGTH(hire_date) = 0

--

Open in new window


Try 3

--

select empno,hire_date from employee where hire_date = ''

--

Open in new window

0
 
LVL 37

Accepted Solution

by:
Geert Gruwez earned 250 total points
ID: 41873590
use dump(column) to see what's really in it


with employee as 
   (select 1 empno, cast('  ' as varchar2(50)) hire_date from dual
    union all select 2 empno, to_char(sysdate) hire_date from dual)
 select empno,hire_date, dump(hire_date) from employee

Open in new window

0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41873714
@Geert
What do 2 lines "from dual"  achieve?

with employee as 
   (select 1 empno, cast('  ' as varchar2(50)) hire_date from dual
    union all 
    select 2 empno, to_char(sysdate) hire_date from dual
   )
select empno,hire_date, dump(hire_date) from employee

===============================================================
 	EMPNO	HIRE_DATE	DUMP(HIRE_DATE)
 	1			Typ=1 Len=2: 32,32
 	2	04.11.16	Typ=1 Len=8: 48,52,46,49,49,46,49,54
===============================================================

Open in new window

0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41873758
Paul,
 Really ?

You have never been on a database where there is no employee table ?
you have never had to conjure up some sample rows to explain something using "from dual" ?

And you got to level 47 how exactly ?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:chalie001
ID: 41873795
i use is null
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41873796
sorry... It was a serious question
I just don't follow the logic as you haven't unioned the table employee at all, you just have 2 rows from dual

did you intend to union to the table?

forgive me I was attempting to help
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 250 total points
ID: 41873850
Just a comment on using empty strings.  Oracle does not support empty strings, it equates them to NULL.

So, this:

hire_date = ''

will always return false.  It is impossible for anything to ever equal null.

Try them out:

select * from dual where '' = '';
select * from dual where null = '';
select * from dual where null = null;
select * from dual where '' is null;

Only the last query will return a result.  All others will return no rows.
0
 
LVL 18

Expert Comment

by:Pawan Kumar Khowal
ID: 41873857
This is working for me .. :)

with employee as 
   (select 1 empno, cast(' ' as varchar2(50)) hire_date from dual
    union all select 2 empno, to_char(sysdate) hire_date from dual)
    
select empno,hire_date
from employee
WHERE hire_date = ' '

Open in new window


Output...
----------------------------------

      EMPNO      HIRE_DATE
1      1
0
 
LVL 34

Expert Comment

by:johnsone
ID: 41873864
That has a space in it, it is not an empty string.  What was posted earlier is:

hire_date = ''

No space, so it is an empty string.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 41874038
Paul,
i can't union the employee table, as i don't have a database here with an employee table
i don't have access to chalie001's database, i think
> you never one when a new user with a certain alias is asking question on a site and actually sitting next to you

chalie001,
how come paul get's point by using my sample, but i don't ?
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41874152
Geert, thanks. i understand now. I  didnt befote.

chalie001
I am not comfortable having points for asking a question
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Export BLOB data from Oracle 10g 4 25
Data center mess 4 49
SQL anywhere 11 databases 1 38
Best RAID for a BDD Oracle 4 27
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Creating and Managing Databases with phpMyAdmin in cPanel.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now