clob字段超过4000转String类型

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

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

提供一个通用工具类:

 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

希望对大家有所帮助!

原文地址:https://www.cnblogs.com/lq147760524/p/9516223.html