利用OCI,向BLOB字段插入数据的问题

hzn1982 2010-04-23 03:53:22
问题是这样的:
oci编程:
向oracle数据库,拥有blob字段的数据插入数据时,用OCIBindByPos()函数,参数通过指定参数SQLT_BIN,可以向数据库blob字段插入数据,但是当value的位数比较大时会产生一个ora01426数值溢出问题
OCIBindByPos(stmthp, &bndhp, errhp, pos, (dvoid *)(value), (sb4)(valuesize),SQLT_BIN,(dvoid *) 0, (ub2 *)0, (ub2 *)0, (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT));

查了一下oci的文档,可以利用OCILobLocator来实现对blob的插入和获取。网上也找了不少例子。但是没有找到怎么通过OCILobLocator,来实现对非空blob的插入。
换句话说按照文档表述,没有实现成功
Binding LOB Locators
Either a single locator or an array of locators can be bound in a single bind call. In each case, the application must pass the address of a LOB locator and not the locator itself. For example, if an application has prepared a SQL statement like

INSERT INTO some_table VALUES (:one_lob)


where one_lob is a bind variable corresponding to a LOB column, and has made the following declaration:

OCILobLocator * one_lob;


Then the following sequence of steps would be used to bind the placeholder, and execute the statement

/* initialize single locator */
one_lob = OCIDescriptorAlloc(...OCI_DTYPE_LOB...);
...
/* pass the address of the locator */
OCIBindByName(...,(dvoid *) &one_lob,... SQLT_CLOB, ...);
OCIStmtExecute(...,1,...) /* 1 is the iters parameter */

网上还有oracle 提供的方法都是,向表中insert,空blob,然后再update。这种方法费时又费力。

有哪位达人,通过OCILobLocator,直接向blob字段插入数据的经历指点一下。

...全文
927 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
luj2006 2012-09-17
  • 打赏
  • 举报
回复
两年之后还有人求解这个问题。楼主当初没有把答案公布。
建树 2010-07-26
  • 打赏
  • 举报
回复
正在为这个问题(oci对blob类型的处理)郁闷ING,能给您的代码给我看一下吗
jssz103b 2010-06-17
  • 打赏
  • 举报
回复
问个问题
能把oci处理lob类型的代码给我看一下吗
OCILobLocator* plob = OCIDescriptorAlloc((void*)m_pOCIEnv,(void**)(plob ),
OCI_DTYPE_LOB,(size_t)(sizeof(OCILobLocator*),
(dvoid**)NULL);
准备SQL
然后 OCIDefineByPos(ocistmt,&pdefine1,m_pOCIError,
(ub4)1,(dvoid*)plob,(sb4)sizeof(OCILobLocator*),OCI_DTYPE_LOB, NULL, NULL, NULL, OCI_DEFAULT);
绑定第一个位置
执行
fetch
read
ForestDB 2010-06-17
  • 打赏
  • 举报
回复
恭喜,结贴。
hzn1982 2010-04-23
  • 打赏
  • 举报
回复
呵呵,这个问题我自己解决了
没有使用OCILobCreateTemporary()

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