<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Decode360's Blog

    業(yè)精于勤而荒于嬉 QQ:150355677 MSN:decode360@hotmail.com

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 ::  :: 管理 ::
      397 隨筆 :: 33 文章 :: 29 評(píng)論 :: 0 Trackbacks
    在Oracle中存儲(chǔ)Image
    ?
    ??? 學(xué)習(xí)一下如何在Oracle中存儲(chǔ)圖片、影像等大文件。是從Tom那里搬過(guò)來(lái)的代碼,真的是深入淺出啊,能把復(fù)雜的問(wèn)題弄簡(jiǎn)單。好了廢話不多說(shuō)了,直接上代碼。 注意:后面那段是用于直接輸出html代碼在網(wǎng)頁(yè)展現(xiàn)的腳本。
    ?
    ?
    SQL> create table demo
    ? 2? ( id??????? int primary key,
    ? 3??? theBlob?? blob
    ? 4? )
    ? 5? /
    ?
    Table created.
    ?
    ?
    SQL> create or replace directory my_files as 'D:\TEST\Image';
    ?
    Directory created.
    ?
    ?
    SQL> declare
    ? 2????? l_blob??? blob;
    ? 3????? l_bfile?? bfile;
    ? 4? begin
    ? 5????? insert into demo values ( 1, empty_blob() )
    ? 6????? returning theBlob into l_blob;
    ? 7
    ? 8????? l_bfile := bfilename( 'MY_FILES', 'af73.jpg' );
    ? 9????? dbms_lob.fileopen( l_bfile );
    10
    11????? dbms_lob.loadfromfile( l_blob, l_bfile,
    12???????????????????????????? dbms_lob.getlength( l_bfile ) );
    13
    14????? dbms_lob.fileclose( l_bfile );
    15? end;
    16? /
    ?
    PL/SQL procedure successfully completed.
    ?
    --done
    ?
    ?
    ?
    ?

    --Now here is the package that can retrieve the pdf (or anything for that matter.? Just
    --keep adding procedures that are named after the file type like .doc, .pdf, .xls and so
    --on.? Some browsers really want the extension in the URL to be "correct")

    SQL> create or replace package image_get
    ? 2? as
    ? 3????? procedure gif( p_id in demo.id%type );
    ? 4? end;
    ? 5? /
    ?
    Package created.
    ?
    SQL>
    SQL> create or replace package body image_get
    ? 2? as
    ? 3
    ? 4? procedure gif( p_id in demo.id%type )
    ? 5? is
    ? 6????? l_lob?? blob;
    ? 7????? l_amt?? number default 30;
    ? 8????? l_off?? number default 1;
    ? 9????? l_raw?? raw(4096);
    10? begin
    11????? select theBlob into l_lob
    12??????? from demo
    13?????? where id = p_id;
    14?????? -- make sure to change this for your type!
    15????? owa_util.mime_header( 'image/gif' );
    16
    17????????? begin
    18???????????? loop
    19??????????????? dbms_lob.read( l_lob, l_amt, l_off, l_raw );
    20
    21??????????????? -- it is vital to use htp.PRN to avoid
    22??????????????? -- spurious line feeds getting added to your
    23??????????????? -- document
    24??????????????? htp.prn( utl_raw.cast_to_varchar2( l_raw ) );
    25??????????????? l_off := l_off+l_amt;
    26??????????????? l_amt := 4096;
    27???????????? end loop;
    28????????? exception
    29???????????? when no_data_found then
    30??????????????? NULL;
    31????????? end;
    32? end;
    33
    34? end;
    35? /
    ?
    Package body created.
    ?
    ?
    ?
    ??? 注:以上腳本涉及到的系統(tǒng)包有:DBMS_LOB | OWA_UTIL | UTL_RAW | HTP
    ?
    ??????? UTL_RAW might not be installed on your database.? It is part of replication.
    ??????? If you do not have it installed, simply:
    ??????? o cd $ORACLE_HOME/rdbms/admin
    ??????? o find the two files with "raw" in their name (eg: ls *raw*)
    ??????? o using svrmgrl connect as INTERNAL OR SYS -- only these users, no one else can successfully install UTL_RAW
    ??????? o run the .sql and then the .plb file
    ?
    ??? 系統(tǒng)包使用方法可查看《PLSQL Packages and Types Reference》
    ?
    ?
    ?
    ?
    posted on 2009-03-16 21:45 decode360 閱讀(322) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): 06.PLSQL
    主站蜘蛛池模板: 亚洲国产精品无码久久久秋霞1| 久久亚洲国产精品| 亚洲AV日韩精品久久久久久| 美女视频黄频a免费| 国产成人免费a在线视频色戒| 亚洲爆乳无码精品AAA片蜜桃| 麻豆国产人免费人成免费视频 | 亚洲国产另类久久久精品小说| fc2成年免费共享视频网站| 亚洲精品无码激情AV| eeuss影院免费直达入口| 亚洲精品线路一在线观看| 一级片在线免费看| 国产成人精品日本亚洲| 最近免费mv在线电影| 亚洲国产美女在线观看| 天天摸夜夜摸成人免费视频 | 99热免费在线观看| 亚洲国产日韩在线成人蜜芽| 亚洲人成网站免费播放| 亚洲AV无码国产剧情| 亚洲精品国产精品乱码不卞 | 最刺激黄a大片免费网站| 亚洲人成电影在线观看网| 在线观看国产情趣免费视频| 一级做a爰全过程免费视频毛片| 亚洲国产另类久久久精品小说| 亚洲免费视频网址| 老湿机一区午夜精品免费福利 | 亚洲电影在线播放| 国产亚洲精品免费| 在线观看免费视频网站色| 亚洲国产精品成人精品小说 | 最近中文字幕国语免费完整 | 一级毛片正片免费视频手机看| 亚洲av日韩av无码| 国产黄色片在线免费观看| 好久久免费视频高清| 亚洲国产精品嫩草影院| 亚洲永久精品ww47| 好吊妞在线成人免费|