oracle10g与11g中的一个函数wmsys.wm_concat 的不同返回值

wmsys.wm_concat的作用是将多行合并为一行,如一个人买了3只股票A,B,C 正常我们会记录成三条数据,现在要以一条数据显示该人的股票,这是wmsys.wm_concat方法就有用了.
但是,在10G中该方法返回值可直接转为String后使用,但是在11G中却是Clob类型,我们必须将clob转为String 或其他类型后才可以使用


/**
     * 将CLOB转成String ,静态方法
     * @param clob 字段
     * @return 内容字串,如果出现错误,返回null
     */
    public final static String clob2String(Clob clob){
      if (clob == null){
        return null;
      }
      StringBuffer sb = new StringBuffer(65535);//64K
      Reader clobStream = null;//创建一个输入流对象
      try{
        clobStream = clob.getCharacterStream();
        char[] b = new char[60000];//每次获取60K
        int i = 0;
        while((i = clobStream.read(b)) != -1){
          sb.append(b,0,i);
        }
      }
      catch(Exception ex){
        sb = null;
      }
      finally{
        try{
          if (clobStream != null)
            clobStream.close();
        }
        catch (Exception e) {
        }
      }
      if (sb == null)
        return null;
      else
        return sb.toString();
    }

猜你喜欢

转载自ycscsjj-126-com.iteye.com/blog/1679032