作者:人生-顺势而为 | 来源:互联网 | 2014-07-09 16:02
Oracle读写文件文档建立表Java代码CREATETABLEBLOBDATA(www.2cto.comOIDdecimal(22)PRIMARYKEYNOTNULL,DATAblob);建立目录和过程Java代码createorreplacedirectory...Synta
Oracle读写文件文档
建立表
Java代码
CREATE TABLE BLOBDATA
( www.2cto.com
OID decimal(22) PRIMARY KEY NOT NULL,
DATA blob
);
建立目录和过程
Java代码
create or replace directory doc_loc
as '/tmp';
CREATE OR REPLACE PROCEDURE Load_BLOB_From_File (file_name in varchar2,oid in number)
AS
src_loc bfile:= bfilename('DOC_LOC',Load_BLOB_From_File.file_name);
dest_loc BLOB;
begin
insert into blobdata(oid,data) values(Load_BLOB_From_File.oid,empty_blob()) returning data
into dest_loc;
DBMS_LOB.open(src_loc,DBMS_LOB.LOB_READONLY);
DBMS_LOB.LOADFROMFILE( www.2cto.com
dest_lob => dest_loc
,src_lob => src_loc
,amount => DBMS_LOB.getLength(src_loc));
DBMS_LOB.CLOSE(src_loc);
COMMIT;
end;
/
在SQuirrel SQL下执行过程
Java代码
{call LOAD_BLOB_FROM_FILE('test.txt',1190101)}
在PL/SQL下执行过程
exec LOAD_BLOB_FROM_FILE('test.txt',1190101)
www.2cto.com
注意:
1. bfilename
语法:
BFILENAME (‘directory’, ‘file’)
变量:
directory:服务器中的物理目录名,最长只能30个字符
file:服务器中物理文件名
directory有大小写区分,这里尽量用大写