在.net下用c++写的代码如下:
// testClob.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "oracl.h"
#include <iostream>
#include <fstream>using namespace std;// Example for OClob::Read
int main()
{ //Initialize oo4o, connect, execute sql
OStartup();
ODatabase odb("hjx", "sys", "yellow"); //ODynaset odyn(odb, "SELECT * FROM test"); ODynaset odyn(odb, "SELECTCOLB * FROM test");
if (!odyn.IsOpen())
{
cout <<"Connect Error: "<<odb.GetErrorText()<<endl;
cout <<"SQL Error: "<<odyn.GetErrorText()<<endl;
return 1;
}
OClob oclob;
int a;
odyn.GetFieldValue("count",&a);
cout<<a;
unsigned char *buffer = 0;
if(!oclob.IsNull())
{
cout<<"Clob is not null."<<endl;
} else{ //under the condition that the oclob is null!!!
cout<<"Clob is null."<<endl; const char buf2[] = "Clob is null.";
ofs.write(buf2, sizeof(buf2)); if(oclob.IsOpen())
cout<<"Clob is open.."<<endl;
try //test result that is the oclob is null, any opration is permitted!!!
{
fstream fs;
fs.open("c:\\descout.txt", ios::out);
unsigned long size = oclob.GetSize();
// calculate an optimum buffersize of approximately 32k bytes
unsigned long optchunk = oclob.GetOptimumChunkSize();
unsigned int bufsize = ((int)(32768/optchunk)) *optchunk;
if (bufsize > size)
bufsize = size; buffer = (unsigned char *)malloc(bufsize); //By taking advantage of streaming we get the best performance
//and do not need to allocate a large buffer
short status= OLOB_NEED_DATA;
unsigned long amtread=0;
cout<<"22"; while(status == OLOB_NEED_DATA)
{ amtread = oclob.Read(&status, buffer, bufsize); //added to convert the type char *tebuffer;
tebuffer = (char*)buffer;
cout <<buffer<<endl;
fs.write(tebuffer, amtread);
}
oclob.DisableStreaming();
fs.close();
}
catch(OException E) //there is an exception which throw to the dos platform: clob.getsize() Error:opreation was not permitted on a null lob
{
cout<<"11"<<E.GetFailedMethodName()<< " Error: "<<E.GetErrorText()<<endl;
const char buf3[] = "some failure!";
ofs.write(buf3, sizeof(buf3));
}//catch
}//else
if (buffer)
free(buffer); getchar();
OShutdown();
return 0;
}
// testClob.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "oracl.h"
#include <iostream>
#include <fstream>using namespace std;// Example for OClob::Read
int main()
{ //Initialize oo4o, connect, execute sql
OStartup();
ODatabase odb("hjx", "sys", "yellow"); //ODynaset odyn(odb, "SELECT * FROM test"); ODynaset odyn(odb, "SELECTCOLB * FROM test");
if (!odyn.IsOpen())
{
cout <<"Connect Error: "<<odb.GetErrorText()<<endl;
cout <<"SQL Error: "<<odyn.GetErrorText()<<endl;
return 1;
}
OClob oclob;
int a;
odyn.GetFieldValue("count",&a);
cout<<a;
unsigned char *buffer = 0;
if(!oclob.IsNull())
{
cout<<"Clob is not null."<<endl;
} else{ //under the condition that the oclob is null!!!
cout<<"Clob is null."<<endl; const char buf2[] = "Clob is null.";
ofs.write(buf2, sizeof(buf2)); if(oclob.IsOpen())
cout<<"Clob is open.."<<endl;
try //test result that is the oclob is null, any opration is permitted!!!
{
fstream fs;
fs.open("c:\\descout.txt", ios::out);
unsigned long size = oclob.GetSize();
// calculate an optimum buffersize of approximately 32k bytes
unsigned long optchunk = oclob.GetOptimumChunkSize();
unsigned int bufsize = ((int)(32768/optchunk)) *optchunk;
if (bufsize > size)
bufsize = size; buffer = (unsigned char *)malloc(bufsize); //By taking advantage of streaming we get the best performance
//and do not need to allocate a large buffer
short status= OLOB_NEED_DATA;
unsigned long amtread=0;
cout<<"22"; while(status == OLOB_NEED_DATA)
{ amtread = oclob.Read(&status, buffer, bufsize); //added to convert the type char *tebuffer;
tebuffer = (char*)buffer;
cout <<buffer<<endl;
fs.write(tebuffer, amtread);
}
oclob.DisableStreaming();
fs.close();
}
catch(OException E) //there is an exception which throw to the dos platform: clob.getsize() Error:opreation was not permitted on a null lob
{
cout<<"11"<<E.GetFailedMethodName()<< " Error: "<<E.GetErrorText()<<endl;
const char buf3[] = "some failure!";
ofs.write(buf3, sizeof(buf3));
}//catch
}//else
if (buffer)
free(buffer); getchar();
OShutdown();
return 0;
}
解决方案 »
- 初学orcale 谁知道如何 把excel里的一列 复制到一个表中的一列 用的pL SQL
- 请教一条SQL文
- 数据类型转换出错
- 请问大家在写数据库文档的时候如何描述PROC啊?用什么图?用什么工具?
- oracle xmldb 中文分词
- SQL(ORACLE)中的条件和is not null问题
- 高手们来帮我看看这个关于关联的SQL问题.简单但我却搞不来!救命~~~
- oracle 用户问题
- oracle redolog的切换问题 Thread 1 cannot allocate new log
- dbca相关问题
- 请问在Oracle中的嵌套表有什么用处,怎么定义嵌套表,怎么使用嵌套表
- Oracle 可以实现像SQL Server 的合并复制功能吗?
现在是读不出来,求救!!!