• 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

  • 相关阅读:
    理解HTTP的POST和PUT的区别
    眼见为实 — CSS的overflow属性
    Iconfont的代码使用
    JSP中contentType、pageEncoding和meta charset的区别
    在 webpack 中使用 ECharts
    MVC 中的 ViewModel
    一个简单例子理解C#的协变和逆变
    C#中使用委托、接口、匿名方法、泛型委托实现加减乘除算法
    c#打包文件解压缩
    8种主要排序算法的C#实现 (二)
  • 原文地址:https://www.cnblogs.com/wshan/p/2873668.html
Copyright © 2020-2023  润新知