PRO*C是Oracle提供的应用程序专用开发工具,它以C语言为宿主语言,能在C程序中嵌入SQL语句,进行数据库操作。
官方下载路径:http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
建议下载RPM包,方便安装。
注明: Base下的Basic Package和Basic Light Package是相同的安装包,下载一个就行。
官方下载路径:http://www.oracle.com/technetwork/topics/precomp-112010-084940.html
以安装PROC为例:
[zhaojq@ Oracle~]$ rpm -ivh oracle-instantclient18.3-precomp-18.3.0.0.0-1.x86_64.rpm
准备中... ################################# [100%]
正在升级/安装...
1:oracle-instantclient18.3-precomp-################################# [100%]
安装完成后,执行proc -v出现错误:
[zhaojq@ Oracle~]$ proc -v
proc: error while loading shared libraries: libclntsh.so.18.1: cannot open shared object file: No such file or directory
解决办法:
[zhaojq@ Oracle~]$ vi /etc/ld.so.conf
在末尾增加一行 /usr/lib/oracle/18.3/client64/lib/
执行
[zhaojq@ Oracle~]$ ldconfig
[zhaojq@ Oracle~]$ proc -v
Pro*C/C++: Release 18.0.0.0.0 - Production on Thu Aug 2 10:55:09 2018
Version 18.3.0.0.0
[zhaojq@ Oracle~]$ touch connect.pc
[zhaojq@ Oracle~]$ vim connect.pc
#include.h>
#include.h>
#include.h>
#include.h>
void main()
{
char username[10], password[10], server[10];
char name[11], title[10];
float salary;
printf("input name:");
gets(username);
printf("input pass:");
gets(password);
printf("input server:");
gets(server);
EXEC SQL CONNECT :username IDENTIFIED BY :password USING :server;
printf("input empoyee name:");
gets(name);
EXEC SQL SELECT sal, job INTO :salary, :title FROM emp WHERE UPPER(ename) = UPPER(:name);
printf("title:%s, salary:%6.2f\n", title, salary);
EXEC SQL COMMIT RELEASE;
}
[zhaojq@ Oracle~]$ proc iname=connect.pc parse=full include=/usr/local/include/ include=/usr/include/
Pro*C/C++: Release 18.0.0.0.0 - Production on Thu Aug 2 09:51:53 2018
Version 18.3.0.0.0
Copyright (c) 1982, 2018, Oracle and/or its affiliates. All rights reserved.
System default option values taken from: /usr/lib/oracle/18.3/client64/lib/precomp/admin/pcscfg.cfg
[zhaojq@ Oracle~]$ ls
connect.pc connect.c connect.lis
直接GCC编译,发生错误:
[root@vio062033 Oracle]# gcc -o connect connect.c
connect.c: 在函数‘main’中:
connect.c:155:3: 警告:不建议使用‘gets’(声明于 /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(username);
^
connect.c:157:3: 警告:不建议使用‘gets’(声明于 /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(password);
^
connect.c:159:3: 警告:不建议使用‘gets’(声明于 /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(server);
^
connect.c:217:3: 警告:不建议使用‘gets’(声明于 /usr/include/stdio.h:638) [-Wdeprecated-declarations]
gets(name);
^
/tmp/ccOHKOZ3.o:在函数‘main’中:
connect.c:(.text+0x22): 警告:the `gets' function is dangerous and should not be used.
connect.c:(.text+0xa7):对‘ECPGget_sqlca’未定义的引用
connect.c:(.text+0x2ae):对‘sqlcxt’未定义的引用
connect.c:(.text+0x336):对‘ECPGget_sqlca’未定义的引用
connect.c:(.text+0x50b):对‘sqlcxt’未定义的引用
connect.c:(.text+0x57b):对‘ECPGget_sqlca’未定义的引用
connect.c:(.text+0x5b8):对‘sqlcxt’未定义的引用
解决办法:
ECPGget_sqlca’未定义的引用
编译时增加 -lecpg
对‘sqlcxt’未定义的引用
编译时增加 -L/usr/lib/oracle/18.3/client64/lib -lclnts
正确的编译命令:
[zhaojq@ Oracle~]$ gcc -o connect connect.c -L/usr/lib/oracle/18.3/client64/lib -lclntsh -lecpg
[zhaojq@ Oracle~]$ ls
connect connect.pc connect.c connect.lis
编译成功,生成可执行文件。