--创建有大对象字段的一张表
 create table test001
 (
       fname varchar2(50),
       content blob
 )
 
 select * from dba_users;
 
 select * from test001
 
 --(一)..准备插入大对象
 --1. 创建文件存放目录(让Oracle管理,该目录)
 create or replace directory test_dir
        as
 'e:\Pictures';
 
 --2.可以将该目录授权给其他用户访问
 grant read,write on directory test_dir to scott;
 
 --(二).准备将大对象,存放在test001表中
 declare
       tempimg blob;--定义临时变量存放数据
       tempdir bfile := bfilename('TEST_DIR','Azul.jpg');--非常重要:所有数据都是大写存放的
 begin      
       insert into test001 values ('first.jpg',empty_blob()) returning content into tempimg;
       
       --使用内置的包,给tempimg写入数据
       dbms_lob.fileopen(tempdir);--打开指定文件
       dbms_lob.loadfromfile(tempimg,tempdir,dbms_lob.getlength(tempdir));
       dbms_lob.fileclose(tempdir);--关闭文件
       
       dbms_output.put_line('恭喜你,终于成功了!!!');
       
       commit;
 end ;
 
 select * from test001
 
 select * from dba_directories
 
 
 --将Blob对象,写成磁盘文件
 declare
        l_file utl_file.file_type;--定义写入磁盘文件的类型和格式
        l_buffer raw(32767);--定义缓冲区大小
        l_amount binary_integer := 3276; --每次位移个数
        l_pos int :=1;--开始位置
        l_blob blob;--临时数据存放
        l_blob_len int;--总长度
 begin
        select content into l_blob from test001; --将数据库中的数据,存放在blob变量中
        
        --获取blob文件的长度
        l_blob_len := dbms_lob.getlength(l_blob);
        
        --准备写入磁盘文件
        l_file := utl_file.fopen('TEST_DIR','HHAHAHAHAHAHAHAHAAHA.JPG','wb');
        
        --写入数据
        while l_pos<l_blob_len loop       
              dbms_lob.read(l_blob,l_amount,l_pos,l_buffer);             
              utl_file.put_raw(l_file,l_buffer,true);             
              l_pos := l_pos + l_amount;       
        end loop;
               
        utl_file.fclose(l_file);       
        dbms_output.put_line('恭喜,恭喜。。。。文件写成功!');       
 end;
 
 
 /*
 文本大对象的写入和读取(clob)。
 */
 --写入文本文件第一种方式
 declare
       tempimg clob;--定义临时变量存放数据
       tempdir bfile := bfilename('TEST_DIR','DIV3.html');--非常重要:所有数据都是大写存放的
       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 test002 values ('第四个文本文件',empty_clob()) returning content 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
     filecontent clob;
     input_file utl_file.file_type;
     buffer varchar2(2000);
     l_pos int := 1;
     amount int;
 begin
     insert into test002 values ('第二个文本数据',empty_clob()) returning content into filecontent;
     --打开磁盘文件
     input_file := utl_file.fopen('TEST_DIR','DIV3.html','r');
     
     loop                  
          utl_file.get_line(input_file,buffer);
          
          --获取每次读取的长度
          amount:=length(buffer);--每次写入的字符长度
          
          exit when amount<=0;
          
          dbms_lob.write(filecontent,amount,l_pos,buffer);
          
          l_pos:=l_pos+amount;
          
     end loop;
     
     utl_file.fclose(input_file);
     
     dbms_output.put_line('文件写入完毕!');
 
 exception
     when no_data_found then
     dbms_output.put_line('数据已经读取完毕了!');
     utl_file.fclose(input_file);
 end;
 
 
 select * from test002
 
 
 
 
 --读取表中的数据,到文件
 declare
     src clob;
     outfile utl_file.file_type;
     length integer;
     buffer varchar2(8000);
 begin
     select content into src from test002 where fname='第四个文本文件';
     
     length := dbms_lob.getlength(src);
     
     dbms_lob.read(src,length,1,buffer);
     
     --打开磁盘文件
     outfile := utl_file.fopen('TEST_DIR','hahahahhahahahah.html','w',8000);
     
     utl_file.put(outfile,buffer);--写入数据
     
     utl_file.fclose(outfile); --关闭指针
     
     dbms_output.put_line('文件已经写入完毕!');
 end;

