You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

数据库迁移执行Liquibase时遇ORA-01704字符串过长错误

Fixing ORA-01704 (String Literal Too Long) in Liquibase XML Migrations

Ah, that classic Oracle string length issue biting you when using Liquibase! The problem here is that when you stick a string longer than 4000 characters directly into the value attribute of a <column> tag, Liquibase passes it as a literal string to Oracle, which hits the VARCHAR2 literal limit. Here are three solid ways to fix this:

This bypasses XML parsing limitations and leverages Oracle's native handling of CLOBs via bind parameters—plus it avoids SQL injection risks:

<changeSet id="insert_long_customer_text" author="your_username">
  <sql>
    INSERT INTO ORG_CUSTOMER ("My-Column")
    VALUES (TO_CLOB(?))
    <param value="a very long string that goes on and on and... (way over 4000 chars)" />
  </sql>
</changeSet>

2. Swap value for valueClob in the <column> tag

Liquibase has a dedicated attribute for CLOB values that tells it to handle the string as a large object instead of a regular literal:

<insert tableName="ORG_CUSTOMER">
  <column name="My-Column" valueClob="a very long string...."/>
</insert>

Important: Make sure your target column is actually a CLOB (or NCLOB) type. If it's still a VARCHAR2, Oracle will truncate the data even if Liquibase sends it correctly—so you'll need to alter the column first if needed.

3. Load the long text from an external file

For extra-long strings (think tens of thousands of characters), storing the content in a separate text file keeps your changelog clean and avoids XML parsing headaches:

<insert tableName="ORG_CUSTOMER">
  <column name="My-Column" valueClobFile="./data/long_customer_text.txt"/>
</insert>

The path can be relative to your changelog file or an absolute path—just make sure Liquibase can access the file when running your update command.

Bonus: Adjust your column type if needed

If your My-Column is still a VARCHAR2, you'll need to modify it to CLOB first to hold the long data:

<changeSet id="convert_column_to_clob" author="your_username">
  <modifyDataType tableName="ORG_CUSTOMER" columnName="My-Column" newDataType="CLOB"/>
</changeSet>

Run this changeSet before your insert to avoid truncation issues.

Also, double-check that you're using a recent Oracle JDBC driver (ojdbc8 or newer)—older versions had quirks with CLOB handling that could cause unexpected errors.

内容的提问来源于stack exchange,提问作者Benny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:36:27