2012-01-11 2 views
0

私は(7A + 5dfAA7D ...)アルファベットと数字のようなデータを持っています。その長さはtwo lack文字より大きくなります。だから、文字列リテラルが長すぎると言うエラーを投げるので、私はupdateを使ってそのclob列を更新できません。sql oracleを使用してバルク・データでCLOB列を更新するにはどうすればよいですか?

値を更新するにはどうすればよいですか?

私を助けてください。

ありがとうございます!

+0

:テーブルの

はTEST_IDの列とTEST_BLOBで、TESTと呼ばれるoverwrsubiting?文字列の置換?追加? – APC

+0

実際には単純な更新クエリを使用して単純に更新する空の列です –

+0

PreparedStatementを使用する必要があります(またはプログラミング言語があなたに提供する同等のもの) –

答えて

0

ファイルのデータをCLOB列に挿入するJavaコードの一部です。そのトリックは、最初にempty_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:[email protected]ost: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 
0

SQL * Loaderを使用してデータをロードできますが、ファイルから実行する必要があります。これは、どのくらいのデータが含まれているかによっては困難な場合もありますが、データを含む順次ファイルを設定するスクリプトを作成する可能性があります。この構成は、この例から派生した

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/[email protected]dbserver.mycompany.com control=control.txt 
sqlldr USER/[email protected] 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 

:あなたがやっているアップデートのどのようなAsk Tom

関連する問題