標籤:blog http io for ar 資料 2014 代碼 log
1、首先要在Oracle資料庫中建對應的表,Oracle資料庫中的欄位類型和Sql Server 有所不同,Oracle中常用的有varchar2、integer、nchar、date,Sql Server 的欄位類型相對多一些,uniqueidentifier類型的長度是36。
2、開啟管理工具——資料來源(ODBC),配置SqlServer的資料來源。
3、開啟Oracle資料庫——工具——ODBC匯入
4、選擇伺服器,輸入資料庫帳號和密碼
5、選擇使用者和表,然後點擊左下角的匯入按鈕即可
6、附上由SqlServer表自動產生Oracle的代碼:
/********1.定義變數*********/ DECLARE @table_id int, @table_name varchar(100), @column_id int, @c_name sysname, @c_type varchar(50), @max_length smallint, @precision tinyint, @scale tinyint, @is_nullable bit, @cons_sql varchar(5000)
/********2.變數初始化*********/ set @table_name=‘mio_log‘ set @cons_sql=‘create table ‘[email protected]_name+‘(‘
/********3.取表的id*********/ DECLARE tbl_cursor CURSOR FOR select a.id from sys.sysobjects a where a.id = object_id(N‘[dbo].[‘[email protected]_name+‘]‘) and OBJECTPROPERTY(id, N‘IsUserTable‘) = 1
OPEN tbl_cursor FETCH NEXT FROM tbl_cursor INTO @table_id
/********4.構建表的結構*********/ DECLARE columns_cursor CURSOR FOR SELECT b.column_id,b.name,c.name,b.max_length, b.precision,b.scale,b.is_nullable from sys.columns b,sys.systypes c where [email protected]_id and b.system_type_id=c.xtype order by b.column_id asc
OPEN columns_cursor
FETCH NEXT FROM columns_cursor INTO @column_id, @c_name, @c_type, @max_length, @precision, @scale, @is_nullable
WHILE @@FETCH_STATUS = 0 BEGIN set @[email protected][email protected]_name+‘ ‘+ (case when @c_type in(‘smallint‘,‘tinyint‘) then ‘int‘ when @c_type=‘int‘ then ‘number‘ when @c_type =‘varchar‘ then ‘varchar2(‘+convert(varchar(2),@max_length)+‘)‘ when @c_type in(‘datetime‘,‘smalldatetime‘) then ‘date‘ when @c_type=‘decimal‘ then ‘number‘+‘(‘+convert(varchar(1),@precision)+‘,‘+convert(varchar(1),@scale)+‘)‘ when @c_type=‘char‘ then ‘char(‘+convert(varchar(2),@max_length)+‘)‘ when @c_type=‘text‘ then ‘long‘ --此處有待於進一步資料類型的映射 else ‘##‘ end)+ (case when @is_nullable=1 then ‘ null‘ else ‘ not null‘ end)+‘,‘ FETCH NEXT FROM columns_cursor INTO @column_id, @c_name, @c_type, @max_length, @precision, @scale, @is_nullable END
/********5.輸出建表語句*********/ select left(@cons_sql,Len(@cons_sql)-1)+‘);‘
/********6.釋放遊標*********/ DEALLOCATE tbl_cursor DEALLOCATE columns_cursor
利用ODBC從SQLServer向Oracle中導資料