zoukankan      html  css  js  c++  java
  • 载入图片到数据库

    --载入图片到数据库
    declare
        alob        blob;
        afile       bfile;
        amount      int;
        src_offset  int := 1;
        dest_offset int := 1;
    begin
        select photo into alob from photo_tab  for update;
        afile := bfilename('G', 'a.jpg');
        dbms_lob.fileopen(afile, 0);
        amount := dbms_lob.getlength(afile);
        dbms_lob.loadblobfromfile(alob, afile, amount, dest_offset, src_offset);
        dbms_lob.fileclose(afile);
        commit;
    end;
    /
    
    --从数据库读取图片到文件.
    declare
        alob   blob;
        amount   int;
        offset   int := 1;
        totalw   int := 0;
        currentw int;
        buffer   raw(2000);
        f        utl_file.file_type;
    begin
        select photo into alob from photo_tab ;
        amount := dbms_lob.getlength(alob);
        f      := utl_file.fopen('G', 'b.jpg', 'ab', 2000);
        loop
            if ((amount - totalw) >= 2000) then
                currentw := 2000;
            else
                currentw := amount - totalw;
            end if;
            dbms_lob.read(alob, currentw, totalw + 1, buffer);
            utl_file.put_raw(f, buffer);
            totalw := totalw + currentw;
            exit when totalw = amount;
        end loop;
        utl_file.fclose(f);
    end;
    /
  • 相关阅读:
    FreeMarker缓存处理
    freemarker入门实例与源码研究准备工作
    Freemarker常用技巧(二)
    Freemarker常用技巧(一)
    Hessian与Spring整合
    Hessian学习
    数组常见的面试题
    关于排序的实现
    Redis与Memcache的区别
    JDBC编程步骤
  • 原文地址:https://www.cnblogs.com/qqjue/p/2612157.html
Copyright © 2011-2022 走看看