確認現有對象
SQL> col fdesc for a
SQL> select fid
fname
fdesc from eygle_blob;
FID FNAME FDESC
ShaoLin
jpg 少林寺
康熙手書
DaoYing
jpg 倒映
創建存儲Directory
SQL> connect / as sysdba
Connected
SQL> create or replace directory BLOBDIR as
D:\oradata\Pic
;
Directory created
SQL>
SQL> grant read
write on directory BLOBDIR to eygle;
Grant succeeded
SQL>
創建存儲過程
SQL> connect eygle/eygle
Connected
SQL>
SQL> CREATE OR REPLACE PROCEDURE eygle_dump_blob (piname varchar
poname varchar
) IS
l_file UTL_FILE
FILE_TYPE;
l_buffer RAW(
);
l_amount BINARY_INTEGER :=
;
l_pos INTEGER :=
;
l_blob BLOB;
l_blob_len INTEGER;
BEGIN
SELECT FPIC
INTO l_blob
FROM eygle_blob
WHERE FNAME = piname;
l_blob_len := DBMS_LOB
GETLENGTH(l_blob);
l_file := UTL_FILE
FOPEN(
BLOBDIR
poname
wb
);
WHILE l_pos < l_blob_len LOOP
DBMS_LOB
READ (l_blob
l_amount
l_pos
l_buffer);
UTL_FILE
PUT_RAW(l_file
l_buffer
TRUE);
l_pos := l_pos + l_amount;
END LOOP;
UTL_FILE
FCLOSE(l_file);
EXCEPTION
WHEN OTHERS THEN
IF UTL_FILE
IS_OPEN(l_file) THEN
UTL_FILE
FCLOSE(l_file);
END IF;
RAISE;
END;
/
Procedure created
取出數據
SQL> host ls
l d:\oradata\Pic
total
rwxrwxrwa
gqgai None
Apr
:
DaoYing
jpg
rwxrwxrwa
gqgai None
Apr
:
ShaoLin
jpg
SQL> exec eygle_dump_blob(
ShaoLin
jpg
jpg
)
PL/SQL procedure successfully completed
SQL> host ls
l d:\oradata\Pic
total
rwxrwxrwa
Administrators SYSTEM
Apr
:
jpg
rwxrwxrwa
gqgai None
Apr
:
DaoYing
jpg
rwxrwxrwa
gqgai None
Apr
:
ShaoLin
jpg
SQL>
SQL> exec eygle_dump_blob(
DaoYing
jpg
jpg
)
PL/SQL procedure successfully completed
SQL> host ls
l d:\oradata\Pic
total
rwxrwxrwa
Administrators SYSTEM
Apr
:
jpg
rwxrwxrwa
Administrators SYSTEM
Apr
:
jpg
rwxrwxrwa
gqgai None
Apr
:
DaoYing
jpg
rwxrwxrwa
gqgai None
Apr
:
ShaoLin
jpg
From:http://tw.wingwit.com/Article/program/Oracle/201311/16690.html