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

mfc 插入oracle blob、clob字段

2013-08-31 15:17 351 查看
参考网址:http://sourceforge.net/p/orclib/discussion/470800/thread/5a2f05f1

当我看到这篇文字的时候想死的心都有了,所以写下来作为以后的教训,而且是深刻的教训呀。

方法一:

OCI_Statement* stmt = OCI_StatementCreate(conn);

OCI_Lob * clob = OCI_LobCreate(conn, OCI_CLOB);

OCI_Prepare(stmt, "UPDATE tbl_clob SET clob = :clob WHERE id = :id");

OCI_BindLob(stmt, ":clob", clob);

OCI_BindInt(stmt, ":id", &id);

OCI_LobWrite(clob, const_cast(data.c_str()), data.length());

OCI_Execute(stmt);

 

方法二:

#include "ocilib.h"

#define SIZE_BUF 512

int main(void)
{
OCI_Connection *cn;
OCI_Statement *st;
OCI_Resultset *rs;
OCI_Lob *lob1, *lob2;

char temp[SIZE_BUF+1];
int code, n;

if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT))
return EXIT_FAILURE;

cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);

OCI_ExecuteStmt(st, "select code, content from test_lob for update");

rs = OCI_GetResultset(st);

while (OCI_FetchNext(rs))
{
code = OCI_GetInt(rs, 1);
lob1 = OCI_GetLob(rs, 2);
lob2 = OCI_LobCreate(cn, OCI_CLOB);

n = OCI_LobWrite(lob1, "Today, ", 7);
OCI_LobSeek(lob1, n, OCI_SEEK_SET);

n = OCI_LobWrite(lob2, "I'm going to the cinema !", 25);

OCI_LobAppendLob(lob1, lob2);
OCI_LobSeek(lob1, 0, OCI_SEEK_SET);

n = OCI_LobRead(lob1, temp, SIZE_BUF);
temp
= 0;

printf("code: %i, action : %s\n", code, temp);

OCI_LobFree(lob2);
}

printf("\n%d row(s) fetched\n", OCI_GetRowCount(rs));

OCI_Cleanup();

return EXIT_SUCCESS;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c c++ VC++ mfc oracle