Oracle中将Clob字段转换成字符串

硅谷探秘者 4987 0 0

1.利用dbms_lob.substr()方法可将对应字段转换成字符串如下:

select dbms_lob.substr(content) from NEWS

该方法有个缺点,当content字段长度超过某个值时,会报错。


2.获取Clob对象,在Java中通过对流处理获取字段内容,该方式没有长度限制

select content from NEWS
// 将字CLOB转成STRING类型 
    public String ClobToString(Clob clob) throws SQLException, IOException { 
    	
        String reString = ""; 
        java.io.Reader is = clob.getCharacterStream();// 得到流 
        BufferedReader br = new BufferedReader(is); 
        String s = br.readLine(); 
        StringBuffer sb = new StringBuffer(); 
        while (s != null) {// 执行循环将字符串全部取出付值给StringBuffer由StringBuffer转成STRING 
            sb.append(s); 
            s = br.readLine(); 
        } 
        reString = sb.toString(); 
        return reString; 
    }

接下来的重点是将从数据库获取到的该字段的对象转换成Clob对象,如下:

String content = ClobToString((Clob)obj[1]);

其中我的obj是从数据库获取的字段数组,obj[1]对应该Clob对象



评论区
请写下您的评论...
暂无评论...
猜你喜欢
算法基础 1188 c#对象和jsonusingSystem; usingSystem.Runtime.Serialization.Json; usingSystem.IO; usingSystem.Text
数据库基础 1982 '%from_str%'说明:table_name——表的名field_name——名from_str——需要替to_str——替
official 874 leetcode第344题(简单)原链接:https://leetcode-cn.com/problems/reverse-string/题目描述编写一个函数,其作用是输入的过来。输入
weblog 1763 SelectORD(‘a’)-:973.CONV(N,from_base,to_base)对数n进制,并返回,N是要的数据,from_base是原进制,to_base是目标进制。selectCO
数据库基础 1635 mysql截取函数总结1.截取:left(str,length)mysqlselectleft('example.com',3
数据库基础 1743 mysql截取mysql索引从1开始一、mysql截取函数1、left(str,index)从左边第index开始截取2、right(str,index)从右边第index开始截取3
java序列化储存 2781 序列化和反序列化请参考:http://www.jiajiajia.club/blog/artical/yjw520/161源码下载地址:http://photo.jiajiajia.club/file/blob.rarcontroller层代码:importorg.springframework.beans.factory.annotation.Autowired;importorg.spring
算法基础 949 今天在项目遇到用"|"分割的问题,如果直接使用下面方式,不会按照我们预想的分割:String[]ids="12|13|14".split("|");分割出来是[1,2,|,1,3,|1,4
归档
2018-11  12 2018-12  33 2019-01  28 2019-02  28 2019-03  32 2019-04  27 2019-05  33 2019-06  6 2019-07  12 2019-08  12 2019-09  21 2019-10  8 2019-11  15 2019-12  25 2020-01  9 2020-02  5 2020-03  16 2020-04  4 2020-06  1 2020-07  7 2020-08  13 2020-09  9 2020-10  5 2020-12  3 2021-01  1 2021-02  5 2021-03  7 2021-04  4 2021-05  4 2021-06  1 2021-07  7 2021-08  2 2021-09  8 2021-10  9 2021-11  16 2021-12  14 2022-01  7 2022-05  1 2022-08  3 2022-09  2 2022-10  2 2022-12  5 2023-01  3 2023-02  1 2023-03  4 2023-04  2 2023-06  3 2023-07  4 2023-08  1 2023-10  1 2024-02  1 2024-03  1 2024-04  1
标签
算法基础 linux 前端 c++ 数据结构 框架 数据库 计算机基础 储备知识 java基础 ASM 其他 深入理解java虚拟机 nginx git 消息中间件 搜索 maven redis docker dubbo vue 导入导出 软件使用 idea插件 协议 无聊的知识 jenkins springboot mqtt协议 keepalived minio mysql ensp 网络基础 xxl-job rabbitmq haproxy srs 音视频 webrtc javascript
目录
没有一个冬天不可逾越,没有一个春天不会来临。最慢的步伐不是跬步,而是徘徊,最快的脚步不是冲刺,而是坚持。