ITPub博客

首页 > Linux操作系统 > Linux操作系统 > Oracle lob加载bfile数据到blob字段中

Oracle lob加载bfile数据到blob字段中

原创 Linux操作系统 作者:尛样儿 时间:2010-05-23 16:12:55 0 删除 编辑

DBMS_LOB.LOADBLOBFROMFILE(从BFILE加载内容到BLOB)
[oracle@blliu ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.5.0 - Production on Sun May 23 16:01:58 2010

Copyright (c) 1982, 2010, Oracle.  All Rights Reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> host;
[oracle@blliu ~]$ pwd
/home/oracle
[oracle@blliu ~]$ ls bg.jpg
bg.jpg
[oracle@blliu ~]$ exit
exit

SQL> create directory test_dir as '/home/oracle';

Directory created.

SQL> create table test (id number,img bfile);

Table created.

SQL> insert into test values (111,bfilename('TEST_DIR','bg.jpg'));

1 row created.

SQL> commit;

Commit complete.

SQL> create table test2 (id number ,img blob);

Table created.

SQL> insert into test2 values (111,empty_blob());

1 row created.

SQL> commit;

Commit complete.

SQL> declare
  2  dl test2.img%type;
  3  sb test.img%type;
  4  do number:= 1;
  5  so number:= 1;
  6  begin
  7  select img into dl from test2 where id=111 for update;
  8  select img into sb from test where id=111;
  9  dbms_lob.fileopen(
 10  file_loc=>sb,
 11  open_mode=>dbms_lob.FILE_READONLY);
 12  dbms_lob.loadblobfromfile(
 13  dest_lob=>dl,
 14  src_bfile=>sb,
 15  amount=>dbms_lob.lobmaxsize,
 16  dest_offset=>do,
 17  src_offset=>so
 18  );
 19  dbms_lob.close(file_loc=>sb);
 20  end;
 21  /

PL/SQL procedure successfully completed.

SQL> select dbms_lob.getlength(img) from test;

DBMS_LOB.GETLENGTH(IMG)
-----------------------
                   6618

SQL> select dbms_lob.getlength(img) from test2;

DBMS_LOB.GETLENGTH(IMG)
-----------------------
                   6618

SQL>

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23135684/viewspace-663457/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Oracle数据库管理员,Oracle数据库系统构架员;2012年7月出版《构建最高可用Oracle数据库系统:Oracle 11gR2 RAC管理、维护与性能优化》一书;Oracle 10g OCM。

注册时间:2010-01-05

  • 博文量
    483
  • 访问量
    5649725