Oracle 10g及pro*c相關問題及解決方法

Oracle 10g及pro*c相關問題及解決方法 2010-09-26 10:47:35

分類: C/C++

最近一直在進行ORACLE 10g和PRO*C的學習,其中遇到了不少的問題,現記錄下來,以供以後參考。

一、常見問題
 
[注:我的linux版本是rhel 5,Oracle版本是10g]
1、在ORACLE 10g 安裝準備的過程中:缺少libXp.so.6依賴
上網搜過不少文章,但是都不是很好的解決
我自己摸索出一個解決方法:
在RHEL5的安裝盤中找到libXp-1.0.0-8.i386.rpm,進行安裝後,便可解決

2、在ORACLE 10g 安裝過程中Xlib: connection to ":0.0" refused by server

Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified
Error: Can't open display: :0.0

以root用戶登陸,在shell中運行
[root@brady ~]# xhost local:oracle
non-network local connections being added to access control list
然後oracle身份就可以運行X程序了。

man xhost中有這樣一段
A complete name has the syntax ‘‘family:name’’ where the families are as follows:
inet      Internet host (IPv4)
inet6     Internet host (IPv6)
dnet      DECnet host
nis       Secure RPC network name
krb       Kerberos V5 principal
local     contains only one name, the empty string
si        Server Interpreted

其中local那個是用來解決同一臺機器的不同用戶訪問X的問題的。

3.proc: error while loading shared libraries: libclntsh.so.10.1:
cannot open shared object file: No such file or directory

解決方法:
在/etc/profile中添加
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib;
export LD_LIBRARY_PATH

然後可以用source /etc/profile 生效一下

4、PCC-S-02201錯誤

在用proc進行編譯的時候(proc iname=test.pc) 出錯
錯誤信息有很多:
PCC-S-02201, Encountered the symbol "<eof>;" when expecting one of the following....
發生 PCC-S-02201 錯誤時有兩種解決辦法:
1)升級編譯器
2)設置 parse=none


更正後的命令:proc iname=test.pc parse=none
結果生成test.c文件

5、error: sqlca.h: No such file or directory

執行gcc -o test test.c時:
test.c:152:19: error: sqlca.h: No such file or directory
sqlca.h在$ORACLE_HOME/precomp/public/下
更正後的命令:gcc -o test test.c -I $ORACLE_HOME/precomp/public

6、undefined reference to `sqlcxt'

執行5中的命令時出現錯誤如下:
test.c:(.text+0x5e5): undefined reference to `sqlcxt'
需要用到$ORACLE_HOME/lib/libclntsh.so

故需加上 -L $ORACLE_HOME/lib -l clntsh
更正後的命令爲:
gcc -o test test.c -I /home/oracle/oracle/product/10.2.0/db_1/precomp/public -L $ORACLE_HOME/lib -l clntsh
OK!至此編譯成功!

但是這樣寫太麻煩
 
7、自定義的結構體總是編譯不過去,提示類型不對
 
我的環境是suse10sp2+oracle10g, 程序中定義瞭如下結構體,並在EXEC SQL中使用此結構體的變量    
 typedef struct Tjkjmlog{
           char  m_getdatatime[18 +1];
           char  m_monitorcode[6 +1];
           char  m_ip[23 +1];
           char  m_res[30+1];
           char  m_alarmlevel[2+1];
           char  m_info[128 +1];
        }Tjkjmlog;
 
編譯錯誤如下:
hrwang:~/test # proc iname=jkserv.pc
Pro*C/C++: Release 10.2.0.1.0 - Production on Mon Sep 27 10:15:46 2010
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
System default option values taken from: /opt/or1/precomp/admin/pcscfg.cfg
Syntax error at line 491, column 2, file jkserv.pc:
Error at line 491, column 2 in file jkserv.pc
        Tjkjmlog jmlog;                    
.1
PCC-S-02201, Encountered the symbol "Tjkjmlog" when expecting one of the followi
ng:
   auto, char, const, double, enum, extern, float, int, long,
   ulong_varchar, OCIBFileLocator OCIBlobLocator,
   OCIClobLocator, OCIDateTime, OCIExtProcContext, OCIInterval,
   OCIRowid, OCIDate, OCINumber, OCIRaw, OCIString, register,
   short, signed, sql_context, sql_cursor, static, struct,
   typedef, union, unsigned, utext, uvarchar, varchar, void,
   volatile, a typedef name, a precompiled header, exec oracle,
   exec oracle begin, exec, exec sql, exec sql begin,
   exec sql end, exec sql type, exec sql var, exec sql include,
The symbol "enum," was substituted for "Tjkjmlog" to continue.
Error at line 0, column 0 in file jkserv.pc
PCC-F-02102, Fatal error while doing C preprocessing

 
自定義的結構體提示沒有發現的錯誤,通常是由於結構體定義在了
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL END DECLARE SECTION;
這兩個語句的外面,只要將結構體定義在這兩句中間就可以了。如下:
 
