1.  proc: error while loading shared libraries: libclntsh.so.11.1: cannot open shared object file: No such file or directory
解决方法:https://blog.csdn.net/roofwei/article/details/38946453
 进入$ORACLE_HOME/lib文件夹,检查libclntsh是否存在
1>[oracle@oracledb lib]$ cd $ORACLE_HOME/lib

2>[oracle@oracledb lib]$ pwd
/opt/oracle/app/product/11.2.0/dbhome_1/lib

以root用户修改/etc/ld.so.conf添加$ORACLE_HOME/lib路径

3>[root@RHELDB tmp]# vi /etc/ld.so.conf,文件内容如下:

include ld.so.conf.d/*.conf
/opt/oracle/app/product/11.2.0/dbhome_1/lib #注:这里只能写绝对路径,不能写$ORACLE_HOME/lib

4>[root@RHELDB tmp]# ldconfig
---------------------
作者:roofwei
来源:CSDN
原文:https://blog.csdn.net/roofwei/article/details/38946453
版权声明:本文为博主原创文章,转载请附上博文链接!
   
  2.Pro*C/C++: Release 11.2.0.1.0 - Production on Sun Apr 21 08:25:21 2019

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

System default option values taken from: /opt/oracle/app/product/11.2.0/dbhome_1/precomp/admin/pcscfg.cfg
 
   
   Error at line 0, column 0 in file first.pc
PCC-F-02102, Fatal error while doing C preprocessing
解决方法:
https://www.linuxidc.com/Linux/2013-08/88880p2.htm

说明在 pcscfg.cfg 中系统头文件的位置不正确,需要重新设置:
查看pcscfg.cfg文件:

$[Oracle@oracleserver ~]$ cat /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg
sys_include=(/ade/aime_rdbms_9819/oracle/precomp/public,/usr/include,/usr/lib/gcc-lib/i486-SUSE-linux/2.95.3/include,/usr/lib/gcc-lib/i386-RedHat-linux/3.2.3/include,/usr/lib/gcc-lib/i386-redhat-linux7/2.96/include)
ltype=short
查找头文件 stddef.h 位置:

1》[root@oracleserver ~]# find / -name "stddef.h" -print
/usr/include/xulrunner-sdk-1.9/system_wrappers/stddef.h
/usr/include/linux/stddef.h
/usr/lib/bcc/include/stddef.h
/usr/lib/gcc/i386-redhat-linux/3.4.6/include/stddef.h
/usr/lib/gcc/i386-redhat-linux/4.1.1/include/stddef.h
/usr/lib/syslinux/com32/include/bitsize/stddef.h
/usr/lib/syslinux/com32/include/stddef.h
/usr/src/kernels/2.6.18-194.el5-i686/include/linux/stddef.h
比较发现,pcscfg.cfg中的/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/include和/usr/lib/gcc-lib/i386-redhat-linux7/2.96/include路径均无效,与实际系统中的路径不符,修改为/usr/lib/gcc/i386-redhat-linux/4.1.1/include和/usr/lib/gcc/i386-redhat-linux/3.4.6/include 即可:

$ cat /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg
sys_include=(/ade/aime_rdbms_9819/oracle/precomp/public,/usr/include,/usr/lib/gcc-lib/i486-suse-linux/2.95.3/include,/usr/lib/gcc/i386-redhat-linux/4.1.1/include,/usr/lib/gcc/i386-redhat-linux/3.4.6/include)
ltype=short
写个简单的程序测试下:

$ proc test.pc
Pro*C/C++: Release 10.2.0.1.0 - Production on Tue May 21 16:07:16 2013

Copyright (c) 1982, 2005, Oracle. All rights reserved.

System default option values taken from: /home/oracle/OraHome1/oracle10g/precomp/admin/pcscfg.cfg




3。/usr/bin/ld: cannot find -lclntsh
/opt/oracle/app/product/11.2.0/dbhome_1/lib  $ORACLE_HOME/
vi ~/.bashrc
xport LIBRARY_PATH=$LIBRARY_PATH:/opt/oracle/app/product/11.2.0/dbhome_1/lib:/usr/lib:.






登录数据库:
sqlplus  system
Enter passwd:oracle
SQL>select * from emp;
关闭数据库:
shutdown immediate;



RHEL6.5系统管理中登录数据库的方法:
第一步:先以管理员身份登录oracle
sqlplus /nolog
SQL>conn sys as sysdba;  以系统管理员的身份连接
SQL> startup  nomount;        startup命令启动数据库实例
SQL>alter database mount;    挂载数据库
SQL>alter database open;    alter database命令讲数据库的状态修改为open

第二步:以普通用户登录:
sqlplus system
passwd:oracle
关闭数据库:
SQL>shutdown immediate;

  create table  emp(
       id  number,
       name varchar2(30),
       salary number  
   );
   
   插入数据库:
   insert  into emp values(1,'test1',123);
   commit;

 

 

接下来编写程序

//first.pc   C语言编写

/*
[oracle@oracledb]$ proc first.pc
[oracle@oracledb]$  gcc first.c -lclntsh
[oracle@oracledb$ ./a.out
*/

#include<stdio.h>

/* 包含一个数据结构 */
exec sql include sqlca;
int main()
{

char userpasswd[30]="system/oracle";
char var_name[30];
/* 链接数据库 */
exec sql connect:userpasswd;
/* 查询 */
exec sql select name into :var_name  from emp where id=1;
printf("var_name=%s \n",var_name);

/* 提交之后断开链接 */
exec sql commit work release;
}

 

mycpp.pc  C++ 语言编写

//    proc ***.pc oname=***.cpp parse=none code=cpp;
//    proc mycpp.pc oname=mycpp.cpp parse=none code=cpp
//    g++ mycpp.cpp -lclntsh
//    ./a.out
#include<iostream>
using namespace std;

/* 包含一个数据结构 */
exec sql include sqlca;
int main()
{
    exec sql begin declare section;
    char userpasswd[30]="system/oracle";
    char var_name[30];
    exec sql end   declare section;
    /* 链接数据库 */
    exec sql connect:userpasswd;
    /* 查询 */
    exec sql select name into :var_name  from emp where id=1;
    cout<<"var_name="<<var_name<<endl;
    /* 提交之后断开链接 */
    exec sql commit work release;

}