linux下使用C语言连接oracle数据库

下载地址

https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

需要注册oracle账户

下载三个rpm包(对应oracle数据库的版本)

[root@localhost oracle]# ls

oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm  oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

[root@localhost oracle]#

安装

[root@localhost oracle]#

[root@localhost oracle]# rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

  1:oracle-instantclient12.########################################### [100%]

[root@localhost oracle]# rpm -ivh oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

  1:oracle-instantclient12.########################################### [100%]

[root@localhost oracle]# rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm

Preparing...                ########################################### [100%]

  1:oracle-instantclient12.########################################### [100%]

设置环境变量

[root@localhost oracle]# export ORACLE_HOME=/usr/lib/oracle/12.1/client64

[root@localhost oracle]# export TNS_ADMIN=$ORACLE_HOME/network/admin

[root@localhost oracle]# export NLS_LANG='simplifiedchinese_china.UTF8'

[root@localhost oracle]# export LD_LIBRARY_PATH=$ORACLE_HOME/lib

[root@localhost oracle]# export PATH=$ORACLE_HOME/bin:$PATH

编译

[root@localhost oracle]# g++ -o test -I /usr/include/oracle/12.1/client64/ -L/usr/lib/oracle/12.1/client64/lib/ oracle_test.cpp -lclntsh -locci -lmql1 -lipc1 -lnnz12 -lons -lclntshcore -Wall -O -g

[root@localhost oracle]# ls

oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm  oracle-instantclient12.1-sqlplus-12.1.0.2.0-1.x86_64.rpm  test

oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm  oracle_test.cpp

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容