EXEC SQL BEGIN DECLARE SECTION;
 typedef struct Tjkjmlog{
           char  m_getdatatime[18 +1];
           char  m_monitorcode[6 +1];
           char  m_ip[23 +1];
           char  m_res[30+1];
           char  m_alarmlevel[2+1];
           char  m_info[128 +1];
        }Tjkjmlog;
 Tjkjmlog jmlog;    /* 定義結構體變量 */
EXEC SQL END DECLARE SECTION;
 

8、proc編譯時,提示相關的表需要聲明

我的環境是在suse10sp2+oracle10g。 程序中使用exec sql insert into t_jm_err_his語句,編譯時,總提示如下錯誤:

hrwang:~/test # proc iname=jkserv.pc

Pro*C/C++: Release 10.2.0.1.0 - Production on Mon Sep 27 09:42:53 2010

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

System default option values taken from: /opt/or1/precomp/admin/pcscfg.cfg

Error at line 677, column 10 in file jkserv.pc
         EXEC SQL insert into T_jm_err_his
.........1
PLS-S-00201, identifier 'T_JM_ERR_HIS' must be declared
Error at line 677, column 10 in file jkserv.pc
         EXEC SQL insert into T_jm_err_his
.........1
PLS-S-00000, SQL Statement ignored
Semantic error at line 677, column 10, file jkserv.pc:
         EXEC SQL insert into T_jm_err_his
.........1
PCC-S-02346, PL/SQL found semantic errors

出現這樣的錯誤,我們可以proc iname=jkserv.pc userid=scott/hrwang來進行編譯,
並且確保scott用戶對這個表有權限(根據你的oracle情況更改用戶名和密碼)。或者你可以將userid=scott/hrwang 加入$oracle_home/precomp/admin/pcscfg.cfg文件中,這樣在編譯時就不用每次都指定了。
 

9、error while loading shared libraries: $ORACLE_HOME/lib/libnnz10.so:
cannot restore segment prot after reloc: Permission denied

執行程序(./test)時提示錯誤:
error while loading shared libraries: $ORACLE_HOME/lib/libnnz10.so:
cannot restore segment prot after reloc: Permission denied
相關的文章:
Topic:
Some Linux distributions with SELinux enabled may prevent IDL from running under the default security context. This TechTip is a workaround for CR#41937

Discussion:
Newer Linux distributions have enabled new kernel security extensions from the SELinux project at the NSA. These extensions allow finer-grained control over system security. However, SELinux also changes some default system behaviors, such as shared library loading, that can be problematic to third party programs.If you receive the error message "cannot restore segment prot after reloc: Permission denied" when launching IDL, then your SELinux configuration is preventing IDL from launching.

To rectify this issue, you can either:
(1)Change the default security context for IDL by issuing the command:
chcon -t texrel_shlib_t /usr/local/rsi/idl_6.1/bin/bin.linux.x86/*.so

(2)Disabling SELinux altogether by setting the line
SELINUX=disabled
in your /etc/sysconfig/selinux file.

我使用的解決辦法:chcon -t texrel_shlib_t $ORACLE_HOME/lib/*.so
 
 
注:這篇文章很多內容是轉自互聯網,具體出處找不到了:(。 7、8是自己添加上去的。3、4、5、6這幾個問題也都遇到並按照上述方法解決了。其它的還沒有試過。
 
 
 
二、SUSE10SP2+ORACLE10G的PRO*C的環境設置
 
下面我再將自己配置suse10sp2+oracle10的proc環境進行一下說明,供大家參考:
 
(1)安裝oracle這步我就省略了
 
(2)在/etc/profile文件中添加相關oracle環境變量設置:
ORACLE_SID=HRWANG  
ORACLE_HOME=/opt/or1
LD_LIBRARY_PATH=/opt/or1/lib:/lib:/usr/lib:/usr/local/lib
PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID ORACLE_HOME LD_LIBRARY_PATH PATH
 
上述環境變量應該根據你的情況進行調整,不能死搬硬套。更改完成後可以通過source /etc/profile來使其在當前shell中生效。
 
(3)更改$ORACLE_HOME/precomp/admin/pcscfg.cfg爲如下內容:
sys_include=(/opt/or1/precomp/public,/usr/include,/usr/lib/gcc/i586-suse-linux/4.1.2/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
userid=scott/hrwang           #數據庫用戶名密碼,根據你的情況填寫
mode=oracle
parse=none
sqlcheck=semantics
dbms=v8
def_sqlcode=true
 
此文件的sys_include中應包含sqlca.h所在的路徑,我這裏爲/opt/or1/precomp/public。還需要包括stddef.h所在的路徑,我這裏爲/usr/lib/gcc/i586-suse-linux/4.1.2/include。如果這兩個文件你也不知道在什麼位置,可以通過
#find / -name "sqlca.h"
#find / -name "stddef.h"
來查找。另外再將常用的頭文件路徑加上即可,如/usr/include。
 
 

發佈了2 篇原創文章 · 獲贊 4 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章