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;
    /
  • 相关阅读:
    构建之法阅读笔记04
    团队项目
    构建之法阅读笔记03
    第6周学习进度
    求最大子数组03
    四则运算4(完结)
    第5周学习进度
    敏捷开发概述
    第4周学习进度
    构建之法阅读笔记01
  • 原文地址:https://www.cnblogs.com/qqjue/p/2612157.html
Copyright © 2011-2022 走看看