Oracle操作大对象CLOB
2013-11-19 13:11
330 查看
--创建测试表
create table test1 ( tid int primary key, tname varchar2(20), tcontent clob )
create sequence sequ_test1
--插入数据 insert into test1 values (sequ_test1.nextval,'第一个文件','heheh')
--使用系统内部的文件读写函数。
--1. 创建一个Oracle能够管理的磁盘目录(Oracle系统中存放的系统数据全都都是大写形式)
create or replace directory test_dir as 'e:/' select * from test1
--2.
declare
tempimg clob;--定义临时变量存放数据
tempdir bfile := bfilename('TEST_DIR','a.txt');--非常重要:所有数据都是大写存放的
amount int:=dbms_lob.getlength(tempdir);
src_offset int:=1;
dest_offset int:=1;
csid int:=0;
lc int:=0;
warning int; begin
insert into test1 values (sequ_test1.nextval,'第一个文件信息',empty_clob())
returning tcontent into tempimg; --使用内置的包,给tempimg写入数据
dbms_lob.fileopen(tempdir);--打开指定文件
dbms_lob.loadclobfromfile(tempimg,tempdir,amount,dest_offset,src_offset,csid,lc,warning);
dbms_lob.fileclose(tempdir);--关闭文件
dbms_output.put_line('恭喜你,终于成功了!!!');
commit;
end ;
--读取出来
declare src clob;
outfile utl_file.file_type;
length integer;
buffer varchar2(8000);
begin
select tcontent into src from test1 where tid=1;
length := dbms_lob.getlength(src);
dbms_lob.read(src,length,1,buffer); --打开磁盘文件
outfile := utl_file.fopen('TEST_DIR','hello.sql','w',8000);
utl_file.put(outfile,buffer);--写入数据
utl_file.fclose(outfile); --关闭指针
dbms_output.put_line('文件已经写入完毕!');
end;
select * from test1
create table test1 ( tid int primary key, tname varchar2(20), tcontent clob )
create sequence sequ_test1
--插入数据 insert into test1 values (sequ_test1.nextval,'第一个文件','heheh')
--使用系统内部的文件读写函数。
--1. 创建一个Oracle能够管理的磁盘目录(Oracle系统中存放的系统数据全都都是大写形式)
create or replace directory test_dir as 'e:/' select * from test1
--2.
declare
tempimg clob;--定义临时变量存放数据
tempdir bfile := bfilename('TEST_DIR','a.txt');--非常重要:所有数据都是大写存放的
amount int:=dbms_lob.getlength(tempdir);
src_offset int:=1;
dest_offset int:=1;
csid int:=0;
lc int:=0;
warning int; begin
insert into test1 values (sequ_test1.nextval,'第一个文件信息',empty_clob())
returning tcontent into tempimg; --使用内置的包,给tempimg写入数据
dbms_lob.fileopen(tempdir);--打开指定文件
dbms_lob.loadclobfromfile(tempimg,tempdir,amount,dest_offset,src_offset,csid,lc,warning);
dbms_lob.fileclose(tempdir);--关闭文件
dbms_output.put_line('恭喜你,终于成功了!!!');
commit;
end ;
--读取出来
declare src clob;
outfile utl_file.file_type;
length integer;
buffer varchar2(8000);
begin
select tcontent into src from test1 where tid=1;
length := dbms_lob.getlength(src);
dbms_lob.read(src,length,1,buffer); --打开磁盘文件
outfile := utl_file.fopen('TEST_DIR','hello.sql','w',8000);
utl_file.put(outfile,buffer);--写入数据
utl_file.fclose(outfile); --关闭指针
dbms_output.put_line('文件已经写入完毕!');
end;
select * from test1
相关文章推荐
- JDBC操作Oracle CLOB对象
- oracle对大对象类型操作:blob,clob,nclob,bfile
- 【转】oracle对大对象类型操作:blob,clob,nclob,bfile
- oracle中CLOB对象操作
- 对oracle大对象(Blob,Clob)操作(增,删,改)的C#代码(一)
- oracle对大对象类型操作:blob,clob,nclob,bfile
- HTML数据保存 Oracle CLOB大对象操作
- 对oracle大对象(Blob,Clob)操作(增,删,改)的C#代码(二)
- oracle对大对象类型操作:blob,clob,nclob
- 对oracle大对象(Blob,Clob)操作(增,删,改)的C#代码
- oracle对大对象类型操作:blob,clob,nclob,bfile
- oracle对大对象类型操作:blob,clob,nclob,bfile
- oracle对大对象类型操作:blob,clob,nclob
- 【摘抄】oracle对大对象类型操作:blob,clob,nclob,bfile
- oracle对大对象类型操作:blob,clob,nclob
- oracle对大对象类型操作:blob,clob,nclob
- J2EE操作Oracle的clob类型字段
- JDBC中操作Blob、Clob等对象
- ibatis操作oracle的clob字段和blob字段
- oracle中的大字段clob和blob操作