简体   繁体   English

一次查询中的Odbc和Sql连接

[英]Odbc & Sql connection in one query

I wanna select some records from the informix database via Odbc connection and insert them to a Sql database table. 我想通过Odbc连接从notifyix数据库中选择一些记录,并将它们插入到Sql数据库表中。

INSERT INTO SAS.dbo.disconnectiontemp 
        (meterno) 
SELECT DISTINCT met_number                 
FROM   Bills.dbadmin.MeterData 

I've searched regrading that, but they didn't solve my issue. 我已经搜索过了,但他们没有解决我的问题。 Is it possible to have both connections at one place? 是否可以将两个连接都放在一个地方?
Any help or suggestions would be appreciated. 任何帮助或建议,将不胜感激。 Thanks 谢谢

I believe that an ODBC connection is made using an ODBC driver custom-made for the specific DB engine (eg Oracle, MSSQL, PSQL, etc.), and hence, a sole query cannot contain two different database engines as the query runs through a specific driver through the ODBC interface. 我认为,ODBC连接是使用为特定数据库引擎(例如Oracle,MSSQL,PSQL等)定制的ODBC驱动程序进行的,因此,单个查询不能包含两个不同的数据库引擎,因为该查询通过一个数据库运行。通过ODBC接口的特定驱动程序。

However, you can easily utilize two ODBC drivers in on code using a simple script in any programming language which has an ODBC library. 但是,您可以使用具有ODBC库的任何编程语言中的简单脚本,轻松地在代码中使用两个ODBC驱动程序。 For example, I use Python along with pyodbc to initialize multiple connections and transfer data between MSSQL, MySQL and PSQL databases. 例如,我使用Python和pyodbc来初始化多个连接并在MSSQL,MySQL和PSQL数据库之间传输数据。 Here's a pseudo-code example: 这是一个伪代码示例:

import pyodbc
psql_cursor = pyodbc.connect('<PSQL_ODBC_CONNECTION_STRING>').cursor()
mysql_cursor = pyodbc.connect('<MYSQL_ODBC_CONNECTION_STRING>').cursor()
result_set = mysql_cursor.execute('<SOME_QUERY>').fetchall()
to_insert = <.... Some code to transform the returned data if needed ....>
psql_cursor = psql_cursor.execute('insert into <some_table> VALUES (%s)' % to_insert)

I realize I'm taking you in a different direction, but hopefully this is still helpful in someway. 我知道我将您带往另一个方向,但是希望这在某种程度上还是有帮助的。 Happy to provide other examples if needed. 如果需要,很高兴提供其他示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM