上次提到listagg()和wm_concat()方法合併過的字段類型爲clob,要是字段長度超過4000,直接使用to_char()方法轉會報錯。java
解決方法能夠在java代碼中使用流的方式轉化成字符串。app
提供一個通用工具類:ide
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 }
但願對你們有所幫助!工具