Insert into Oracle 10g from MS SQL Server with pass through openquery - sql-server

I am attempting to insert data across a DB link from an MS SQL Server 2008 into and Oracle 11g server using a pass through insert:
insert into openquery(ORACLE,'select varchar2_1,varchar2_2, number1 from table1')
select varchar_1, varchar_2, integer_1 from mssql_table;
When I try and execute this I get and error saying that the data violates the schema.
Error:
The OLE DB provider "MSDAORA" for linked server "ORACLE" could not INSERT INTO table "[MSDAORA]" because of column "VARCHAR2_1". The data value violated the schema for the column.
I searched around google and stackoverflow but could not seem to find a specific solution to this problem.
fyi: I cannot change the schema in the oracle DB.
Any help would be greatly appreciated.

Check the lengths of the data in varchar_2. Can the data fit into the oracle column varchar2_1?

Related

SSIS, query Oracle table using ID's from SQL Server?

Here's the basic idea of what I want to do in SSIS:
I have a large query against a production Oracle database, and I need the following where clause that brings in a long list of ids from SQL Server. From there, the results are sent elsewhere.
select ...
from Oracle_table(s) --multi-join
where id in ([select distinct id from SQL_SERVER_table])
Alternatively, I could write the query this way:
select ...
from Oracle_table(s) --multi-join
...
join SQL_SERVER_table sst on sst.ID = Oracle_table.ID
Here are my limitations:
The Oracle query is large and cannot be run without the where id in (... clause
This means I cannot run the Oracle query, then join it against the ids in another step. I tried this, and the DBA's killed the temp table after it became 3 TB in size.
I have 160k id's
This means it is not practical to iterate through the id's one by one. In the past, I have run against ~1000 IDs, using a comma-separated list. It runs relatively fast - a few minutes.
The main query is in Oracle, but the ids are in SQL Server
I do not have the ability to write to Oracle
I've found many questions like this.
None of the answers I have found have a solution to my limitations.
Similar question:
Query a database based on result of query from another database
To prevent loading all rows from the Oracle table. The only way is to apply the filter in the Oracle database engine. I don't think this can be achieved using SSIS since you have more than 160000 ids in the SQL Server table, which cannot be efficiently loaded and passed to the Oracle SQL command:
Using Lookups and Merge Join will require loading all data from the Oracle database
Retrieving data from SQL Server, building a comma-separated string, and passing it to the Oracle SQL command cannot be done with too many IDs (160K).
The same issue using a Script Task.
Creating a Linked Server in SQL Server and Joining both tables will load all data from the Oracle database.
To solve your problem, you should search for a way to create a link to the SQL Server database from the Oracle engine.
Oracle Heterogenous Services
I don't have much experience in Oracle databases. Still, after a small research, I found something in Oracle equivalent to "Linked Servers" in SQL Server called "heterogeneous connectivity".
The query syntax should look like this:
select *
from Oracle_table
where id in (select distinct id from SQL_SERVER_table#sqlserverdsn)
You can refer to the following step-by-step guides to read more on how to connect to SQL Server tables from Oracle:
What is Oracle equivalent for Linked Server and can you join with SQL Server?
Making a Connection from Oracle to SQL Server - 1
Making a Connection from Oracle to SQL Server - 2
Heterogeneous Database connections - Oracle to SQL Server
Importing Data from SQL Server to a staging table in Oracle
Another approach is to use a Data Flow Task that imports IDs from SQL Server to a staging table in Oracle. Then use the staging table in your Oracle query. It would be better to create an index on the staging table. (If you do not have permission to write to the Oracle database, try to get permission to a separate staging database.)
Example of exporting data from SQL Server to Oracle:
Export SQL Server Data to Oracle using SSIS
Minimizing the data load from the Oracle table
If none of the solutions above solves your issue. You can try minimizing the data loaded from the Oracle database as much as possible.
As an example, you can try to get the Minimum and Maximum IDs from the SQL Server table, store both values within two variables. Then, you can use both variables in the SQL Command that loads the data from the Oracle table, like the following:
SELECT * FROM Oracle_Table WHERE ID > #MinID and ID < #MaxID
This will remove a bunch of useless data in your operation. In case your ID column is a string, you can use other measures to filter data, such as the string length, the first character.

Unable to migrate data from sql server to aurora Mysql DB using AWS data migration service

I am unable migrating data from SQL server to aurora MySQL DB using AWS DMS service. Currently, I have a different number of columns for a particular table in MySQL DB due to which I am unable to transfer data from SQL server to aurora MySQL DB.
Please check the below image for reference.
As the picture suggests, I want to transfer data from booking table in SQL server to booking table in aurora Mysql DB having less number of columns.
Can anyone suggest a way to do it?
There may be a way to cope with this directly from AWS without having to change your schema. But, one option here would be to simply create a table in MySQL which matches the column/type count of the counterpart in SQL Server, i.e.
CREATE TABLE booking (bookingID int, bookingVersion int, ...) -- 7 columns
Then, migrate the data from SQL Server to MySQL using the AWS tool. Finally, just drop the bookingVersion column from your MySQL table:
ALTER TABLE booking DROP COLUMN bookingVersion;
This should work, because all the extra DML steps I suggested can completely be done within MySQL, and don't involve your SQL Server database at all.

INSERT to Oracle table from SQL Server database link

I have created a database link to SQL Server 2012 database in Oracle 11gR2 using the Oracle Gateway for SQL Server. The connection is working fine and I am able to run queries and stored procedure from SQL Server.
The problem arises when I try to retrieve an XML column from SQL Server. Oracle documents clearly states that if database is in UTF character set (AL32UTF8), XML is supported, but in LONG datatype format.
I am able to query the XML column by
SET LONG 5000;
select "XMLColumn" FROM "xmltable"#sqlserver;
but while trying to insert this into an oracle table with Long datatype it gives the following error.
SQL Error: ORA-00997: illegal use of LONG datatype
Is there any workaround for this problem.
I even tried to convert the incoming XML to CLOB as suggested by Sanders, which perfectly makes sense. But somehow that too throws back the same error. In below query Name is obviously the XML column from SQL Server.
CREATE TABLE TEMPCLOB
AS
SELECT TO_LOB("Name") AS "Name" FROM "xmldata"#sqlserver;
LONG is deprecated datatype in Oracle. You can spend time to this problem, but I'd advice you to convert it immediately into CLOB or XMLTYPE and have no problem at all.

"IN" keyword sql file path

While moving an app from access to sql server I have come across a keyword that is causing errors. The keyword within the query is "IN". INSERT INTO Table IN 'file path of sql server database'. Does sql server allow you to insert data using the file path within the query? I have been researching this for a few days and have come up with nothing.
Thanks
The IN keyword in Microsoft Access in this syntax allows you to specify another database file where the table is. This is equivalent to being in another database in Sql Server.
It looks like you are taking multiple Access database files and importing them into multiple Sql Server databases. Let's say you have an Access database called One.MDB and it gets some data from a table in Access database Two.MDB, and you have imported into Sql Server into databases One and Two. So you need to get the data from the other database. Sql Server uses a syntax of Database.Schema.Table (the schema by default is the database owner schema, or dbo).
So this in Microsoft Access:
INSERT INTO MyTable IN 'Two.MDB' ...
translates to this in Sql Server:
INSERT INTO Two.dbo.MyTable ...
That's assuming you are still using separate databases. If you've put it all in the same database, you just need to reference the table directly:
INSERT INTO MyTable ...

Sybase to SQLserver linkserver errors

I have set up a SQL link server between an SQLserver 2005 on a W2003 R2 and a SYBASE 12.5.0.2 server on a IBM AIX H70 system.
I use the Sybase ODBC driver 04.20.00.67
The problem is than most of the times (there is no pattern ) when I select rows from a Sybase table I get ONLY ONE ROW without any error. Please note that there is no problem when I insert rows from SQL server to the SYBASE server
I appreciate any possible solutions...
How are you selecting the rows? Is it via
select a,b,c FROM LINKED_SERVERNAME.foo.bar.bletch
or are you doing 'pass-thru' sql like this
EXEC('SELECT * FROM foo..bletch') AT LINKED_SERVERNAME
I have had way more success with the pass-thru style query: SQL Server does not appear to get what it needs metadata-wise from the Sybase ODBC driver. I was forced to write replacements for the sp_tables_ex and friends family of stored procedures as they did not work for me with linked Sybase dataservers.
pjjH

Resources