在表t的content字段中,存放了一个大文本,现在要将其读出,我用的语句是:
select id,dbms_lob(content) from t where id=4;
错误显示:
 PL/SQL: 数字或值错误 : 字符串缓冲区太小
为什么?

解决方案 »

  1.   

    SQL> create table a(a clob);SQL> insert into a values('1234');SQL> insert into a values('5648');SQL> select *from a; 12345648 SQL> select * from a where a like '%12%';select * from a where a like '%12%'                      *ERROR 位于第 1 行:ORA-00932: 数据类型不一致 SQL> SELECT * FROM A WHERE dbms_lob.instr(a.a,'12',1,1)>0; 1234 SQL> SELECT * FROM A WHERE dbms_lob.instr(a.a,'5',1,1)>0; 5648
      

  2.   

    //先建立表 lob_example1
    create table lob_example1(
    id number(6) primary key,
    name varchar2(10),
    resume clob
    );//插入数据
    insert into lob_example1 values(1,'猪',empty_clob());
    insert into lob_example1 values(2,'狗',empty_clob());
    commit;//创建目录
    CREATE OR REPLACE DIRECTORY DOCS AS 'C:\';//创建将文件内容写入数据库CLOB的存储过程
    CREATE OR REPLACE PROCEDURE update_doc(
       t_id  number,
       filename varchar2 
       )
    as
       lobloc clob;
       fileloc bfile;
       amount int;
       src_offset int:=1;
       dest_offset int:=1;
       csid int:=0;
       lc  int:=0;
       warning int;
    begin
       fileloc:=bfilename('DOCS',filename);
       dbms_lob.fileopen(fileloc,0);
       amount:=dbms_lob.getlength(fileloc);
       select resume into lobloc from lob_example1
         where id=t_id for update;
       dbms_lob.loadclobfromfile(lobloc,fileloc,amount,dest_offset,src_offset,csid,lc,warning);
       dbms_lob.fileclose(fileloc);
       commit;
    end;//调用存储过程,把文件读入数据库CLOB中
    call update_doc(1,'aa.csv');
    call update_doc(2,'bb.csv');//察看id是2和1的行中文件大小
    select length(resume) from lob_example1 where id=2;select length(resume) from lob_example1 where id=1;/////////////////////////////////////////////////////文件已经放入数据库//将文件从数据库clob中读出来
    CREATE OR REPLACE PROCEDURE get_doc(
       t_id  number,
       filename varchar2 
       )
    as
       lobloc clob;
       amount int;
       offset int:=1;
       buffer varchar2(2000);
       handle utl_file.file_type;
    begin
       select resume into lobloc from lob_example1 where id=t_id;
       amount:=dbms_lob.getlength(lobloc);
       dbms_lob.read(lobloc,amount,offset,buffer);
       handle:=utl_file.fopen('DOCS',filename,'w',2000);
       utl_file.put_line(handle,buffer);
       utl_file.fclose(handle);
    end;
    /
     
    //调用这个过程,把文件读出来
    call get_doc(1,'zz.csv');
      

  3.   

    这个字段是不可以用sql语句直接查出来的,需要别的工具才可以