---
title: "(转)sqlplus中如何插入blob数据?"
author: "mlxia"
date: "2010-09-01T09:39:02Z"
tags: []
categories: ["数据库"]
slug: "sqlplus-blob"
draft: false
lastmod: "2010-09-01T09:39:02Z"
id: 752349
url: "https://mlxia.iteye.com/blog/752349"
---

[http://www.itpub.net/viewthread.php?tid=136741&page=1](http://www.itpub.net/viewthread.php?tid=136741&page=1)

标题: sqlplus中如何插入blob数据?

[]()![离线](http://www.itpub.net/images/itpub/callingoff.gif)[shell](http://www.itpub.net/viewpro.php?uid=31733)   
老会员

![](http://www.itpub.net/avatar/org/31733)

精华贴数 0  
[个人空间](http://space.itpub.net/31733/) 0  
技术积分 1258 (1798)  
社区积分 12 (12467)  
注册日期 2002-12-15  
论坛徽章:3

![会员2006贡献徽章](http://www.itpub.net/medalimgs/medal_31_small.gif) ![授权会员](http://www.itpub.net/medalimgs/medal_14_small.gif) ![ITPUB新首页上线纪念徽章](http://www.itpub.net/medalimgs/home_small.gif)                  

 

[#1](http://www.itpub.net/viewthread.php?tid=136741&page=1 "复制帖子链接到剪贴板")

[使用道具](http://www.itpub.net/magic.php?action=user&pid=801239)  

发表于 2003-6-29 18:04 

[](http://www.itpub.net/misc.php?action=viewratings&tid=136741&pid=801239 "评分 0")

sqlplus中如何插入blob数据?

一个字段是blob型,请问在  
sqlplus中如何插入blob数据?

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\__

请各位老师多指教!

[只看该作者](http://www.itpub.net/viewthread.php?tid=136741&elevator=31733)    [![顶部](http://www.itpub.net/images/itpub/top.gif)](http://www.itpub.net/viewthread.php?tid=136741&page=1)

[]()![离线](http://www.itpub.net/images/itpub/callingoff.gif)[southron](http://www.itpub.net/viewpro.php?uid=30918)   
中级会员

精华贴数 0  
[个人空间](http://space.itpub.net/30918/) 0  
技术积分 676 (3545)  
社区积分 0 (89212)  
注册日期 2002-12-6  
论坛徽章:0

                       

 

[#2](http://www.itpub.net/viewthread.php?tid=136741&page=1 "复制帖子链接到剪贴板")

[使用道具](http://www.itpub.net/magic.php?action=user&pid=801257)  

发表于 2003-6-29 18:37 

[](http://www.itpub.net/misc.php?action=viewratings&tid=136741&pid=801257 "评分 0")

在internal这个用户下给scott用户授权如下：  
SQL&gt;grant create any directory to scott;  
SQL&gt;grant create any library to scott;  
在scott这个用户下执行下述语句：  
SQL&gt;create table bfile\_tab (bfile\_column BFILE);  
SQL&gt;create table utl\_lob\_test (blob\_column BLOB);  
SQL&gt;create or replace directory utllobdir as 'C:\\DDS\\EXTPROC';  
SQL&gt;set serveroutput on  
然后执行下面语句就将C:\\DDS\\EXTPROC目录下的word文件COM.doc存入到utl\_lob\_test   
表中的blob\_column字段中了。  
declare  
  a\_blob  BLOB;  
  a\_bfile BFILE := BFILENAME('UTLLOBDIR','COM.doc'); --用来指向外部操作系统  
文件  
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;  
/  
SQL&gt;show errors  
此时可以使用DBMS\_LOB包的getlength这个procedure来检测是否已经将该word文件存入  
到blob字段中了。如：  
SQL&gt; select dbms\_lob.getlength(blob\_column) from UTL\_LOB\_TEST;  
结果如下：  
DBMS\_LOB.GETLENGTH(BLOB\_COLUMN)  
\-------------------------------  
               83968  
说明该word文件已经存入到blob字段中去了。

\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\__

好好学习，天天向上！