Question

How do I search for null date fields using Oracle 11g and TOAD 9.7.2.5?

Asked by: kev1970

Using Oracle 11g and TOAD 9.7.2.5, I'm executing:
select *
from TestTable
where TestDate is null

but it's not giving me any results even though TestDate field has thousands of null entries.
I discovered the problem when TOAD failed to run "Copy data to another schema" because of a null column violation.
This problem appeared following my adding a date column with a not null constraint which Oracle 11 allowed me to do even though there were thousands of null (TestDate) entries.
I have worked around the copy problem by disabling the not null constraint in the destination table but why is my statement not returning any rows in the source schema?
After the copy, I ran the same statement (see above) in the destination schema and it brought back the results correctly however, as expected, it is not allowing me to enable the not null constraint.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-08 at 10:06:33ID24035866
Tags

Oracle 11

,

TOAD 9

,

date

,

null

Topic

Oracle 11.x Database

Participating Experts
3
Points
500
Comments
28

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Oracle and Toad
    Hi, I am using Toad 7.6.0.11 Standard Addition for the first time and I want to create 2 new tablespaces but I can't see how to do this; there doesn't appear to be any menu option that I can see that allows you to create a 'tablespace'... Can you help...? Thanks Ian
  2. toad
    I am having a strange problem with toad. It used to be fine until today ; It will let me type words and stuff but will not let me use the backspace or any arrow keys( up, down etc) or page up or page down. All that I can do is to type and if I typed something wrong ; so have...
  3. checking locking in oracle with toad
    In TOAD for Oracle, How do I view for process locking and user session? as I was well know with sql server sp_who2 will list me the process but how to view it in Oracle?
  4. schema compare in toad for oracle
    Hi experts, I did a compare schema in TOAD 9 between a production and a uat environment, for which a import of the prd data for that schema has been done and the result of that schema comparison gives me body differences for functions, procedures, views and for triggers it g...
  5. TOAD_EXPORT
    I have two questions on TOAD: 1. can TOAD be used to create a script of a schema in 9i so i can take script and create in 10g express. 2. Can i use TOAD to export data from a table directly to Excel or create the Excel spreadsheet. thanks,

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sdstuberPosted on 2009-01-08 at 10:08:50ID: 23327878

are you sure the data has null and not simply "blank" data in it?

 

by: sdstuberPosted on 2009-01-08 at 10:09:44ID: 23327898

oops, clicked submit too soon.  I mean maybe one column has blank data and onther is null and maybe it's a different contraint that is failing?

 

by: sujith80Posted on 2009-01-08 at 18:57:04ID: 23332488

What is the data type of column TestDate?

 

by: kev1970Posted on 2009-01-09 at 02:29:25ID: 23334214

I've cloned the database by executing the schema generated by the TOAD "Generate Schema Script".
TestDate is a DATE type.

 

by: sonicefuPosted on 2009-01-09 at 08:18:20ID: 23337018

You should recheck the data type of the field, it seems that the data type is string (char, varchar2 etc.).

 

by: kev1970Posted on 2009-01-13 at 01:33:43ID: 23361057

I've cloned the database by executing the schema generated by the TOAD "Generate Schema Script".
In other words, TestDate is a DATE type in both databases.

 

by: sdstuberPosted on 2009-01-15 at 15:43:19ID: 23389174

also recheck the constraint,  maybe it was a different column that was showing up as null

 

by: kev1970Posted on 2009-01-22 at 13:10:25ID: 23443686

Let me explain.
I generated a schema script (S1) in TOAD and then executed the script in a blank schema (S2). On the second try, it executed with no errors:
S2 is a clone of S1.

 

by: kev1970Posted on 2009-01-22 at 13:16:51ID: 23443748

I then copied all of the data by using "Copy data to another schema".

The issue is that there is null data in that field in both of the schemas, because they both have the same schema and data, but the query only works in the cloned (S2) table.

 

by: sdstuberPosted on 2009-01-22 at 14:43:08ID: 23444509

try this on both source and destination


select *
from TestTable
where nvl(TestDate,to_date('99991231235959','yyyymmddhh24miss')) = to_date('99991231235959','yyyymmddhh24miss')


if you happen to have data with that date then pick another one so the nvl will only match your null data

 

by: kev1970Posted on 2009-01-23 at 04:20:34ID: 23448259

No rows were returned from the source.
Thousands of rows were returned, correctly, from the destination.

I'm perplexed as I can see no data in that column and the below statement also produces the above results:
select *
from TestTable
where trunc(TestDate) is null

How else can you see no data in a DATE type column and it not be null?

 

by: sdstuberPosted on 2009-01-23 at 06:21:35ID: 23449074

you'll need to file a ticket on metalink with oracle support.  
clearly your source system is screwed up.

one last thought,  do you have any rewrite options turned on?  either query rewrite via materialized
views or advanced rewrite that may be running something instead of the SQL you expect?

assuming you don't then I suggest you submit the results of all of the above queries and the following ones to exhaustively show the source sytem's NULL's don't show up.
I wouldn't include anything from the destination system, since it's behaving properly it's not really part of the problem.

select *
from TestTable
minus
select *
from TestTable
where TestDate is not NULL

select count(*) from TestTable;

select count(*) from TestTable where TestDate is not NULL;

select count(*) from TestTable where TestDate is NULL;

 

by: sdstuberPosted on 2009-01-23 at 06:23:40ID: 23449090

another thought.  Is the not null constraint enabled but not validated?

The results should still come back correctly, but that may help indicate the problem if oracle is trying to "optimize" your results by returning nothing for NULLs because it can see a contraint even one that isn't validated.

 

