1.用whiche proc 和 proc查看当前环境下proc是否配置好。
[sms@db proc_demo]$ which proc
/u01/app/oracle/product/10.2.0/client_1/bin/proc
[sms@db proc_demo]$ ls -lt /u01/app/oracle/product/10.2.0/client_1/bin/proc
-rwxr-xr-x 1 sms oinstall 7362193 Oct 15 15:55 /u01/app/oracle/product/10.2.0/client_1/bin/proc
[sms@db proc_demo]$
2.安装oracle或者oracle客户端,里面就带有proc的环境,需要在bash_profile中配置export PATH=$ORACLE_HOME/bin:$PATH,因为proc在$ORACLE_HOME/bin目录下,
配置LD_LIBRARY_PATH环境变量是因为这里有proc执行时候需要的函数库(不配置它会报libclntsh.so找不到)。我的虚拟机中详细配置如下:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/client_1
#export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
export PATH=$ORACLE_HOME/bin:$PATH
export LANG="en_US.UTF-8"
export NLS_LANG="American_America.AL32UTF8" #SIMPLIFIED CHINESE_CHINA.ZHS16GBK
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
#java settings
export PATH
export JAVA_HOME=/u01/app/software/jdk1.6.0_21
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export JAVA_lib=/home/sms/javamem/memcDemo
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_lib/lib:$JAVA_lib/lib/commons-pool-1.5.6.jar:$JAVA_lib/lib/java_memcached-release_2.6.6.jar:$JAVA_lib/lib/slf4j-api-1.6.1.jar:$JAVA_lib/lib/slf4j-simple-1.6.1.jar
CATALINA_HOME=/u01/app/software/apache-tomcat-6.0.18
3.配置好环境变量生效后,执行proc,就可以显示出当前环境下proc的默认参数值。
修改系统配置文件,添加pro*c程序需要的头文件路径。
[sms@db msgseq]$ cat /u01/app/oracle/product/10.2.0/client_1/precomp/admin/pcscfg.cfg
sys_include=(/u01/app/oracle/product/10.2.0/client_1/precomp/public/,/usr/include,/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/include,/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3/include,/usr/lib/gcc/x86_64-redhat-linux/4.1.1/include,/usr/lib64/gcc/x86_64-suse-linux/4.1.0/include)
ltype=short
define=__x86_64__
[sms@db proc_demo]$ proc
Pro*C/C++: Release 10.2.0.1.0 - Production on Thu Oct 17 15:41:25 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
System default option values taken from: /u01/app/oracle/product/10.2.0/client_1/precomp/admin/pcscfg.cfg
Option Name Current Value Description
-------------------------------------------------------------------------------
auto_connect no Allow automatic connection to ops$ account
char_map charz Mapping of character arrays and strings
close_on_commitno Close all cursors on COMMIT
cmax 100 CMAX Value for connection pool
cmin 2 CMIN Value for connection pool
cincr 1 CINCR Value for connection pool
ctimeout 0 CTIMEOUT Value for connection pool
cnowait 0 CNOWAIT Value for connection pool
code kr_c The type of code to be generated
comp_charset multi_byte The character set type the C compiler supports
config default Override system configuration file with another
cpool no Support connection pooling
cpp_suffix *none* Override the default C++ filename suffix
dbms native v6/v7/v8 compatibility mode
def_sqlcode no Generate '#define SQLCODE sqlca.sqlcode' macro
define __x86_64__ Define a preprocessor symbol
*none*
duration transaction Set pin duration for objects in the cache
dynamic oracle Specify Oracle or ANSI Dynamic SQL Semantics
errors yes Whether error messages are sent to the terminal
errtype *none* Name of the list file for intype file errors
events no Support publish-subscribe event notifications
fips none FIPS flagging of ANSI noncompliant usage
header *none* Specify file extension for Precompiled Headers
hold_cursor no Control holding of cursors in the cursor cache
iname *none* The name of the input file
include *none* Directory paths for included files
intype *none* The name of the input file for type information
lines no Add #line directives to the generated code
lname *none* Override default list file name
ltype short The amount of data generated in the list file
maxliteral 1024 Maximum length of a generated string literal
maxopencursors 10 Maximum number of cached open cursors
mode oracle Code conformance to Oracle or ANSI rules
native_types no Support for native float/double
nls_char *none* Specify National Language character variables
nls_local no Control how NLS character semantics are done
objects yes Support object types
oname *none* The name of the output file
oraca no Control the use of the ORACA
pagelen 80 The page length of the list file
parse full Control which non-SQL code is parsed
prefetch 1 Number of rows pre-fetched at cursor OPEN time
release_cursor no Control release of cursors from cursor cache
select_error yes Control flagging of select errors
sqlcheck syntax Amount of compile-time SQL checking
sys_include /usr/lib64/gcc/Directory where system header files are found
/usr/lib/gcc/x86_64-redhat-linux/4.1.1/include
/usr/lib64/gcc-lib/x86_64-suse-linux/3.3.3/include
/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/include
/usr/include
/u01/app/oracle/product/10.2.0/client_1/precomp/public/
threads no Indicates a multi-threaded application
type_code oracle Use Oracle or ANSI type codes for Dynamic SQL
unsafe_null no Allow a NULL fetch without indicator variable
userid *none* A username/password [@dbname] connect string
utf16_charset nchar_charset The character set form used by UTF16 variables
varchar no Allow the use of implicit varchar structures
version recent Which version of an object is to be returned
PCC-F-02135, CMD-LINE: User asked for help
[sms@db proc_demo]$
4.常用预编译选项 INAME,ONAME,INCLUDE,PARSE,SQLCHECK,USERID
INAME:用于指定pc源文件的名称(路径+文件名,文件名)
ONAME:用于指定编译生成后c/c++文件的名称(路径+文件名,文件名),文件名的后缀由CPP_SUFFIX指定
INCLUDE:用于指定#include或者EXEC SQL INCLUDE 语句对应的头文件路径。在预编译的时候,预编译器会按照下面顺序定位c/c++头文件
a.当前目录
b.SYS_INCLUDE选项指定的目录(命令行,系统配置文件,用户配置文件)
c.INCLUDE选项指定的目录(命令行,系统配置文件,用户配置文件)
d.c/c++标准头文件的内置目录(环境变量?)
PARSE:指定预编译时解析pc源程序的方法,三个待选值FULL(默认值,用c解析器解析解析源程序,源程序中不能带有c++的对象),PARTIAL,NONE(要选为C++时需要设置为PARTIAL或NONE,此时必须定义部分内定义的宿主变量。还没有找到哪些内定义的宿主变量???)。
SQLCHECK:用于指定sql语法和语义的检查方式。三个待选值SEMANTICS,FULL(SEMANTICS,FULL时可以解析plsql,必须设置userid),SYNTAX(默认值,只能解析sql语法,不能解析pl/sql块)
USERID:指定用户名,密码,网络服务名
proc iname=/home/sms/procdemo/conntest.pc oname=/home/sms/procdemo/conntest.c
parse=full
include=$ORACLE_HOME/precomp/public proc代码调用的头文件
include=/usr/lib c/c++代码调用的头文件
sqlcheck=full userid=scott/tiger@orcl
[sms@db proc_demo]$ proc iname=conntest.pc oname=conntest_1.c parse=full include=$ORACLE_HOME/precomp/public include=/usr/lib sqlcheck=full userid=ydqxn/ydqxn@ydqx
Pro*C/C++: Release 10.2.0.1.0 - Production on Thu Oct 17 16:49:12 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
System default option values taken from: /u01/app/oracle/product/10.2.0/client_1/precomp/admin/pcscfg.cfg
[sms@db proc_demo]$
[sms@db proc_demo]$ ls -lt
total 72
-rw-r--r-- 1 sms oinstall 6476 Oct 17 16:49 conntest_1.c
-rw-r--r-- 1 sms oinstall 0 Oct 17 16:49 conntest.lis
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpExTC2f
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpIOxpan
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpll0vBj
-rwxr-xr-x 1 sms oinstall 14845 Oct 16 17:25 ddl_dml
-rw-r--r-- 1 sms oinstall 17875 Oct 16 17:25 ddl_dml.c
-rw-r--r-- 1 sms oinstall 2767 Oct 16 17:25 ddl_dml.pc
-rwxr-xr-x 1 sms oinstall 10329 Oct 16 15:13 conntest
-rw-r--r-- 1 sms oinstall 6478 Oct 16 15:13 conntest.c
-rw-r--r-- 1 sms oinstall 816 Oct 16 15:13 conntest.pc
[sms@db proc_demo]$ proc iname=conntest.pc oname=conntest_1.c parse=full include=$ORACLE_HOME/precomp/public include=/usr/lib sqlcheck=full
Pro*C/C++: Release 10.2.0.1.0 - Production on Thu Oct 17 16:49:37 2013
Copyright (c) 1982, 2005, Oracle. All rights reserved.
System default option values taken from: /u01/app/oracle/product/10.2.0/client_1/precomp/admin/pcscfg.cfg
[sms@db proc_demo]$
[sms@db proc_demo]$
[sms@db proc_demo]$ gcc -o conntest_1 conntest_1.c -I $ORACLE_HOME/precomp/public -L $ORACLE_HOME/lib -l clntsh
[sms@db proc_demo]$ ls -lt
total 84
-rwxr-xr-x 1 sms oinstall 10331 Oct 17 16:50 conntest_1
-rw-r--r-- 1 sms oinstall 6476 Oct 17 16:49 conntest_1.c
-rw-r--r-- 1 sms oinstall 0 Oct 17 16:49 conntest.lis
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpAezcy9
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpGRDzgS
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpm63XYA
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpExTC2f
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpIOxpan
-rw------- 1 sms oinstall 0 Oct 17 16:49 tpll0vBj
-rwxr-xr-x 1 sms oinstall 14845 Oct 16 17:25 ddl_dml
-rw-r--r-- 1 sms oinstall 17875 Oct 16 17:25 ddl_dml.c
-rw-r--r-- 1 sms oinstall 2767 Oct 16 17:25 ddl_dml.pc
-rwxr-xr-x 1 sms oinstall 10329 Oct 16 15:13 conntest
-rw-r--r-- 1 sms oinstall 6478 Oct 16 15:13 conntest.c
-rw-r--r-- 1 sms oinstall 816 Oct 16 15:13 conntest.pc
[sms@db proc_demo]$ ./conntest_1
conn success!!!
1
./conntest_1
without conn char!!
[sms@db proc_demo]$ ./conntest_1 ydqxn/ydqxn@ydqx
conn success!!!
2
./conntest_1
conn char:ydqxn/ydqxn@ydqx
conn success!!!
[sms@db proc_demo]$
5.其他预编译选项
这些预编译选项不仅可以在配置文件和命令行下使用,还可以在pc源程序中使用,在多个地方配置时,oracle使用这些参数的顺序如下:
a.pc源程序的选项值
b.命令行的选项值
c.用户配置文件的选项值(proc 带config参数)
d.系统文件的选项值
e.预编译器的内置默认值
pro*c编译环境
最新推荐文章于 2021-05-04 09:50:02 发布