PL/SQL將只讀取/寫入LONG RAW和SQL的第一個32k數據將CONVER將該列作爲RAW,因此只能處理前2000個字節。
您可以使用java直接從DB訪問LONG RAW列,如問題"Get the LENGTH of a LONG RAW"中所示。
這裏有一個小例子,第一個設置:
SQL> CREATE TABLE t (ID NUMBER PRIMARY key, source BLOB, destination LONG RAW);
Table created
SQL> DECLARE
2 l_lob BLOB;
3 BEGIN
4 INSERT INTO t VALUES (1, 'FF', '') RETURNING SOURCE INTO l_lob;
5 FOR i IN 1..10 LOOP
6 dbms_lob.writeappend(l_lob, 4000,
7 utl_raw.overlay('FF', 'FF', 1, 4000, 'FF'));
8 END LOOP;
9 END;
10/
PL/SQL procedure successfully completed
的Java類:
SQL> CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Raw" AS
2 import java.io.*;
3 import java.sql.*;
4 import oracle.jdbc.driver.*;
5
6 public class Raw {
7
8 public static void updateRaw(int pk) throws SQLException,IOException {
9
10 Connection conn = new OracleDriver().defaultConnection();
11
12 PreparedStatement ps = conn.prepareStatement
13 ("SELECT dbms_lob.getlength(source) length, source "
14 + "FROM t WHERE id = ? FOR UPDATE");
15 ps.setInt(1, pk);
16 ResultSet rs = ps.executeQuery();
17
18 rs.next();
19 int len = rs.getInt(1);
20 InputStream source = rs.getBinaryStream(2);
21 byte[] destArray = new byte[len];
22 int byteRead = source.read(destArray);
23 ps = conn.prepareStatement(
24 "UPDATE t SET destination = ? WHERE id = ?");
25 ((OraclePreparedStatement) ps).setRAW(1,
26 new oracle.sql.RAW(destArray));
27 ps.setInt(2, pk);
28 ps.execute();
29 }
30 }
31/
Java created
你可以調用這個過程從PL/SQL:
SQL> CREATE OR REPLACE
2 PROCEDURE update_raw(p_id NUMBER)
3 AS LANGUAGE JAVA NAME 'Raw.updateRaw(int)';
4/
Procedure created
SQL> exec update_raw(1);
PL/SQL procedure successfully completed
['LONG RAW'](http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/datatype.htm#i4146)列最多支持2GB的數據。你爲什麼要從「LOB」到「LONG RAW」,而你應該走另一條路? – NullUserException
我需要這個,因爲我使用的數據庫是非常古老的,我們必須使用這個,除非並且直到LONG RAW被convertrd轉換爲LOB。 –