VARCHAR2 字段中可以存储的字符数是否受字符集影响?

Is the number of characters that can be stored in a VARCHAR2 field influenced by the charset?

在我们客户的数据库中设置了以下字符集:

NLS_CHARACTERSET    AL32UTF8

在我的本地数据库上配置如下:

NLS_CHARACTERSET    AL32UTF8

当对我们客户的数据库执行插入到 VARCHAR2(4000) 列时,会发生此错误:

Caused by: java.sql.SQLException: ORA-01461: can bind a LONG value only for insert into a LONG column

在我的电脑上一切正常。

值是使用 java.sql.PreparedStatementpreparedStatement.setString(3, value3); 绑定的。

会不会是字符集不同导致的错误?字符集是否影响可以存储在 VARCHAR2 字段中的字符数量?

Prior to Oracle 12.1, a VARCHAR2 column is limited to storing 4000 bytes of data in the database character set even if it is declared VARCHAR2(4000 CHAR). Since every character in your string requires 2 bytes of storage in the UTF-8 character set, you won't be able to store more than 2000 characters in the column. Of course, that number will change if some of your characters actually require just 1 byte of storage or if some of them require more than 2 bytes of storage.

另见 this answer