您的位置:首页 > 数据库 > Oracle

Oracle Proc*c初步学习总结

2012-02-10 18:37 295 查看
  有了oracle环境后,开始在Linux下编写proc*c 初始例子一般都是一个连接到数据库的程序:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sqlca.h"

EXEC SQL BEGIN DECLARE SECTION;
char *uid = "scott/tiger@CENTOS";
EXEC SQL END DECLARE SECTION;

int main()
{
EXEC SQL CONNECT :uid;
printf("%s",sqlca.sqlerrm.sqlerrmc);
if(sqlca.sqlcode == 0)
printf("Success!!!\n");
else
printf("Fail!!!\n");
}

将其保存为.pc的源程序文件。

流程为 (.pc源文件——>使用proc预编译为.c文件——>使用gcc编译连接——>生成可执行文件)。

使用proc预编译的时候需要注意以下几点 :

  1、要正确的配置/u01/app/oracle/product/10.2.0/db_1/precomp/admin/pcscfg.cfg这个文件中的sys_include=(/u01/app/oracle/product/10.2.0/db_1/precomp/public,/usr/include,/usr/lib/gcc/i386-redhat-linux/4.1.1/include,/usr/lib/gcc/i386-redhat-linux/3.4.6/include)。查看本机的所拥有的库文件:find /usr/lib -name "stddef.h" -print.修改相应的配置。

  若没有配置正确会产生一个错误信息:PCC-S-02015, unable to open include file

  下面是比较全面的解析(E文的)

    Cause: The precompiler could not open the listing file. This message can result from many causes. For example:

    A pathname for a specified listing file contains a non-existent directory.
    An operating-system error occurred because the file system or disk is full.
    Write permission on the specified directory has not been granted.
    Action: Track down the cause of the error, as suggested above, and correct it.

  2、如果配置好后出现这个错误:PCC-F-02081, CMD-LINE: Unterminated option value list or value list was truncat ed.

    Cause: An option that takes a list of values was entered. The value list did not have a closing parenthesis. This error may also occur if the list of values entered on a single line was too long and Pro*C truncated it.

    Action: Ensure that all value lists are terminated with a closing parenthesis. Split long value lists into individual entries.

    不要在一个include中写入太长的内容,太多的话Pro*C会把它截断的。可以分开写或者确认其长度在适当的值内 。

最后使用gcc命令将其生成 gcc -o example example.c -I /u01/app/oracle/product/10.2.0/db_1/precomp/public/ -L /u01/app/oracle/product/10.2.0/db_1/lib/ -l clntsh

当然可以将该命令写入一个文件中执行。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: