ITPub博客

首页 > 数据库 > Oracle > clob载入

clob载入

原创 Oracle 作者:dasong2410 时间:2011-10-31 16:41:09 0 删除 编辑
--参考Oracle 9i&10g编程艺术 及 PL/SQL Packages and Types Reference.pdf
--表结构
--drop table t_clob_test;
create table t_clob_test
(
  name    varchar2(100),
  content clob,
  intype  varchar2(10)
);

--test.txt内容
Hi, I am Marcus Mao.
嗨,我是毛大松。

--pl/sql入库clob
create directory marcus_dump_dir as '/home/oracle/marcus_dump_dir';

declare
  l_clob          clob;
  l_bfile         bfile;
  l_dest_offset   number :=1;
  l_src_offset    number :=1;
  l_bfile_csid    number :=0;
  l_lang_context  number :=0;
  l_warning       number :=0;
begin
  insert into t_clob_test (name, content, intype)
  values ('/home/oracle/marcus_dump_dir/test.txt', empty_clob(), 'pl/sql')
  returning content into l_clob;
 
  l_bfile := bfilename('MARCUS_DUMP_DIR', 'test.txt');
  dbms_lob.fileopen(l_bfile);
 
  dbms_lob.loadclobfromfile
  (
    l_clob,
    l_bfile,
    dbms_lob.getlength(l_bfile),
    l_dest_offset,
    l_src_offset,
    l_bfile_csid,
    l_lang_context,
    l_warning
  );
 
  dbms_lob.fileclose(l_bfile);
  commit;
end;
/

--sqlldr入库clob
--sqlldr.ctl内容
infile *
into table t_clob_test
append
fields terminated by ',' optionally enclosed by '"'
trailing nullcols
(
  name,
  content lobfile(name) terminated by EOF,
  intype constant "sqlldr"
)
begindata
/home/oracle/marcus_dump_dir/test.txt

--查看表数据
select name, content, dbms_lob.getlength(content), intype from t_clob_test;

--truncate table t_clob_test;

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

上一篇: shell中特殊符号
请登录后发表评论 登录
全部评论

注册时间:2011-05-12

  • 博文量
    66
  • 访问量
    349769