在oracle10g环境下使用occi调用含有clob出参的存储过程时,抛出异常:段错误
问题描述:
在oracle10g环境下使用occi调用含有clob出参的存储过程时,抛出异常:段错误
有人知道是什么原因么
数据库版本:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
测试存储过程
CREATE OR REPLACE PROCEDURE p_test_clob_out(
i_p1 in varchar2,
i_p2 in varchar2,
o_info out clob,
o_code out varchar2,
o_msg out varchar
) AS
v_len int;
BEGIN
v_len := to_number(i_p1);
dbms_lob.createtemporary(o_info, TRUE);
for i in 1..v_len loop
dbms_lob.append(o_info,i_p2);
dbms_lob.append(o_info,chr(13)||chr(10));
end loop;
commit;
o_code := 'EC00';
o_msg := '处理成功';
EXCEPTION
WHEN OTHERS THEN
rollback;
o_code := to_char(SQLCODE);
o_msg := SQLERRM;
END;
/
测试c程序
#include <iostream>
#include <string>
#include "occi.h"
using namespace oracle::occi;
using namespace std;
int main()
{
cout << "start" << endl;
string user = "test2";
string pwd = "test2";
string link = "ora10";
try
{
//创建Environment对象
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
Statement *stmt;
//连接数据库
Connection *conn = env->createConnection(user, pwd, link);
cout << "conn success" << endl;
//调用业务过程
stmt = conn->createStatement("BEGIN p_test_clob_out(:v1,:v2,:v3,:v4,:v5); END;");
stmt->setString(1, "10");
stmt->setString(2, "测试");
stmt->registerOutParam(3, OCCICLOB);
stmt->registerOutParam(4, OCCISTRING, 1000);
stmt->registerOutParam(5, OCCISTRING, 2000);
//stmt->executeUpdate();
stmt->execute();
//取出clob
Clob clob_ouput = stmt->getClob(3);
//clob长度
//unsigned int cloblen = clob_ouput.length();
//cout << cloblen << endl;
//分配空间用于存储返回的clob中的字符
//char *chr_out = (char *)malloc(cloblen);
//设置字符类型,避免中文乱码
//clob_ouput.setCharSetForm(OCCI_SQLCS_IMPLICIT);
//读取clob中的数据到内存空间
//clob_ouput.open(OCCI_LOB_READONLY);
//clob_ouput.read(cloblen * 4, (unsigned char *)chr_out, cloblen * 4, 1);
//clob_ouput.close();
//打印clob
//chr_out[cloblen]='\0';
//string str_ouput = chr_out;
//cout << str_ouput.c_str() << endl;
//释放内存
//free(chr_out);
//chr_out = NULL;
//打印其他参数
string col4 = stmt->getString(4);
string col5 = stmt->getString(5);
cout << col4 << endl;
cout << col5 << endl;
//终止Statement对象
conn->terminateStatement(stmt);
//断开数据库
env->terminateConnection(conn);
//终止Environment对象
Environment::terminateEnvironment(env);
cout << "end!" << endl;
return 0;
}
catch (SQLException e)
{
cout << e.getMessage() << endl;
return -1;
}
}
编译
g++ test_getclob.cpp -I./include -L. -Wl,-rpath=. -lclntsh -locci /usr/lib/libstdc++.so.5 -Wall -O -g
运行
[root@localhost accitest]# ./a.out
start
conn success
EC00
处理成功
end!
段错误
ldd
[root@localhost accitest]# ldd a.out
linux-gate.so.1 => (0x0061e000)
libclntsh.so.10.1 => ./libclntsh.so.10.1 (0x0068c000)
libocci.so.10.1 => ./libocci.so.10.1 (0x00110000)
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x0020a000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x002c3000)
libm.so.6 => /lib/libm.so.6 (0x003ae000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x003d7000)
libc.so.6 => /lib/libc.so.6 (0x003e3000)
libnnz10.so => ./libnnz10.so (0x057ad000)
libdl.so.2 => /lib/libdl.so.2 (0x0053c000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00541000)
libnsl.so.1 => /lib/libnsl.so.1 (0x0055a000)
/lib/ld-linux.so.2 (0x0066f000)
gdb
[root@localhost accitest]# gdb a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.0.1-32.el5)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/accitest/a.out...done.
(gdb)
(gdb)
(gdb) r
Starting program: /home/accitest/a.out
warning: .dynamic section for "/usr/lib/libstdc++.so.6" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libm.so.6" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libgcc_s.so.1" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libc.so.6" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libdl.so.2" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libpthread.so.0" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
warning: .dynamic section for "/lib/libnsl.so.1" is not at the expected address
warning: difference appears to be caused by prelink, adjusting expectations
[Thread debugging using libthread_db enabled]
start
conn success
EC00
处理成功
end!
Program received signal SIGSEGV, Segmentation fault.
0x00d833de in kollfrfn () from ./libclntsh.so.10.1
驱动文件信息,来源于/oracle/product/10.2.0/db_1/lib
-rwxr-xr-x 1 root root 151083 11-08 16:22 a.out
drwxr-xr-x 2 root root 4096 11-08 16:10 include
lrwxrwxrwx 1 root root 17 11-08 16:10 libclntsh.so -> libclntsh.so.10.1
-rw-r--r-- 1 root root 18451364 2012-05-28 libclntsh.so.10.1
-rw-r--r-- 1 root root 5480533 2005-06-22 libnnz10.so
-rw-r--r-- 1 root root 1764366 2005-06-28 libocci10.a
lrwxrwxrwx 1 root root 15 11-08 16:10 libocci.so -> libocci.so.10.1
-rw-r--r-- 1 root root 1412527 2012-05-28 libocci.so.10.1
-rw-r--r-- 1 root root 1991 11-08 16:24 test_getclob.cpp
include,来源于/oracle/product/10.2.0/db_1/rdbms/public
[root@localhost include]# ll
总计 1488
-rw-r--r-- 1 root root 33230 2005-02-08 nzerror.h
-rw-r--r-- 1 root root 85310 2004-10-11 nzt.h
-rw-r--r-- 1 root root 11600 2004-03-03 occiAQ.h
-rw-r--r-- 1 root root 38630 2004-12-28 occiCommon.h
-rw-r--r-- 1 root root 73063 2005-01-10 occiControl.h
-rw-r--r-- 1 root root 35218 2004-11-08 occiData.h
-rw-r--r-- 1 root root 2115 2002-10-15 occi.h
-rw-r--r-- 1 root root 29156 2003-11-13 occiObjects.h
-rw-r--r-- 1 root root 7155 1998-05-07 oci1.h
-rw-r--r-- 1 root root 10361 2004-03-19 oci8dp.h
-rw-r--r-- 1 root root 410791 2004-09-24 ociap.h
-rw-r--r-- 1 root root 6055 2000-05-31 ociapr.h
-rw-r--r-- 1 root root 43225 2003-07-07 ocidef.h
-rw-r--r-- 1 root root 4014 1999-05-13 ocidem.h
-rw-r--r-- 1 root root 11331 2002-12-24 ocidfn.h
-rw-r--r-- 1 root root 8954 2003-07-07 ociextp.h
-rw-r--r-- 1 root root 150691 2005-04-07 oci.h
-rw-r--r-- 1 root root 6638 2000-12-04 ocikpr.h
-rw-r--r-- 1 root root 4351 2004-01-30 ocixmldb.h
-rw-r--r-- 1 root root 19099 2003-05-05 odci.h
-rw-r--r-- 1 root root 6605 2004-03-30 oratypes.h
-rw-r--r-- 1 root root 15031 2003-07-07 orid.h
-rw-r--r-- 1 root root 102726 2003-07-07 ori.h
-rw-r--r-- 1 root root 157674 2003-07-07 orl.h
-rw-r--r-- 1 root root 42626 2003-06-09 oro.h
-rw-r--r-- 1 root root 116591 2003-07-07 ort.h
-rw-r--r-- 1 root root 9520 1999-09-14 xa.h
答
你好,我是有问必答小助手,非常抱歉,本次您提出的有问必答问题,技术专家团超时未为您做出解答
本次提问扣除的有问必答次数,将会以问答VIP体验卡(1次有问必答机会、商城购买实体图书享受95折优惠)的形式为您补发到账户。
因为有问必答VIP体验卡有效期仅有1天,您在需要使用的时候【私信】联系我,我会为您补发。