Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2088379
  • 博文数量: 1647
  • 博客积分: 80000
  • 博客等级: 元帅
  • 技术积分: 9980
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-13 15:15
文章分类

全部博文(1647)

文章存档

2011年(1)

2008年(1646)

我的朋友

分类:

2008-10-28 17:45:53

SQL> create table t (
  2  name       varchar2(30),
  3  content clob
  4  )
  5  /
Table created.
SQL> 
SQL> 
SQL> create or replace directory dir1 as '/opt/oracle';
Directory created.
SQL> 
SQL> declare
  2          l_bfile bfile;
  3          l_clob  clob;
  4          l_str   varchar2(1000);
  5  begin
  6          insert into t (name,content)
  7          values ('b.txt',empty_clob())
  8          returning content into l_clob;
  9  
 10          l_bfile := bfilename('DIR1','b.txt');
 11  
 12          dbms_lob.fileopen(l_bfile);
 13          dbms_lob.loadfromfile(l_clob,l_bfile,dbms_lob.getlength(l_bfile));
 14          dbms_lob.fileclose(l_bfile);
 15          commit;
 16          exception when others then
 17          l_str:=sqlerrm(sqlcode);
 18          dbms_output.put_line(l_str);
 19  end;
 20  /
PL/SQL procedure successfully completed.
SQL> select * from t;  
NAME                           CONTENT
------------------------------ ----------------------------------------------
b.txt                          ?test
                               Oracle BFile数据加载问题
                               研究
SQL> 
SQL> declare
  2          l_bfile bfile;
  3          l_clob  clob;
  4          l_str   varchar2(1000);
  5  begin
  6          insert into t (name,content)
  7          values ('b.txt',empty_clob())
  8          returning content into l_clob;
  9  
 10          l_bfile := bfilename('DIR1','b.txt');
 11  
 12          dbms_lob.fileopen(l_bfile);
 13          dbms_lob.loadfromfile(l_clob,l_bfile,dbms_lob.getlength(l_bfile)-2,
 14                            src_offset => 3);
 15          dbms_lob.fileclose(l_bfile);
 16          commit;
 17          exception when others then
 18          l_str:=sqlerrm(sqlcode);
 19          dbms_output.put_line(l_str);
 20  end;
 21  /
PL/SQL procedure successfully completed.
SQL> select * from t;
NAME                           CONTENT
------------------------------ --------------------------------------
b.txt                          ?test测试
                               Oracle BFile数据加载问题
                               研究
b.txt                          test测试
                               Oracle BFile数据加载问题
                               研究
            

--------------------next---------------------

阅读(227) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~