使用Oracle SQL Developer查询两个数据库

10

有没有办法在Oracle SQL Developer中查询两个数据库(在一次查询中)?

除了标准的CRUD语法外,我对Oracle不是很熟悉。

我正在尝试从SQL Server表中插入数据到Oracle表。希望能够像这样做:

INSERT INTO OracleDB.table (field1, 2, ...)
SELECT ... FROM SQLServerDB.schema.table

我在Oracle SQL Developer中创建了两个数据库的(正常工作的)连接。

谢谢

--编辑--

我没有数据库本身的管理员权限。(无法创建链接服务器等)。


所以这是从 SQL Server 读取并插入到 Oracle 吗? - Sathyajith Bhat
是的(从SQL-Server读取并插入到Oracle) - Chains
2个回答

10
是的,这是可能的。在SQL Developer中建立连接是无法帮助您的 - 您需要从Oracle数据库设置数据库链接到SQL Server数据库。
在创建数据库链接之前,您需要设置一个异构网关来连接到SQL Server。
一般步骤包括:
  • Install Oracle ODBC drivers on the server that will access the remote SQL Server database using the database link.

  • Setup the ODBC connection on the local Oracle database using the Windows ODBC Data Source Administrator

  • Test the ODBC drivers to ensure that connectivity is made to the SQL Server database.

  • Configure the Oracle Heterogeneous services by creating an initodbc.ora file within the Oracle database.

  • Modify the Listener.ora file.

        SID_NAME is the DSN for the remote database.
        ORACLE_HOME is the actual Oracle home file path.
        PROGRAM tells Oracle to use heterogeneous services.
    
        SID_LIST_LISTENER =
        (SID_LIST =
        (SID_DESC =
        (SID_NAME=ora_sid) -- Enter the DSN on this line
        (ORACLE_HOME = c:\oracle10gdb) -- Enter your Oracle home on this line
        (PROGRAM = hsodbc) ) )
    
  • Modify the Tnsnames.ora file to point to the gateway

        (DESCRIPTION=
        (ADDRESS_LIST=
        (Address=(PROTOCOL=TCP)
        (HOST=
        -- (Server x)
        (PORT=1521))) -- Enter the port on which the server x Oracle installation
        -- is listening
        (CONNECT_DATA=(SID=Cas30c)) - Enter the DSN name
        (HS=OK) -- Enter this value. It tells Oracle to use hetergeneous services
        )
    
  • Reload the listener on local Oracle database

  • Create a database link on the local Oracle installation that accesses the heterogeneous connection, which, in turn, connect to SQL Server.

创建数据库链接后,您应该能够使用简单的方式将数据插入到数据库中:
 insert into <oracle_tablename>
 select * from <sqlserver_table_name>@dblink_name

进一步阅读:


2
您可以使用异构服务从ODBC连接读取数据。但是,设置起来有些麻烦。您需要编辑Oracle安装中的多个文件以设置新的TNS侦听器,然后在您的模式/全局中创建一个dlink。 此指南适用于Unix,但在我看来是最简短/最不愚蠢的指南。
另一种选择是通过第三方程序传输数据。例如,我认为您可以在MS Access中创建查询,然后将数据导出到Oracle或SQL Server。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接