Oracle如何操作LOB

2021-03-31 08:56:31 字數 3184 閱讀 3563

dbms_lob

create table lob_table (

key_value      integer,

b_lob          blob,

c_lob          clob,

n_lob          nclob,

f_lob          bfile);

insert into a_table values (empty_blob());

insert into lob_table values

(21, null, null, null, bfilename('img', 'image1.gif'));

insert into lob_table values

(22, null, null, null, bfilename('img', 'image2.gif'));

update lob_table set f_lob = bfilename('img', 'image3.gif')

where key_value = 22;

update lob_table

set f_lob = (select f_lob from lob_table where key_value = 22)    

where key_value = 21;

create directory scott_dir as '/usr/home/scott';

maximum number of open bfiles

session_max_open_files=20

insert into lob_table

values (1, null, 'abcd', null, null);

***mit;

declare

num_var           integer;

clob_selected     clob;

clob_updated      clob;

clob_copied       clob;

read_amount       integer;

read_offset       integer;

write_amount      integer;

write_offset      integer;

buffer            varchar2(20);  

begin

select c_lob into clob_selected from lob_table where key_value = 1;

select c_lob into clob_updated from lob_table where key_value = 1 for update;

clob_copied := clob_selected;

read_amount := 10;

read_offset := 1; 

dbms_lob.read(clob_selected, read_amount, read_offset, buffer);

--  dbms_output.put_line('clob_selected value: ' || buffer);

insert into temp values(1,buffer);

read_amount := 10;

dbms_lob.read(clob_copied, read_amount, read_offset, buffer);

--  dbms_output.put_line('clob_copied value: ' || buffer);

insert into temp values(2,buffer);

read_amount := 10;

dbms_lob.read(clob_updated, read_amount, read_offset, buffer);

--  dbms_output.put_line('clob_updated value: ' || buffer);

insert into temp values(3,buffer);

-- at time t4:

write_amount := 3;

write_offset := 5;

buffer := 'efg';

dbms_lob.write(clob_updated, write_amount, write_offset, buffer);

read_amount := 10;

dbms_lob.read(clob_updated, read_amount, read_offset, buffer);

--  dbms_output.put_line('clob_updated value: ' || buffer);

insert into temp values(4,buffer);

read_amount := 10;

dbms_lob.read(clob_selected, read_amount, read_offset, buffer);

--  dbms_output.put_line('clob_selected value: ' || buffer);

insert into temp values(5,buffer);

-- produces the output 'abcd'

read_amount := 10;

dbms_lob.read(clob_copied, read_amount, read_offset, buffer);

--  dbms_output.put_line('clob_copied value: ' || buffer);

insert into temp values(6,buffer);

-- produces the output 'abcd'

end;

/ocilobgetlength()    ocilobwrite()

function empty_blob() return blob;

function empty_clob() return clob;

function bfilename(directory_alias in varchar2,filename in varchar2) return bfile;

oracle 操作lob檔案(舉例Blob)

一.寫入blob 1.先在blob中插入empty blob 2.獲得對剛剛插入記錄的引用 blob blob blob rs.getblob 你的blob欄位名稱 3.寫入 outputstream out blob.getbinaryoutputstream out.write encypwd ...

oracle 操作lob檔案(舉例Blob)

一.寫入blob 1.先在blob中插入empty blob 2.獲得對剛剛插入記錄的引用 blob blob blob rs.getblob 你的blob欄位名稱 3.寫入 outputstream out blob.getbinaryoutputstream out.write encypwd ...

oracle中lob型別的相關操作

在oracle的早期版本中,使用long 和long raw型別存放大資料。從8i版本開始,oracle引入了lob資料型別,並且oracle建議開發人員儘量去使用lob型別而不去使用 long 和long raw定位器 是操作這些值的指標。當我們想讀取或者修改lob資料時,我們必須先要獲取lob ...

Oracle中的LOB欄位解讀

lob欄位是oracle資料庫用於儲存大資料物件的欄位型別,包括blob clob nlob bfile 當lob欄位大小超過4k時,資料庫會單獨為該lob欄位分配額外的blob segments儲存blob物件,儲存在lobsegment中的lob預設不在緩衝區快取,對於lob的讀寫都是物理io,...

ORACLE中LOB欄位的使用和維護

隨著社會的發展,在現代資訊系統的開發中,需要儲存的已不僅僅是簡單的文字資訊,同時還包括一些和音像資料或者是超長的文字。比如開發一套旅遊資訊系統,每一個景點都有豐富的 音像資料和大量的文字介紹。這就要求後臺資料庫要有儲存這些資料的能力。oracle公司在其oracle8i中通過提供lob欄位實現了該功...