Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle

Posted on 2011-02-24
6
Medium Priority
?
755 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 7

Accepted Solution

by:
MrNed earned 1000 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 1000 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
Industry Leaders: 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!

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

609 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