blob数据读取(一般是图片)

1.确认现有对象
SQL> select fid,fname,fdesc from eygle_blob;
  
  FID FNAME                       FDESC
  
---------- -------------------------------------------------- ------------------------------
  1 ShaoLin.jpg                    少林寺-康熙手书
  
2 DaoYing.jpg                    倒映
  
  
2.创建存储Directory
  
  SQL
> connect / as sysdba
  Connected.
  SQL
> create or replace directory BLOBDIR as 'D:/oradata/Pic';
  Directory created.
  
  SQL> grant read,write on directory BLOBDIR to eygle;
  
Grant succeeded.
  
  
  
3.创建存储过程
SQL> connect eygle/eygle

SQL> CREATE OR REPLACE PROCEDURE eygle_dump_blob (piname varchar2,poname varchar2) IS
  
2  l_file   UTL_FILE.FILE_TYPE;
  
3  l_buffer  RAW(32767);
  
4  l_amount  BINARY_INTEGER := 32767;
  
5  l_pos    INTEGER := 1;
  
6  l_blob   BLOB;
  
7  l_blob_len INTEGER;
  
8 BEGIN
  
9  SELECT FPIC
  
10  INTO   l_blob
  
11  FROM   eygle_blob
  
12  WHERE FNAME = piname;
  
13
  
14  l_blob_len := DBMS_LOB.GETLENGTH(l_blob);
  
15  l_file := UTL_FILE.FOPEN('BLOBDIR',poname,'wb', 32767);
  
16
  
17  WHILE l_pos < l_blob_len LOOP
  
18   DBMS_LOB.READ (l_blob, l_amount, l_pos, l_buffer);
  
19   UTL_FILE.PUT_RAW(l_file, l_buffer, TRUE);
  
20   l_pos := l_pos + l_amount;
  
21  END LOOP;
  
22
  
23  UTL_FILE.FCLOSE(l_file);
  
24
  
25 EXCEPTION
  
26  WHEN OTHERS THEN
  
27   IF UTL_FILE.IS_OPEN(l_file) THEN
  
28    UTL_FILE.FCLOSE(l_file);
  
29   END IF;
  
30   RAISE;
  
31 END;
  
32 /
4.取出数据  
  SQL
> exec eygle_dump_blob('ShaoLin.jpg','01.jpg')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值