ORACLE大对象存储的更多相关文章

  1. JAVA操作ORACLE大对象

    一:操作CLOB  (1)数据库表结构如下:         create table CLOB_TEST      (         ID      VARCHAR2(5) not null,   ...

  2. 【巨杉数据库Sequoiadb】巨杉⼯具系列之一 | ⼤对象存储⼯具sdblobtool

    近期,巨杉数据库正式推出了完整的SequoiaDB 工具包,作为辅助工具,更好地帮助大家使用和运维管理分布式数据库.为此,巨杉技术社区还将持续推出工具系列文章,帮助大家了解巨杉数据库丰富的工具矩阵. ...

  3. oracle对大对象类型操作:blob,clob,nclob

     1.基本介绍 Oracle和plsql都支持lob(large object) 类型,用来存储大数量数据,如图像文件,声音文件等.Oracle 9i realse2支持存储最大为4g的数据,or ...

  4. Oracle LOB 大对象处理

    LOB类型列主要是用来存储大量数据的数据库字段,最大可以存储4G字节的非结构化数据. 一.LOB数据类型分类 1.按存储数据的类型分: ①字符类型:   CLOB:存储大量 单字节 字符数据.   N ...

  5. [转帖]Oracle数据库lob大对象数据类型字段总结,值得收藏

    Oracle数据库lob大对象数据类型字段总结,值得收藏 原创 波波说运维 2019-07-11 00:02:00 https://www.toutiao.com/i67108943269703357 ...

  6. Oracle数据库中的大对象(LOB)数据类型介绍

    一.LOB数据类型的介绍 大对象(LOB)数据类型允许我们保存和操作非结构化和半结构化数据,如文档.图形图像.视频片段.声音文件和XML文件等.DMBS_LOB 包被设计用于操作 LOB 数据类型.从 ...

  7. BLOB:大数据,大对象,在数据库中用来存储超长文本的数据,例如图片等

    将一张图片存储在mysql中,并读取出来(BLOB数据:插入BLOB类型的数据必须使用PreparedStatement,因为插入BLOB类型的数据无法使用字符串拼写): -------------- ...

  8. 使用JDBC处理Oracle大数据

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

  9. 利用jdbc处理oracle大数据---大文件和二进制文件

    一.Oracle中大数据处理 在Oracle中,LOB(Large Object,大型对象)类型的字段现在用得越来越多了.因为这种类型的字段,容量大(最多能容纳4GB的数据),且一个表中可以有多个这种 ...

随机推荐

  1. java-mybaits-014-数据库缓存设计【querycache、mybatis一级缓存、二级缓存】

    一.概述 一般来说,可以在5个方面进行缓存的设计: 1.最底层可以配置的是数据库自带的query cache, 2.mybatis的一级缓存,默认情况下都处于开启状态,只能使用自带的Perpetual ...

  2. C# 子线程与主线程通讯方法一

    最近在项目中要用到子线程运行结束向主线程通知的需求,利用线程上下文来实现线程之间的同步. 子线程结束后调用同步函数,向主线程发送时间字符串,改变主窗体的label标签 label标签改变事件触发处理函 ...

  3. Delphi中进行延时的4种方法

     1.挂起,不占CPUsleep2.不挂起,占cpuprocedure Delay(msecs:integer);varFirstTickCount:longint;beginFirstTickCou ...

  4. 【转】do...while(0)的妙用

    前言 今天无意中看到这个标题,因为好奇就点进去了,不错,又学习啦... 具体内容: 1. do...while(0)消除goto语句: 2 宏定义中的do...while(0): 参考 1. 原链接_ ...

  5. ng2中 如何使用自定义属性data-id 以及赋值和取值操作

    项目环境:ng4.x 写法说明: [attr.data-nurseKey] <div [attr.data-nurseKey]="k.nurseKey"></di ...

  6. .mmap文件如何打开

    .mmap是一种思维导图文件的后缀,可以用Xmind软件打开.

  7. 虚拟机中Linux环境下使用Squid部署代理缓存服务(及透明传输)

    小知识: 正确的使用Squid服务程序部署代理缓存服务可以有效提升访问静态资源的效率,降低原服务器的负载. 不仅如此,还为读者们添加了对指定IP地址.网页关键词.网址与文件后缀的ACL访问限制功能的实 ...

  8. Vmware player--打开vmdk; 导出系统;

    https://www.cnblogs.com/wxdblog/p/7091496.html 用vmware player打开已经存在的VMDK的方法: https://jingyan.baidu.c ...

  9. es操作手册

    0 _search查询数据时可以指定多个index和type GET /index1,index2/type1,type2/_search GET /_all/type1/_search 相当于查询全 ...

  10. nlp算法

    人工智能算法大体上来说可以分类两类:基于统计的机器学习算法(Machine Learning)和深度学习算法(Deep Learning) 总的来说,在sklearn中机器学习算法大概的分类如下: 1 ...