?
Solved

Oracle Linked server date format issue from sql server 2008

Posted on 2010-09-24
8
Medium Priority
?
892 Views
Last Modified: 2013-12-18
I am trying to get date from oracle using linked server but the date format it is getting is like this

0009-01-10   for 2009-01-10.  does any one seens this issue before,
0
Comment
Question by:hp746
  • 4
  • 4
8 Comments
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 2000 total points
ID: 33755959
The format of the string that Oracle returns for a date is controlled by settings which you can change.

To change at the session level, you can use:

ALTER SESSION SET NLS_DATE_FORMAT='MM/DD/YYYY';

or any other variant of a date format (this is just an example).

It can also be changed at the database level by changing the same parameter.

There is also a registry setting that you can set to change the default format.

All of these will set defaults.  They can always be overridden at the query level with a TO_CHAR(<date_field>, 'MM/DD/YYYY'), again, any valid format is usable here.
0
 

Author Comment

by:hp746
ID: 33756079
Hi John,

This data i am pulling from SQL server 2008 using oracle linked server . here is the query.

SELECT DISTINCT date_effective FROM test_link..test_schema.test_m_view

its returning dates as  0009-11-21 00:00:00.0000000.  what could be the issue here.

Thanks
0
 
LVL 35

Expert Comment

by:johnsone
ID: 33756300
There is no issue.  What format do you want the date in?
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!

 

Author Comment

by:hp746
ID: 33757352
For 2009  its showing 0009  and for 2010  its showing 0010.
0
 
LVL 35

Expert Comment

by:johnsone
ID: 33757687
Then your data is incorrect.  0009 and 0010 are valid years in an Oracle database.  If you insert a 2 digit year into a date field with a 4 digit year as a date mask, you will get that.

If you connect directly to the Oracle database using SQL*Plus, what do you see as a year for those records?  My guess is you will see 0009 and 0010.

I believe that if you change the date format to use RRRR rather than YYYY it should correct that.
0
 

Author Comment

by:hp746
ID: 33758287

Date is oracle is of this format  30-SEP-09 checked thru SQL plus.

I tried to convert using RRRR  as well but it is still returning year as 0009  and 0010.

This issue i am getting in staging server but in dev its returning 2009 and 2010 for year for same table structure and using same query.

Not sure whats going wrong here.  any help will be appreaciated.
0
 
LVL 35

Accepted Solution

by:
johnsone earned 2000 total points
ID: 33765451
When you are checking the date in SQL*Plus, you are only looking at the 2 digit year.  You need to check the 4 digit year.  Use TO_CHAR(<date_field>, 'DD-MON-YYYY HH24:MI:SS').  That will show you the whole date.  This should confirm what the full 4 digit year is on the Oracle side.

RRRR was a long shot, I wasn't sure that would work.  I don't have an Oracle database that I can try this on right now, but this conversion may work.

TO_DATE(TO_CHAR(<date_field>, 'MM/DD/YY HH24:MI:SS'), 'MM/DD/RR HH24:MI:SS')

What this should do is convert it to a string as a 2 digit year an then convert it back to a date using the RR format.  That should fix the year for you.  If that does not work, you are going to have to go through string manipulations to fix the dates.
0
 

Author Closing Comment

by:hp746
ID: 33833176
we have inhouse solution
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

864 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