Solved

Oracle

Posted on 2011-02-24
6
752 Views
Last Modified: 2012-05-11
I can run rings around anyone in SQL, but it's been a while since I've used Oracle with SQL Plus

I've tried everything I could think of or find on line, so you're going to have to come up with something really good to solve this.

I know some of the paid_dates are null

I want the paid_date of any invoice that was paid within 3 days of the approved_date.  Should be simple.  It's not!  I keep getting the error below.  Tried case, nvl, is not null, everything.  I saw an article about it being a known error by Oracle.  Need a solution.  I'm new on the job and want to prove my worth!

select to_date(to_char(paid_date),'RRRR-MM-DD') "PAID DATE"
from Ellipse.MSF260 a
where nvl(paid_date,1900-01-01) between '2010-07-01' and '2011-02-28'
and to_date(to_char(paid_date),'RRRR-MM-DD') between to_date(to_char(approved_date),'RRRR-MM-DD') and to_date(to_char(approved_date),'RRRR-MM-DD') +3

Error:'
ORA-01841: (full) year must be between -4713 and +9999, and not be 0
0
Comment
Question by:glendawi
6 Comments
 
LVL 7

Accepted Solution

by:
MrNed earned 250 total points
ID: 34976240
Are you sure the default date format is YYYY-MM-DD?, try wrapping the two hardcoded dates with a to_date().
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 34976243
First: why go from date to char and back to date?
to_date(to_char(paid_date),'RRRR-MM-DD')

If you don't want the time, just trunc(paid_date)

Now to the error:
nvl(paid_date,1900-01-01) between '2010-07-01' and '2011-02-28'


Never use implicit conversions.
Use to_date('2010-07-01','YYYY-MM-DD')
For any string to date comparisons.

You are also missing quotes on the date in the NVL.
0
 
LVL 7

Expert Comment

by:MrNed
ID: 34976246
And is this a typo? you need quotes:

where nvl(paid_date,1900-01-01)
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 74

Expert Comment

by:sdstuber
ID: 34976531



select paid_date "PAID DATE"
from Ellipse.MSF260 a
where paid_date between date '2010-07-01' and date '2011-02-28'
and approved_date > paid_date
and  approved_date - paid_date < 3
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 34976536
your error is because of your double conversion, one of which is implicit.

Not only is it erroneous, it's also inefficient
0
 

Author Closing Comment

by:glendawi
ID: 34980867
Thanks SO MUCH.
But I also had to add
where paid_date is not null
and paid_date <> ' '
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

697 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