oracle 如何使用 Pro*C 连接到数据库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4825547/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:34:17  来源:igfitidea点击:

How do I connect to a database using Pro*C?

coracleoracle-pro-c

提问by suvitha

As the title says, how do I connect to a given database in Oracle's Pro C? I don't want the connection for Oracle database but for some other database.

正如标题所说,如何连接到 Oracle Pro C 中的给定数据库?我不想要 Oracle 数据库的连接,而是其他一些数据库的连接。

回答by paxdiablo

You use the exec sql connectstatement in your C code:

exec sql connect在 C 代码中使用以下语句:

EXEC SQL CONNECT :myUserId IDENTIFIED BY :myPassword;

If you want to connect to a non-Oracle database, you will probably have to use the atversion of the command:

如果要连接到非 Oracle 数据库,则可能必须使用at以下命令版本:

EXEC SQL CONNECT :myUserId IDENTIFIED BY :myPassword AT :myDbName;

and set up a database link in Oracle so that it can pass requests through to the other DBMS.

并在 Oracle 中设置一个数据库链接,以便它可以将请求传递到其他 DBMS。

DBMS' like DB2 provide transparent gateways which can give you this facility without having to go through ODBC. It depends on which DBMS you're targeting as to how you'd go about setting this up.

DBMS 像 DB2 一样提供透明的网关,它可以为您提供这种便利,而无需通过 ODBC。至于如何进行设置,这取决于您针对的是哪个 DBMS。

回答by paxdiablo

From the documentation available hereand in more detail hereit looks like you can embed a CONNECTstatement directly in your code.

此处提供的文档以及此处的更多详细信息来看,您似乎可以CONNECT直接在代码中嵌入一​​条语句。

To quote the first article, a simplified connect statement would be:

引用第一篇文章,一个简化的连接语句是:

EXEC SQL CONNECT { :user IDENTIFIED BY :oldpswd | :usr_psw }
   [[ AT { dbname | :host_variable }] USING :connect_string ]
      [ {ALTER AUTHORIZATION :newpswd  |  IN { SYSDBA | SYSOPER } MODE} ] ;