0

我将字符串更新为长度为 35 的列到两个表中

第一个表更新成功,但第二个表给出 ORA 错误 ORA-12899 错误字符串太大

select length('Andres Peñalver D1 Palmar Sani salt') bytes from dual;

     BYTES
----------
        35

select lengthb('Andres Peñalver D1 Palmar Sani salt') bytes from dual;

     BYTES
----------
        36

两个表 colm1 字段都声明为 VARCHAR(35),第一个表更新失败,第二个成功。

update t
set colm1='Andres Peñalver D1 Palmar Sani Salt'
where value1='123456';

update t2
set colm1='Andres Peñalver D1 Palmar Sani Salt'
where value1='123456';

ORA-12899

select value from nls_database_parameters where parameter='NLS_CHARACTERSET';

VALUE                                                           
----------------------------------------------------------------
AL32UTF8

让我知道为什么这些具有相同列类型的表会出现这种行为

4

2 回答 2

0

检查 all_tab_columns 中两个表的实际列大小。35 Char 是 3 乘以 35 字节,如果一个表的列是在 char 中定义的,而另一个是在字节中定义的(在 ddl 期间),则大小是不同的。像 AZ az 这样的普通字符需要 1 个字节来存储,但特定于语言的字符需要 3 个字节来存储。

于 2020-05-09T16:12:20.563 回答
0

错误消息文档中描述的完整错误消息应该会给您答案:

$ oerr ora 12899
12899, 00000, "value too large for column %s (actual: %s, maximum: %s)"
// *Cause: An attempt was made to insert or update a column with a value
//         which is too wide for the width of the destination column.
//         The name of the column is given, along with the actual width
//         of the value, and the maximum allowed width of the column.
//         Note that widths are reported in characters if character length
//         semantics are in effect for the column, otherwise widths are
//         reported in bytes.
// *Action: Examine the SQL statement for correctness.  Check source
//          and destination column data types.
//          Either make the destination column wider, or use a subset
//          of the source column (i.e. use substring).

这可能与字符长度语义有关。

于 2020-05-09T15:32:34.130 回答