【问题标题】:How to write update query for long string in Oracle using jdbc?如何使用 jdbc 在 Oracle 中编写长字符串的更新查询?
【发布时间】:2017-01-17 08:43:10
【问题描述】:

我有一个问题

String sqlQuery = 'update t1 set col1 = ? where colId = ?';

表结构:

t1 table
--------------
colId   |col1
--------|------
Integer |Clob
-------------

col1 - 值可以超过 4000 个字符。 因此,当我执行查询时,出现以下错误:

SQL 错误:ORA-01704:字符串文字太长 01704. 00000 - “字符串文字太长”

如何编写 sql 更新查询。我不想要存储过程?谁能帮帮我。

【问题讨论】:

    标签: java sql oracle


    【解决方案1】:

    Clob 最多可以有 2,147,483,647 个字符,因此在您的情况下应该足够了,以防止此问题,而不是将值作为 String 文字提供,该文字仅限于 4,000 字符长您已经注意到,将其作为 nAscii 流或Clob 提供,这分别归功于setAsciiStream 方法之一或PreparedStatement 类的setClob(int parameterIndex, Reader reader) 方法。

    这是一个具体的例子:

    PreparedStatement ps = ...
    
    // - set the value of the input parameter to the input Reader
    ps.setClob(1, new StringReader(myStringContent));
    // Or setAsciiStream(1, fis);
    ps.setInt(2, id);
    ps.execute();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-19
      相关资源
      最近更新 更多