Solved

Oracle Linked server date format issue from sql server 2008

Posted on 2010-09-24
8
779 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
[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
  • 4
  • 4
8 Comments
 
LVL 35

Assisted Solution

by:johnsone
johnsone earned 500 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
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!

 

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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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 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.

729 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