Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 openquery changing datatype

Author  Topic 

lappin
Posting Yak Master

182 Posts

Posted - 2013-08-13 : 07:28:11
I have a procedure which imports from Oracle tables using Openquery to do a Select Into tables in SQL Server. The SQL is dynamic-SQL where the table name is passed in and ran on a loop. The code fired for a particular table is:

SELECT * INTO myTempTable1
FROM OPENQUERY(myLink,'select * from table1)

The temp table is then used to update final table in SQL Server.
Then the temp table is deleted.

The problem is that a varchar2(30) column in Oracle is converted to nvarchar(30) in SQL Server. This is causing some data to be truncated.

Any suggestions?

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-08-13 : 07:55:17
Refer this link http://docs.oracle.com/cd/E10405_01/doc/appdev.120/e10379/ss_oracle_compared.htm#i1026309
what type of data do you have in the varchar2(30) column ? i.e. BYTE or CHAR ?
As per my knowledge, Oracle's VARCAHR2(30) can be mapped to SYSNAME/VARCAHR(30) in SQL Server.

--
Chandu
Go to Top of Page

lappin
Posting Yak Master

182 Posts

Posted - 2013-08-13 : 10:36:26
Yes varchar2(30) needs to be mapped to varchar(30), but it is not happening automatically. Since this is a SELECT * INTO I am not specifying the column types, just relying on SQL Server to correctly chose the matching type. This is my problem: how to get SQL Server to realise that varchar2(30) should map to varchar(30) not nvarchar(30).

I found this:
https://forums.oracle.com/thread/1957428

But not sure how to proceed.
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-08-13 : 13:14:38
If you insert data from a VARCHAR(30) column (or its Oracle equivalent, assuming it is equivalent) into an NVARCHAR(30) column, the data should not get truncated. If the data is getting trucated, the source of the problem may be somewhere else.

Do couple of experiements:

1. Remove the "INTO myTempTable1" part, do you see all the data coming through correctly?

2. For testing purposes, create the destination table and then use INSERT INTO myTempTable1 SELECT * FROM...

Do you get the correct data in either case?
Go to Top of Page
   

- Advertisement -