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
How do I connect to a database using Pro*C?
提问by suvitha
回答by paxdiablo
You use the exec sql connect
statement 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 at
version 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 CONNECT
statement 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} ] ;