MyBatis 读取CLOB格式字段 返回Map相关问题

MyBatis 读取clob格式字段 返回Map,get到的数据oracle.sql.CLOB@4f48e956

1.MyBatis查询到clob数据做转换
    select to_char(column) as alias.....
    将clob转为字符串,解决一部分问题
2.接着遇到(ORA-22835:缓冲区对于CLOB到CHAR转换而言太小)问题
    内容数据过长,字符大于4000
3.网上有说截取
    to_char(substr(column,1,4000))  as column;
4.内容超过4000的部分将丢失
5.最终解决方案之
    直接读取clob:  select column from .....
    Clob columnClob = (Clob) map.get("column");
    将Clob转成String
6.Method:ClobToString(Clob clob)

    // Clob类型 转String
    public String ClobToString(Clob clob) throws SQLException, IOException {
        String ret = "";
        Reader read= clob.getCharacterStream();
        BufferedReader br = new BufferedReader(read);
        String s = br.readLine();
        StringBuffer sb = new StringBuffer();
        while (s != null) {
            sb.append(s);
            s = br.readLine();
        }
        ret = sb.toString();
        if(br != null){
            br.close();
        }
        if(read != null){
            read.close();
        }
        return ret;
    }

你可能感兴趣的:(MyBatis 读取CLOB格式字段 返回Map相关问题)