结合blob与bfile存贮大二进制对象。 -------------------------------------------------- create or replace directory utllobdir as 'c:\xxx'; create table bfile_tab (bfile_column BFILE); create table xxx (blob_column BLOB);declare a_blob BLOB; a_bfile BFILE := BFILENAME('UTLLOBDIR','xxx'); begin insert into bfile_tab values (a_bfile) returning bfile_column into a_bfile; insert into xxx values (empty_blob()) returning blob_column into a_blob; dbms_lob.fileopen(a_bfile); dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile)); dbms_lob.fileclose(a_bfile); commit; end; /
google一下 结果多的会吓你一大跳 :)
先设置自动提交为false 然后写入数据.empty_blod() 定位该记录 用select * for update进行事务锁定 然后用流写.
stmt.executeUpdate("INSERT INTO TEST_BLOB VALUES ('222', EMPTY_BLOB())");ResultSet rs = stmt.executeQuery("SELECT BLOBCOL FROM TEST_BLOB WHERE ID='222' FOR UPDATE");while (rs.next()) {oracle.sql.BLOB blob = (oracle.sql.BLOB)rs.getBlob("BLOBCOL");BufferedOutputStream out = new BufferedOutputStream(blob.getBinaryOutputStream());BufferedInputStream in = new BufferedInputStream(new FileInputStream(infile));int c;while ((c=in.read())!=-1) {out.write(c); 值得注意的是:好像是不能用DBLink写大对象
--------------------------------------------------
create or replace directory utllobdir as 'c:\xxx';
create table bfile_tab (bfile_column BFILE);
create table xxx (blob_column BLOB);declare
a_blob BLOB;
a_bfile BFILE := BFILENAME('UTLLOBDIR','xxx');
begin
insert into bfile_tab values (a_bfile)
returning bfile_column into a_bfile;
insert into xxx values (empty_blob())
returning blob_column into a_blob;
dbms_lob.fileopen(a_bfile);
dbms_lob.loadfromfile(a_blob, a_bfile, dbms_lob.getlength(a_bfile));
dbms_lob.fileclose(a_bfile);
commit;
end;
/
结果多的会吓你一大跳
:)
然后写入数据.empty_blod()
定位该记录
用select * for update进行事务锁定
然后用流写.
值得注意的是:好像是不能用DBLink写大对象