zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    新华字典有多少字
    lisp install
    OCaml Language Sucks
    Erlang, Haskell, OCaml: screw one, marry one, kill one. Which and why?
    Linux获取网页源码的几种方法
    什么是zhcon
    What is plowshare?
    neo4j简单学习
    neo4j 云端部署
    Clojure语言 vs Scala语言
  • 原文地址:https://www.cnblogs.com/wshan/p/2873668.html
Copyright © 2011-2022 走看看