Migrate table from Oracle to SQL Server - sql

Migrate a table from Oracle to SQL Server.
I have used Toad to export (select * from table) into a pipe delimited .txt file so it can be used to be consumed in SQL Server. Now the Oracle table has a DATE column and the output from Toad for that column is (2/26/2016 3.05.10.000000 PM). This format is not being compatible for the datetime column in SQL Server side.
I feel we can convert the date in Oracle to a compatible SQL Server format for easier ingestion.
Please help me understand the conversion both from Oracle to a compatible SQL Server format.

Create Oracle Linked server in SQL Server with ODBC connection. and use that Linked server to play with Oracle and SQL Server tables using SQL Server.

You must understand that DATE datatypes are binary data. Using to_date() on a column that is already a DATE is inappropriate. It forces oracle to perform (behind the scenes) a to_char() on the DATE column in order to produce character data that is the required input to to_date(). Then, when you see (in your text csv file) that it has produced a "date" in some particular format, it is because oracle has then had to run the result of your to_date() back through to_char(), using the default NLS_DATE_FORMAT setting to produce a character string for the text output.
So your solution is this:
First, determine what text format of a date MSSQL wants when it uses this csv file. I don't know what that is, but for the sake of argument, let's say it is 'yyyy-mm-dd'. With that information, construct your SELECT in oracle like this:
select mycol1,
to_char(my_date_col,'yyyy-mm-dd'),
mycol2
from my_table;
That said, I agree with the others, why bother with this cumbersome process in the first place? Or even some other intermediary like SSIS? Why not just create a shared server in MSSQL and query the oracle table directly? Or create a database link in the Oracle DB and, using the oracle transparent gateway as the conduit, INSERT directly into the MSSQL table from Oracle? Either the linked server or the database link will be much faster than any external process.

I would suggest a best way to transfer Oracle table to SQL Serveris by using SSIS package.
You can have a Source as Oracle and your conversion issue can be fixed by Data
Conversion task and your Destination can be SQL Server.

Related

ORA-02070: database %s%s does not support %s in this context

I have an Oracle database from which I am selecting a table from a remote postgres database, pg. The column mydate is of type date.
select to_char(mydate,'mm-dd-yyyy') from "pg_table"#pg
For the above query, I am getting an error like
ORA-02070: database PG does not support TO_CHAR in this context
*Cause: The remote database does not support the named capability in the context in which it is used.
*Action: Simplify the SQL statement.
Why is this happening?
Try to use to_date to first make it an oracle date then use to_char to transform
select to_char(to_date(mydate),'mm-dd-yyyy' ) as "Date"
from "pg_table"#pg
Some functions are not supported by the linked server driver to the backend server. I'm having this happen right now where regex_replace is not supported by links to MSSQL. This is just an unfortunate byproduct of using a linked server.

Select multiple columns as JSON in a single query [duplicate]

I am using SQL Server 2008 and want to convert table data into json format. Can I convert it directly through firing query?
I have created a stored procedure that can take your table and output JSON. You can find it at
GitHub - SQLTableOrViewToJSON
Once you run the stored procedure, you can output your table by making a call like the following:
EXEC SQLTableOrViewToJSON 'MyTable', 'C:\WhereIStowMyJSON\'
Built in support for formatting query results is added in SQL Server 2016 and it will be available in Azure Database.
In older versions you would need to use CLR or some heavy TSQL like:
Producing JSON Documents from SQL Server queries via TSQL
The above solutions seem unnecessarily complicated; starting with 2008, SQL Server supports the following syntax (answer from DBA StackExchange)
SELECT * FROM dbo.x FOR JSON AUTO;
The above query returns a single JSON-formatted column that looks like this (assuming dbo.x contains columns col1~col4of corresponding types):
[{"col1":"val1","col2":"val2","col3":5,"col4":"2019-02-11"}]
More details/options here: https://learn.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server

How to convert data to json format in SQL Server 2008?

I am using SQL Server 2008 and want to convert table data into json format. Can I convert it directly through firing query?
I have created a stored procedure that can take your table and output JSON. You can find it at
GitHub - SQLTableOrViewToJSON
Once you run the stored procedure, you can output your table by making a call like the following:
EXEC SQLTableOrViewToJSON 'MyTable', 'C:\WhereIStowMyJSON\'
Built in support for formatting query results is added in SQL Server 2016 and it will be available in Azure Database.
In older versions you would need to use CLR or some heavy TSQL like:
Producing JSON Documents from SQL Server queries via TSQL
The above solutions seem unnecessarily complicated; starting with 2008, SQL Server supports the following syntax (answer from DBA StackExchange)
SELECT * FROM dbo.x FOR JSON AUTO;
The above query returns a single JSON-formatted column that looks like this (assuming dbo.x contains columns col1~col4of corresponding types):
[{"col1":"val1","col2":"val2","col3":5,"col4":"2019-02-11"}]
More details/options here: https://learn.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server

Modify the dataset format in SAS on a `sql-base` server

Usually I would use proc datasets lib= ; modify to change the format/informats of the columns in a datasets. But when I apply this syntax to a dataset on a sql-based server.
The error shows
ERROR: The HEADER/VARIABLE UPDATE function is not supported by the ODBC engine.
I found some articles that may explain the problem. Here's one. http://support.sas.com/kb/37/015.html
Moreover, whatever dataset I created in the network, the format/informat/length is changed to its 'default' setting. E.g date9. -> datetime 22.3.
But still I don't understand why it happens. Is there something pre-defined in the network and the architecture of the server is not 100% compatible with SAS?
When you modify format, You alter table.
Suppose you have some diferent database (SQL) servers. Example Oracle, MS SQL, MY SQL. All of them have their own dialect on altering table.
When You write modify column; ... you are altering table. But SAS does not which dialect to try. That is why alter table procedure is not supported from datasets procedure.
You can update that table using database server dialect, but it needs to be added from proc sql procedure. Like it was writen in that article
execute( alter table table-name ...specific-Oracle-syntax...)by oracle;
data9. I think You mean date9.. Well it is SAS format. Other database servers, can have or can have not this format. By default they will create database default formats.

How to insert LONG BINARY from SQL Server to Oracle

I need to get a copy of a SQL Server 2008 table into an Oracle RDBMS. I have database link for SQL Server, database has a table which contains LONG BINARY type column.
When I issue
create table test_ora as select * from mssqltable#dblink
I get the error
Can't convert LONG
I tried to use to_lob, to_char, hextoraw and a ream of Oracle conversion function but still hasn't defeated the issue. Do you have any ideas?
p.s. I'm out of work now so can't tell exact ORA- error number.
There is a way to do that with undocumented Oracle's package:
http://tonguc.wordpress.com/2008/08/28/how-to-transfer-long-datatype-over-dblink/
I would recommend tool called Pentaho Data Integration. This is free, small and superb ETL tool.
Download page: community(.)pentaho(.)com
It will recreated all tables and types for you. How to do it:
pldwh(.)blogspot(.)co(.)uk/2013/03/pentaho-data-integration-create-tables_1(.)html