6

根据 文档 CLOB 和 NCLOB 数据类型列,最多可以存储 8 TB 的字符数据。

我有文本,其中包含 100 000 个字符,如何运行这样的查询:

UPDATE my_table SET clob_column = 'text, which contains 100 000 characters' 
WHERE id = 1

?

如果在文本中,字符数最多为 32767,则可以使用 PL/SQL 匿名块:

DECLARE
   myvar VARCHAR2(15000);
BEGIN
    myvar := 'text, which contains 100 000 characters';
    UPDATE my_table SET clob_column = myvar
    WHERE id = 1;
    ....
 END; 

什么是解决方案,其中文本非常大并且包含例如 100 000 个字符?

更新

我正在尝试dbms_lob.append

    create table t1 (c clob);

    declare
      c1 clob;
      c2 clob;
    begin
      c1 := 'abc';
      c2 := 'text, which contains 100 000 characters';
      dbms_lob.append(c1, c2);
      insert into t1 values (c1);
    end;

虽然,也有错误:string literal too long

我做错了什么?

4

3 回答 3

7

You should use the dbms_lob package, the procedure to add some string to the clob is dbms_lob.append.

DBMS_LOB documentation

declare
  c1 clob;
  c2 varchar2(32000);
begin
  c1 := 'abc';
  c2 := 'text, which contains 32 000 characters';
  dbms_lob.append(c1, c2);
  c2 := 'some more text, which contains 32 000 characters';
  dbms_lob.append(c1, c2);
  insert into t1 values (c1);
end;
于 2013-12-16T15:16:46.997 回答
2

我在谷歌搜索如何将数据附加到 CLOB 时发现了这个问题。对于我的特定问题,我正在使用无法使用该dbms_lob包的旧 PL/SQL 系统,因此我认为我会分享我的答案,以便在我的情况下让其他人受益。

解决方案:使用Oracle的CONCAT function in aSELECT query, theCONCAT function works for theCLOB`数据类型。例如(使用@AlenOblak 的示例):

declare
  c1 clob;
  c2 varchar2(32000);
begin
  c1 := 'abc';
  c2 := 'text, which contains 32 000 characters';
  SELECT CONCAT(c1, c2) INTO c1 FROM DUAL;
  c2 := 'some more text, which contains 32 000 characters';
  SELECT CONCAT(c1, c2) INTO c1 FROM DUAL;
  insert into t1 values (c1);
end;

希望有帮助。

于 2017-03-20T21:55:19.927 回答
0

我已经使用 Oracle SQL Developer 中的数据导入功能解决了这种情况:

  1. 使用您的大字符串和其他属性制作 .dsv 文件。
  2. 只需在表格上单击并选择“数据导入”
  3. 选择你的文件
  4. 在 Data Import Wizard Step1 中:选择 rigth Delimeter、Line Terminator、Row Limit、Encloser characters 等。
  5. Step2: Import Method=Insert, Step3: 将文件和表列相互映射
  6. Step4:运行数据导入
于 2019-02-22T15:57:33.657 回答