by: kev1970Posted on 2009-01-30 at 00:15:54ID: 23506104

select *
from TestTable
minus
select *
from TestTable
where TestDate is not NULL------------------- 0 rows

select count(*) from TestTable;------------------- 24077

select count(*) from TestTable where TestDate is not NULL;------------------- 24077

select count(*) from TestTable where TestDate is NULL;------------------- 0

According to TOAD 9.6.1.1's schema browser, the constraint is Enabled and Validated.

 

by: sdstuberPosted on 2009-01-30 at 05:10:36ID: 23507776

how do you know TestTable has thousands of null entries? do you see them in the source system?
or are you only detecting them in the target?

if the latter...
is there any possibility at all that your data copy didn't actually copy everything?  thereby creating null data in the target system?

 

by: kev1970Posted on 2009-02-06 at 00:16:37ID: 23567737

Ok, I'll put it another way.
This is a DATE column which has a NOT NULL constraint that is Enabled and Validated.
When viewing that table in the schema browser, there are rows in which there is no data in that column.
How can this be?

 

by: kev1970Posted on 2009-02-06 at 01:14:11ID: 23567985

More to the point, how did I manage to put a NOT NULL constraint on a column with thousands of NULL entries?

 

by: sdstuberPosted on 2009-02-06 at 06:00:52ID: 23569714

you'll have to contact Oracle support for that.

you can put a contraint on it, but it shouldn't have validated.

Can you post all of the DDL for the table and the constraints?
Are you sure the constraint is validated?
Are you sure the data has NULL's?

All of the results you've posted above indicate a system with a constraint that has no bad data.

If that's not the case, you MUST contact Oracle with a "Wrong Results" bug

 

by: kev1970Posted on 2009-02-18 at 08:54:22ID: 23672197

Interestingly I ran the following SQL:
    select to_char(TestDate , 'dd Mon yyyy')
    from TestTable
    where id = 20000
and it came back with '00 000 0000'
I then ran:
    select count(*)
    from TestTable
    where to_char(TestDate , 'dd Mon yyyy') = '00 000 0000'
and it comes back with a count of all of the rows.

What is date '00 000 0000'? How did I produce it? How would I reproduce it?
Will the following SQL fix it without breaking anything:
    update TestTable
    set TestDate = null
    where to_char(TestDate , 'dd Mon yyyy') = '00 000 0000'

 

by: kev1970Posted on 2009-02-19 at 03:21:41ID: 23680030

I tried to run:
    update TestTable
    set TestDate = null
    where to_char(TestDate , 'dd Mon yyyy') = '00 000 0000'

and it, quite rightly, will not let me violate the null constraint but why does "Copy data to another schema" try to copy null and not the date: '00 000 0000'?
Is this an Oracle or TOAD problem?

 

by: kev1970Posted on 2009-04-02 at 22:17:27ID: 24056842

HELP!!
Can anybody tell me how it is possible to have a date field with date '00 000 0000'?

 

by: sdstuberPosted on 2009-04-03 at 08:20:03ID: 24060891

it's actually pretty easy to do...

if you do data math (including timezone conversion via NEW_TIME) that would adjust the time to before Jan 1, 0001  then you can get invalid dates.

 

by: sdstuberPosted on 2009-04-03 at 08:21:16ID: 24060903


insert into testtable
SELECT
        TO_DATE('1/1/1 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
                        - n / 24                      
  FROM (SELECT ROWNUM  n
          FROM user_objects
         WHERE ROWNUM < 20);

select to_char(testdate,'yyyy-mm-dd hh24:mi:ss BC') from testtable;

 

by: sdstuberPosted on 2009-04-03 at 08:22:14ID: 24060919

assuming your testtable has just one column (testdate)

the above should create 19 rows of invalid dates and then show them to you like...


TO_CHAR(TESTDATE,'YYYY
----------------------
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00
0000-00-00 00:00:00 00

19 rows selected.

 

by: sdstuberPosted on 2009-04-03 at 08:26:43ID: 24060974

Here's a cute trick...

this shows Oracle actuall maintains the entirety of year 0 (which doesn't really exist)
and, is apparently a leap-year as far as Oracle is concerned since there are 366 days (8784 hours) of invalid dates

but, even though their is a "secret" year, you can't really use it because every point in time within it is 0000-00-00 00:00:00


SELECT n,
       TO_CHAR(NEW_TIME(  TO_DATE('1/1/1 00:00:00', 'yyyy/mm/dd hh24:mi:ss')
                        + n / 24,
                        'GMT',
                        'EST'
                       ),
               'yyyy-mm-dd hh24:mi:ss BC'
              )
  FROM (SELECT level - 8800  n
          FROM dual
          connect by level < 8820 )

 

by: sdstuberPosted on 2009-04-03 at 08:28:23ID: 24060992

my guess is the problem occured because of a y2k bug somewhere in your code, or maybe an adhoc query ran some time in the past

Somebody probably had a string of the form '00' or '01' and did some date manipulations on it which were then turned into secret-year-0 dates rather than year 2000

 

by: sdstuberPosted on 2009-04-03 at 08:47:26ID: 24061249

small clarification to my earlier post where I said year 0 didn't exist
actually year 0 does exist on astronomical calendars.

Oracle has a confused (arguably broken) calendar, because it does calculations as if it were an astronomical calendar (where there is a year 0) but it only supports dates in a AD/BC form (where there is not a year 0)

 

by: kev1970Posted on 2009-04-14 at 06:38:59ID: 31532434

Sean, I was on holiday so sorry for the delay.
I still have no idea how I created the data but your solution is fascinating!
Thanks.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...