Oracle Insert BLOB
來源於:
http://arjudba.blogspot.com/2008/06/how-to-insert-blob-dataimage-video-into.html
How to Insert Blob data(image, video) into oracle BLOB size
In this post it is shown how I can insert Blob data link image video into oracle database and also how I can determine the size of the BLOB data from oracle.
1)Create Directory Where BLOB resides.
create or replace directory temp as '/oradata2';
2)Grant read permission to the user who work with this directory.
grant read on directory temp to arju;
3)Create the Table which holds lob object.
-- the storage table for the image file
CREATE TABLE pdm (
dname VARCHAR2(30), -- directory name
sname VARCHAR2(30), -- subdirectory name
fname VARCHAR2(30), -- file name
iblob BLOB); -- image file
4)Create the procedure that insert BLOB objects.
-- create the procedure to load the file
CREATE OR REPLACE PROCEDURE load_file (
pdname VARCHAR2,
psname VARCHAR2,
pfname VARCHAR2) IS
src_file BFILE;
dst_file BLOB;
lgh_file BINARY_INTEGER;
BEGIN
src_file := bfilename('TEMP', pfname);
-- insert a NULL record to lock
INSERT INTO pdm
(dname, sname, fname, iblob)
VALUES
(pdname, psname, pfname, EMPTY_BLOB())
RETURNING iblob INTO dst_file;
-- lock record
SELECT iblob
INTO dst_file
FROM pdm
WHERE dname = pdname
AND sname = psname
AND fname = pfname
FOR UPDATE;
-- open the file
dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
-- determine length
lgh_file := dbms_lob.getlength(src_file);
-- read the file
dbms_lob.loadfromfile(dst_file, src_file, lgh_file);
-- update the blob field
UPDATE pdm
SET iblob = dst_file
WHERE dname = pdname
AND sname = psname
AND fname = pfname;
-- close file
dbms_lob.fileclose(src_file);
END load_file;
/
5)Execute the Procedure.
SQL> exec load_file('TEMP','This is Image','tritha7.png');
PL/SQL procedure successfully completed.
6) From OS see the BLOB size.
SQL> !ls -l /oradata2/tritha7.png
-rwxr-xr-x 1 oracle oinstall 21150 Jun 9 01:55 /oradata2/tritha7.png
7)From Oracle Determine Blob size.
1 declare
2 a blob;
3 begin
4 select iblob into a from pdm;
5 dbms_output.put_line(dbms_lob.getlength(a));
6* end;
SQL> /
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> /
21150
1)Create Directory Where BLOB resides.
create or replace directory temp as '/oradata2';
2)Grant read permission to the user who work with this directory.
grant read on directory temp to arju;
3)Create the Table which holds lob object.
-- the storage table for the image file
CREATE TABLE pdm (
dname VARCHAR2(30), -- directory name
sname VARCHAR2(30), -- subdirectory name
fname VARCHAR2(30), -- file name
iblob BLOB); -- image file
4)Create the procedure that insert BLOB objects.
-- create the procedure to load the file
CREATE OR REPLACE PROCEDURE load_file (
pdname VARCHAR2,
psname VARCHAR2,
pfname VARCHAR2) IS
src_file BFILE;
dst_file BLOB;
lgh_file BINARY_INTEGER;
BEGIN
src_file := bfilename('TEMP', pfname);
-- insert a NULL record to lock
INSERT INTO pdm
(dname, sname, fname, iblob)
VALUES
(pdname, psname, pfname, EMPTY_BLOB())
RETURNING iblob INTO dst_file;
-- lock record
SELECT iblob
INTO dst_file
FROM pdm
WHERE dname = pdname
AND sname = psname
AND fname = pfname
FOR UPDATE;
-- open the file
dbms_lob.fileopen(src_file, dbms_lob.file_readonly);
-- determine length
lgh_file := dbms_lob.getlength(src_file);
-- read the file
dbms_lob.loadfromfile(dst_file, src_file, lgh_file);
-- update the blob field
UPDATE pdm
SET iblob = dst_file
WHERE dname = pdname
AND sname = psname
AND fname = pfname;
-- close file
dbms_lob.fileclose(src_file);
END load_file;
/
5)Execute the Procedure.
SQL> exec load_file('TEMP','This is Image','tritha7.png');
PL/SQL procedure successfully completed.
6) From OS see the BLOB size.
SQL> !ls -l /oradata2/tritha7.png
-rwxr-xr-x 1 oracle oinstall 21150 Jun 9 01:55 /oradata2/tritha7.png
7)From Oracle Determine Blob size.
1 declare
2 a blob;
3 begin
4 select iblob into a from pdm;
5 dbms_output.put_line(dbms_lob.getlength(a));
6* end;
SQL> /
PL/SQL procedure successfully completed.
SQL> set serverout on
SQL> /
21150
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/16860121/viewspace-717065/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle blob過濾Oracle
- Oracle中的insert/insert all/insert firstOracle
- Oracle Blob 轉換為ClobOracle
- Oracle 的 INSERT ALL和INSERT FIRSTOracle
- Oracle插入Blob資料的方法Oracle
- 關於Oracle的BLOB和CLOBOracle
- ORACLE insert命令解析Oracle
- oracle bulk Insert 比insert 快不是一點啊.Oracle
- Oracle-insert into加日期Oracle
- Oracle Direct-Path InsertOracle
- Oracle帶blob欄位移動表空間Oracle
- Oracle 中LONG RAW BLOB CLOB型別介紹Oracle型別
- 檔案插入 Oracle資料庫 Blob型別Oracle資料庫型別
- lightdb -- merge into insert 相容 OracleOracle
- oracle insert兩個關聯表Oracle
- oracle insert all多表插入的示例Oracle
- oracle-演示tom-insert阻塞Oracle
- Oracle lob載入bfile資料到blob欄位中Oracle
- JDBC複習,oracle的blob,clob的讀寫-zhaiJDBCOracleAI
- Oracle批量插入資料insert all into用法Oracle
- JavaScript Blob 物件JavaScript物件
- 【SQL】Oracle BLOB 批量匯入匯出圖片語句SQLOracle
- Oracle - UTL_FILE包之BLOB匯入和匯出Oracle
- 關於oracle中blob欄位的錄入問題Oracle
- Oracle中Blob欄位的寫入處理(一) (轉)Oracle
- Oracle insert大量資料經驗之談Oracle
- oracle-資料庫- insert 插入語句Oracle資料庫
- Oracle中 Update和insert結合語法Oracle
- oracle insert all 特性-------9i開始Oracle
- Oracle BLOB型別的資料如何檢視和下載?Oracle型別
- Oracle10g Logminer處理BLOB欄位錯誤Oracle
- Oracle資料庫中對BLOB資料的操作問題Oracle資料庫
- Blob type 屬性
- Blob size 屬性
- Mysql BLOB、BLOB與TEXT區別及效能影響、將BLOB型別轉換成VARCHAR型別MySql型別
- [Oracle] Append hint(insert sql) will lead a TM LOCKOracleAPPSQL
- Oracle 使用一條insert語句完成多表插入Oracle
- oracle dblink實現insert語句的同步Oracle