Here's a little java client utility that I use for 8.1.7. Look at the usage
string. query_file should contain a query that returns a single lob locator. By
default it reads from Oracle and writes to lob_file. Pass -write to read from
lob_file and write to Oracle. By default it assumes a clob, pass -blob for
binary data.
public long writeClobToFile(Clob clob)
throws IOException, SQLException {
long wrote = 0;
BufferedWriter fwriter = new BufferedWriter(new FileWriter(outFile));
wrote = readFromClob(clob, fwriter);
fwriter.close();
conn.commit();
conn.close();
return wrote;
}
public long writeBlobToFile(Blob blob)
throws IOException, SQLException {
long wrote = 0;
OutputStream fwriter = new FileOutputStream(outFile);
wrote = readFromBlob(blob, fwriter);
fwriter.close();
conn.commit();
conn.close();
return wrote;
}
dbms_lob没有这个功能
如果时9i用utl_file包将数据写入文件。
以前的版本只能用其它语言的程序了。
:(
Prior to Oracle9iR2 you will need to use Java, C, VB, some 3gl language.
In 9iR2 -- PLSQL can write binary files using UTL_FILE.
In 9iR1 and before, you will need to use Java or some other 3gl that has the
ability to do this.
If you have my book "Expert one on one Oracle" -- i do have an example in there
in Pro*C that writes BLOBs to files in an external procedure -- so it works like
a stored procedure call.
找到一个如何往数据库里面写的
grant create any directory to scott;
grant create any library to scott;
create or replace directory utllobdir as 'G:\oracle';
create table bfile_tab (bfile_column BFILE);
create table utl_lob_test (blob_column BLOB);
set serveroutput on
然后执行下面语句就将G:\oracle目录下的Azul.jpg存入到utl_lob_test
表中的blob_column字段中了。
declare
a_blob BLOB;
a_bfile BFILE := BFILENAME('UTLLOBDIR','Azul.jpg');
begin
insert into bfile_tab values (a_bfile)
returning bfile_column into a_bfile;
insert into utl_lob_test 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;
/
select dbms_lob.getlength(blob_column) from UTL_LOB_TEST;