Oracle操作大对象CLOB

--创建测试表

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

转载于:https://www.cnblogs.com/wshan/archive/2013/01/23/2873668.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值