Preface:
BLOB for storing large amounts of binary data. Such as pictures, music, etc., and then stored into a binary number
CLOB for storing large amounts of text data. Such as HTML pages, etc., varchar2 maximum is 4000, with 4000 expected to exceed Clob
text:
1, I use java + mybatis, String deal directly with it. String can save a maximum 4G
Database: Create a table
-- Create table create table CLOB_TEST ( id VARCHAR2(32) default sys_guid(), content CLOB )
Entity classes:
package com.bf.test.entity; public class ClobTest { private String id; private String content; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } }
Query: sql.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.bf.labor.dao.IClobDao"> <resultMap id="BaseResultMap" type="com.bf.test.entity.ClobTest" > <result column="ID" property="id" jdbcType="VARCHAR" /> <result column="CONTENT" property="content" jdbcType="VARCHAR" /> </resultMap> <select id="getList" resultMap="BaseResultMap"> select * from CLOB_TEST </select> <insert id="insert" > insert into CLOB_TEST (CONTENT) values (#{content}) </insert> </mapper>
Test categories:
package com.test; import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import com.bf.labor.entity.ClobTest; import com.bf.labor.service.ClobService; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration("web") @ContextConfiguration(locations = "file:G:/WIM/Source/webapp/WEB-INF/spring-core-config.xml") public class ClobServiceTest { @Autowired private ClobService clobService; @Test public void test() { List<ClobTest> list = this.clobService.getList(); System.out.println("test=" + list); } @Test public void test2() { String str = ""; for (int i = 0; i < 5000; i++) { str = str + "正"; } System.out.println("str=" + str); ClobTest newInfo = new ClobTest(); newInfo.setContent(str); this.clobService.insert(newInfo); } }
2, Clob field is converted into a string. When the database data migration should pay particular attention to this point, not to deal with the case, Clob field is empty
Method 1: dbms_lob.substr ()
Note: dbms_lob.substr (content), more than 4,000 characters, will complain
Reference blog:
Oracle will convert into a string field Clob - sqyNick - CSDN blog
https://blog.csdn.net/u010670151/article/details/52210333