
場景:使用select wm_concat(xxxxx) from table 的時候 返回的字符串過長
解決方案 :使用to_clob 將字符串轉成 clob類型,但是由於使用的前端框架不能解析clob類型的值
再將clob轉化成String類型
List<Map> olists=oDao.queryOrgRoleInfo(query); for(Map omap :olists ){ try { omap.put("ORGNAME", ClobToString((Clob)omap.get("ORGNAME"))); } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
public String ClobToString(Clob clob) throws SQLException, IOException { String reString = ""; if (clob == null){ return ""; } 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; }
