Tip for Linking to Oracle

October 25, 2009

One of the requirements for a project I’ve been working on is to connect to Oracle and retrieve some data related to data in MS SQL Server. After successfully setting up the Oracle server as a linked server, I ran into trouble.

Oracle’s data types aren’t quite the same as SQL Server’s data types. In particular, the timestamp type on the Oracle side would not translate to anything on the SQL Server side. After extensive research, I was considering switching to a .Net solution instead, like maybe I could query SQL Server and Oracle separately and then combine the data within the app. Surely not very efficient, but what else could I do?

Fortunately, I had lunch with my brother during the project and his Oracle experience is much greater than mine. After discussing the problem with him, I ended up using a view to get around the issue. For my project, I only needed the year out of the timestamp. Using the TO_CHAR function, I created a view that allowed me to select the year from the Oracle data as a char(4). Perfect!