リスト1 BLOBデータを格納するPL/SQLサンプル

1 set serveroutput on
2 declare
3         v_blob_locater        blob;
4         v_handle              bfile := bfilename('LOB_DATA_PATH','maguro1.jpg');
5         
6         v_amount              pls_integer;
7         v_doffset             pls_integer := 1;
8         v_soffset             pls_integer := 1;
9         
10 begin
11         dbms_lob.fileopen(
12                 v_handle,
13                 dbms_lob.file_readonly
14         );
15
16         v_amount := dbms_lob.getlength(v_handle);
17
18         insert into test_blob_data (
19                 id,
20                 data
21         ) values (
22                 seq_test_blob_data.nextval,
23                 empty_blob()
24         ) returning data into v_blob_locater;
25         
26         dbms_lob.loadblobfromfile(
27                 v_blob_locater,
28                 v_handle,
29                 v_amount,
30                 v_doffset,
31                 v_soffset
32         );
33         dbms_output.put_line (
'書き込まれたサイズ : ' || v_doffset || 'Bytes' );
34         commit;
35         dbms_lob.fileclose(v_handle);
36 end;
37 /