一、區(qū)別和定義
LONG: 可變長的字符串數(shù)據(jù),最長2G,LONG具有VARCHAR2列的特性,可以存儲長文本一個表中最多一個LONG列
LONG RAW: 可變長二進制數(shù)據(jù),最長2G
CLOB: 字符大對象Clob 用來存儲單字節(jié)的字符數(shù)據(jù)
NCLOB: 用來存儲多字節(jié)的字符數(shù)據(jù)
BLOB: 用于存儲二進制數(shù)據(jù)
BFILE: 存儲在文件中的二進制數(shù)據(jù),這個文件中的數(shù)據(jù)只能被只讀訪。但該文件不包含在數(shù)據(jù)庫內(nèi)。
bfile字段實際的文件存儲在文件系統(tǒng)中,字段中存儲的是文件定位指針.bfile對oracle來說是只讀的,也不參與事務(wù)性控制和數(shù)據(jù)恢復(fù).
CLOB,NCLOB,BLOB都是內(nèi)部的LOB(Large Object)類型,最長4G,沒有LONG只能有一列的限制
要保存圖片、文本文件、Word文件各自最好用哪種數(shù)據(jù)類型?
--BLOB最好,LONG RAW也不錯,但Long是oracle將要廢棄的類型,因此建議用BLOB。
二、操作
1、 get
CLOB
java 代碼
-
- Connection con = ConnectionFactory.getConnection();
- con.setAutoCommit(false);
- Statement st = con.createStatement();
-
- ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1");
- if (rs.next())
- {
- java.sql.Clob clob = rs.getClob("CLOBATTR");
- Reader inStream = clob.getCharacterStream();
- char[] c = new char[(int) clob.length()];
- inStream.read(c);
-
- data = new String(c);
- inStream.close();
- }
- inStream.close();
- con.commit();
- con.close();
-
BLOB
java 代碼
-
- Connection con = ConnectionFactory.getConnection();
- con.setAutoCommit(false);
- Statement st = con.createStatement();
-
- ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1");
- if (rs.next())
- {
- java.sql.Blob blob = rs.getBlob("BLOBATTR");
- InputStream inStream = blob.getBinaryStream();
-
- data = new byte[input.available()];
- inStream.read(data);
- inStream.close();
- }
- inStream.close();
- con.commit();
- con.close();
2、 put
CLOB
java 代碼
-
- Connection con = ConnectionFactory.getConnection();
- con.setAutoCommit(false);
- Statement st = con.createStatement();
-
- st.executeUpdate("insert into TESTCLOB (ID, NAME, CLOBATTR) values (1, "thename", empty_clob())");
-
- ResultSet rs = st.executeQuery("select CLOBATTR from TESTCLOB where ID=1 for update");
- if (rs.next())
- {
-
- oracle.sql.CLOB clob = (oracle.sql.CLOB) rs.getClob("CLOBATTR");
- Writer outStream = clob.getCharacterOutputStream();
-
- char[] c = data.toCharArray();
- outStream.write(c, 0, c.length);
- }
- outStream.flush();
- outStream.close();
- con.commit();
- con.close();
-
BLOB
java 代碼
-
- Connection con = ConnectionFactory.getConnection();
- con.setAutoCommit(false);
- Statement st = con.createStatement();
-
- st.executeUpdate("insert into TESTBLOB (ID, NAME, BLOBATTR) values (1, "thename", empty_blob())");
-
- ResultSet rs = st.executeQuery("select BLOBATTR from TESTBLOB where ID=1 for update");
- if (rs.next())
- {
-
- oracle.sql.BLOB blob = (oracle.sql.BLOB) rs.getBlob("BLOBATTR");
- OutputStream outStream = blob.getBinaryOutputStream();
-
- outStream.write(data, 0, data.length);
- }
- outStream.flush();
- outStream.close();
- con.commit();
- con.close();
posted on 2010-08-06 14:20
fly 閱讀(906)
評論(0) 編輯 收藏 所屬分類:
數(shù)據(jù)庫學(xué)習(xí)