--创建有大对象字段的一张表
 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. 小D课堂 - 零基础入门SpringBoot2.X到实战_第6节 SpringBoot拦截器实战和 Servlet3.0自定义Filter、Listener_24、深入SpringBoot过滤器和Servlet配置过滤器

    笔记 1.深入SpringBoot2.x过滤器Filter和使用Servlet3.0配置自定义Filter实战(核心知识)     简介:讲解SpringBoot里面Filter讲解和使用Servle ...

  2. Mac OS 安装 MySQL5.7

    在 macOS 上安装 MySQL 5.7 安装 Homebrew $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubuserconten ...

  3. 008-SpringBoot发布WAR启动报错:Error assembling WAR: webxml attribute is required

    一.Spring Boot发布war包流程: 1.修改web model的pom.xml <packaging>war</packaging> SpringBoot默认发布的都 ...

  4. Linux下Mycat安装配置和使用

    mysql安装下载mysql[百度云]tar -zxvf mysql-5.6.32-linux-glibc2.5-x86_64.tar.gz 解压把mysql文件夹移动到 /usr/local/ 下m ...

  5. 深入理解JVM+G1+GC.pdf (中文版带书签)

    目录 序 VII前言 IX 第1章 JVM & GC基础知识 11.1 引言 21.2 基本术语 31.2.1 Java相关术语 41.2.2 JVM/GC通用术语 241.2.3 G1涉及术 ...

  6. 利用eclipse导入jar包到本地仓库

    如果不也不想用mvn install xxxxxx 后面跟一大堆的东东,可以让eclipse替代完成导入,看下图 File------->Import 大功告成,可见eclipse还没有废掉,至 ...

  7. ibatis 参数 指定类型

    文档: http://ibatis.apache.org/docs/dotnet/datamapper/ch03s04.html <update id="UpdateAccountVi ...

  8. Codeforces-Two Buttons-520problemB(思维题)

    B. Two Buttons Vasya has found a strange device. On the front panel of a device there are: a red but ...

  9. SUPPA 可变剪切分析

      SUPPA是一款通过转录本定量来获取可变剪切定量结果的软件.转录本的定量方式有很多,例如count,FPKM, TPM等,作者建议使用TPM,因为先均一化了基因的长度,然后均一化了测序的深度.同时 ...

  10. (模板)hdoj2544(最短路--bellman-ford算法&&spfa算法)

    题目链接:https://vjudge.net/problem/HDU-2544 题意:给n个点,m条边,求点1到点n的最短路. 思路: 今天学了下bellman_ford,抄抄模板.dijkstra ...