如何使用sql oracle使用批量数据更新CLOB列?

如何使用sql oracle使用批量数据更新CLOB列?,oracle,oracle10g,clob,Oracle,Oracle10g,Clob,我有像(7A+5dfAA7D…)字母表和数字这样的数据。其长度大于个字符。因此,我无法使用update更新clob列,因为它会抛出一个错误,指出字符串文字太长 如何更新这些值 请帮帮我 提前谢谢 这里是一些java代码的一部分,它将文件中的数据插入CLOB列。诀窍是首先插入一个空的_clob()值,然后更新记录 try { /* Register the Oracle driver */ DriverManager.registerDriver(n

我有像(7A+5dfAA7D…)字母表和数字这样的数据。其长度大于个字符。因此,我无法使用
update
更新clob列,因为它会抛出一个错误,指出字符串文字太长

如何更新这些值

请帮帮我


提前谢谢

这里是一些java代码的一部分,它将文件中的数据插入CLOB列。诀窍是首先插入一个空的_clob()值,然后更新记录

try {
            /* Register the Oracle driver */
            DriverManager.registerDriver(new OracleDriver());

            /* Establish a connection to the Oracle database. I have used the Oracle Thin driver.
              jdbc:oracle:thin@host:port:sid, "user name", "password" */

            conn = DriverManager.getConnection(connectString, userName, passWord);

            /* Set auto commit to false, it helps to speed up things, by default JDBC's auto commit feature is on.
               This means that each SQL statement is commited as it is executed. */

            conn.setAutoCommit(false);
            stmt = conn.createStatement();

            /* Insert all the data, for the BLOB column we use the function empty_blob(), which creates a locator for the BLOB datatype.
               A locator is an object that ponts to the actual location of the BLOB data in the database. A locator is essential to manipulate BLOB data. */

            query = "INSERT INTO CLOB_TABLE (id,data_clob,bestandsnaam,dt_geplaatst) " +
                    "VALUES(" + ID + ", empty_clob(),\'" + fileName + "\',sysdate)";

            //System.out.println(query);

            stmt.execute(query);

            /* Once the locator has been inserted, we retrieve the locator by executing a SELECT statement 
               with the FOR UPDATE clause to manually lock the row. */

            query = "SELECT DATA_CLOB FROM CLOB_TABLE WHERE ID=\'" + ID + "\' FOR UPDATE";

            //System.out.println(query);
            rs = stmt.executeQuery(query);
            //System.out.println("Select statement uitgevoerd");

            if (rs.next()) {

                /* Once a locator has been retrieved we can use it to insert the binary data into the database. */
                CLOB clob = (CLOB)((OracleResultSet)rs).getClob(1);
                os = clob.getAsciiOutputStream();
                final File f = new File(fileName);
                is = new FileInputStream(f);
                final byte[] buffer = new byte[clob.getBufferSize()];
                int bytesRead = 0;
                while ((bytesRead = is.read(buffer)) != -1) {
                    os.write(buffer, 0, bytesRead);
                }
                clob = null;
                returnValue = 0;
            }


        } catch

可以使用SQL*Loader加载数据,但必须从文件中加载。这可能很困难,也可能不困难,这取决于所涉及的数据量,尽管您可能会编写一个脚本来设置包含数据的顺序文件

对于名为TEST的表,包含TEST_ID和TEST_BLOB列:

Control.dat:

load data
infile data.dat
replace 
into table TEST
Fields terminated by ','
(
  TEST_ID, 
   lob_file FILLER CHAR,
  TEST_CLOB LOBFILE(lob_file) TERMINATED BY EOF
)

data.dat:

1,c:\work\clob1_data.dat
2,c:\work\clob2_data.dat
etc...

C:\Work>sqlldr USER/PASS@dbserver.mycompany.com control=control.txt
sqlldr USER/PASS@dbserver.mycompany.com control=control.txt
SQL*Loader: Release 10.2.0.1.0 - Production on Thu Sep 24 01:20:06 2009
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Commit point reached - logical record count 2

此配置源自此示例:

您正在执行哪种更新:覆盖?字符串替换?追加?实际上它是空列,只需使用简单更新查询进行更新您将需要使用PreparedStatement(或您的编程语言提供的任何等效内容)