• 访问LOB


    CLOB用于存放大批量的文本数据,所允许的最大数据长度为4G字节。

    1-建立包含CLOB列的表

    View Code
    SQL> create table lob_example1(
      2  id number(6) primary key,
      3  name varchar2(10),
      4  resume clob);
     
    Table created

    2-初始化CLOB列

    View Code
    SQL> insert into lob_example1 values(1,'王鸣',empty_clob());
     
    1 row inserted
     
    SQL> insert into lob_example1 values(2,'玛丽',empty_clob());
     
    1 row inserted
     
    SQL> commit;
     
    Commit complete

    3-更新CLOB列的数据

    View Code
    SQL> declare
      2  lob_loc clob;
      3  text varchar2(200);
      4  amount int;
      5  offset int;
      6  begin
      7  select resume into lob_loc from lob_example1
      8  where id=&id for update;
      9  offset:=dbms_lob.getlength(lob_loc)+1;
     10  text:='&resume';
     11  amount:=length(text);
     12  dbms_lob.write(lob_loc,amount,offset,text);
     13  commit;
     14  end;
     15  /

    4读取CLOB列的内容

    View Code
    SQL> declare 
      2  lob_loc clob;
      3  buffer varchar2(200);
      4  amount int;
      5  offset int;
      6  begin
      7   select resume into lob_loc from lob_example1
      8  where id=&id;
      9  offset:=6;
     10  amount:=dbms_lob.getlength(lob_loc);
     11  dbms_lob.read(lob_loc,amount,offset,buffer);
     12  dbms_output.put_line(buffer);
     13  end;
     14  /

    5-将文本文件内容写入到CLOB列

    View Code
    SQL> declare
      2  lobloc clob;
      3  fileloc bfile;
      4  amount int;
      5  src_offset int:=1;
      6  dest_offset int:=1;
      7  csid int:=0;
      8  lc int:=0;
      9  warning int;
     10  begin
     11   fileloc:=bfilename('G','玛丽.txt');
     12  dbms_lob.fileopen(fileloc,0);
     13  amount:=dbms_lob.getlength(fileloc);
     14  select resume into lobloc from lob_example1
     15  where id=2 for update;
     16  dbms_lob.loadbclobfromfile(lobloc,fileloc,amount,dest_offset,src_offset,csid,lc,warning);
     17  dbms_lob.fileclose(fileloc);
     18  commit;
     19  end;
     20  /
  • 相关阅读:
    重启宝塔面板后提示-ModuleNotFoundError: No module named 'geventwebsocket'
    浅谈自动化
    【测试基础】App测试要点总结
    记录python上传文件的坑(2)
    使用navicat连接只开放内网ip连接的数据库
    【测试基础】数据库索引
    记录python上传文件的坑(1)
    使用docker-compose安装wordpress
    2-2 远程管理命令-网卡和IP地址的概念
    2-1. 远程管理常用命令-关机和启动
  • 原文地址:https://www.cnblogs.com/canyangfeixue/p/2458544.html
Copyright © 2020-2023  润新知