php oracle blob写入,oracle blob 的读写 操作

--blob 的读写cbef093dcc044b2793832001e2365e43.pngCREATEORREPLACEPROCEDUREP_IMG_INSERT (v_filenameVARCHAR2)

cbef093dcc044b2793832001e2365e43.pngIScbef093dcc044b2793832001e2365e43.png  v_bfile BFILE;--文件指针cbef093dcc044b2793832001e2365e43.pngv_blob BLOB;

cbef093dcc044b2793832001e2365e43.png  DIR CONSTANTVARCHAR2(20) :='TEST';--文件存放DIRECTORY,区分大小写cbef093dcc044b2793832001e2365e43.pngV_DESTNUMBER:=1;  

cbef093dcc044b2793832001e2365e43.png    V_LANGNUMBER:=1;  

cbef093dcc044b2793832001e2365e43.png

cbef093dcc044b2793832001e2365e43.pngBEGIN2f88ce130b654eb5dc6788e02dbcfc90.png

dbf989d57862681739b642d8621fe1f0.png/**//*通过empty_blob()函数将类型为blob的列初始化为空以便以后填充*/cbef093dcc044b2793832001e2365e43.pngINSERTINTOres_info (res_blob)

cbef093dcc044b2793832001e2365e43.pngVALUES(EMPTY_BLOB ())RETURNres_blobINTOv_blob;

cbef093dcc044b2793832001e2365e43.png

cbef093dcc044b2793832001e2365e43.png  v_bfile:=BFILENAME (DIR, v_filename);

cbef093dcc044b2793832001e2365e43.png 

cbef093dcc044b2793832001e2365e43.pngIF(dbms_lob.fileexists(v_bfile)!=0)THENcbef093dcc044b2793832001e2365e43.png    dbms_lob.fileopen(v_bfile,dbms_lob.file_readonly);--打开目标文件2f88ce130b654eb5dc6788e02dbcfc90.png

dbf989d57862681739b642d8621fe1f0.png/**//*将文件字数据加载到指定的LOB类型变量*/cbef093dcc044b2793832001e2365e43.png    dbms_lob.loadblobfromfile(v_blob,

cbef093dcc044b2793832001e2365e43.png                                                      v_bfile,

cbef093dcc044b2793832001e2365e43.png                                                      dbms_lob.getlength(v_bfile),

cbef093dcc044b2793832001e2365e43.png                                                      V_DEST,

cbef093dcc044b2793832001e2365e43.png                              V_LANG);

cbef093dcc044b2793832001e2365e43.png--dbms_lob.loadblobfromfilecbef093dcc044b2793832001e2365e43.pngdbms_lob.fileclose(v_bfile);--关闭文件cbef093dcc044b2793832001e2365e43.pngCOMMIT;

cbef093dcc044b2793832001e2365e43.png    dbms_output.put_line('已经从'||DIR||'目录中读取了文件'||v_filename||'向表中插入');

cbef093dcc044b2793832001e2365e43.png

cbef093dcc044b2793832001e2365e43.pngELSE--如果文件定位器指向的文件不存在cbef093dcc044b2793832001e2365e43.pngdbms_output.put_line('文件没找到');

cbef093dcc044b2793832001e2365e43.pngENDIF;

cbef093dcc044b2793832001e2365e43.png  EXCEPTIONWHENOTHERSTHENcbef093dcc044b2793832001e2365e43.png  dbms_output.put_line(SQLERRM);

cbef093dcc044b2793832001e2365e43.pngEND;

说明下:

DBMS_LOB.LOADBLOBFROMFILE (

dest_lob IN OUT NOCOPY BLOB,

src_bfile IN BFILE,

amount IN INTEGER,

dest_offset IN OUT INTEGER,

src_offset IN OUT INTEGER);

Parameter

Description

dest_lob

BLOB locator of the target for the load.

src_bfile

BFILE locator of the source for the load.

amount

Number of bytes to load from the BFILE. You can also use DBMS_LOB.LOBMAXSIZE to load until the end of the BFILE.

dest_offset

(IN) Offset in bytbes in the destination BLOB (origin: 1) for the start of the write. (OUT) New offset in bytes in the destination BLOB right after the end of this write, which is also where the next write should begin.

src_offset

(IN) Offset in bytes in the source BFILE (origin: 1) for the start of the read .(OUT) Offset in bytes in the source BFILE right after the end of this read, which is also where the next read should begin.

posted on 2012-07-17 15:54 chen11-1 阅读(1360) 评论(0)  编辑  收藏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值