Solved

not null query returning null value

Posted on 2015-01-28
7
144 Views
Last Modified: 2015-01-29
hi i have the folloing query but returning null value even if there is no value related to other table

SELECT * FROM CAL_OBJ
          WHERE TRIM(OBJ_NAME) NOT IN(SELECT TRIM(OBJ_NAME) FROM cal_book);this query return null
        
 
          select * from cal_book
          where obj_name = 'LHLODS06.FMB';this query return null
          
           select * from cal_obj
          where obj_name = 'LHLODS06.FMB';  this query return value

Open in new window

THE second query suppose to be the one to return value not the last query, is there another way to write the first query
0
Comment
Question by:chalie001
7 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 40576803
In case of the second query, what do you mean it returns NULL? You query whole records. If there is no cal_book with the obj_name 'LHLODS06.FMB', you get no records, an empty result set, but not NULL.

If you get an empty result set a NOT IN subquery can't check a value against a set of other values and therefore this also results in an empty result set.

You should rather use NOT EXISTS.

Bye, Olaf.
0
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 40576823
Does your obj_name column in cal_obj has null values  ?

check with this :

select * from cal_obj
          where obj_name is null ?
0
 

Author Comment

by:chalie001
ID: 40576903
i whated to say it return blank no value at all
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 40576912
do you mean that query returned 0 records ? do not confuse with words blank, no value, null etc
0
 
LVL 28

Accepted Solution

by:
Naveen Kumar earned 500 total points
ID: 40576921
you should use this query to get all form names which exist in the cal_obj table but not in the cal_book table.

  select * from cal_obj a
          where not exists ( select 1 from cal_book b where a.obj_name = b.obj_name );

Test it out.

Thanks,
0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 40578068
"I wanted to say it return blank no value at all"  That is not the same as returning a null.

Try this example:

create table test_tab
(item_code    varchar2(3),
 price        number(6,2),
 date_shipped date);
 
insert into test_tab
values ('ABC',15, trunc(sysdate - 1));

insert into test_tab
values ('DEF',25, trunc(sysdate));
 
insert into test_tab
values ('GHI',30, null);

commit;

If you run either of these queries:
select * from  test_tab;
or
select * from  test_tab where item_code = 'GHI';

You *WILL* get  a null value returned for column: "date_shipped" in the record for 'GHI'.

If you run this query:
select * from  test_tab where item_code = 'XYZ';

You will get no rows returned.  That is different from "returning a null".
0
 

Author Closing Comment

by:chalie001
ID: 40578140
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 91
Oracle Syntax 8 54
Get FileTypes from a list of FileNames  in a Table field 18 43
Query Records that don't match 8 32
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database

929 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

10 Experts available now in Live!

Get 1:1 Help Now