欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

clob字段超过4000转String类型

程序员文章站 2022-06-30 20:08:11
上次提到listagg()和wm_concat()方法合并过的字段类型为clob,要是字段长度超过4000,直接使用to_char()方法转会报错。 解决方法可以在java代码中使用流的方式转化成字符串。 提供一个通用工具类: 1 public static String clob2String(C ......

    上次提到listagg()和wm_concat()方法合并过的字段类型为clob,要是字段长度超过4000,直接使用to_char()方法转会报错。

解决方法可以在java代码中使用流的方式转化成字符串。

提供一个通用工具类:

clob字段超过4000转String类型
 1 public static string clob2string(clob clob){
 2         if(null == clob){
 3             return "";
 4         }
 5         reader is = null;
 6         try{
 7             is = clob.getcharacterstream();
 8             bufferedreader br = new bufferedreader(is);
 9             stringbuilder sb = new stringbuilder();
10             string temp = br.readline();
11             while(temp != null){
12                 sb.append(temp);
13                 temp = br.readline();
14             }
15             return sb.tostring();
16         }catch (exception e) {
17             return "clobtostring转换失败";
18         }finally {
19             try{
20                 if(is != null){
21                     is.close();
22                 }
23             }catch (exception e) {
24                 e.printstacktrace();
25             }
26         }
27     }
clob2string

希望对大家有所帮助!