【问题标题】:ORA-00972 when trying to update field in tableORA-00972 尝试更新表中的字段时
【发布时间】:2020-06-30 06:44:01
【问题描述】:
update t set command="select PIN_ID, PIN_STATUS from inventory where trunc(EXPIRY_DATE) <= trunc(sysdate) and pin_status in ('Delivered','GenHold')" where id='8';

我收到此错误 命令行错误:2 列:32 错误报告 - SQL 错误:ORA-00972:标识符太长 00972. 00000 - “标识符太长” *原因:指定了超过 128 个字节的标识符, 或指定了超过 30 个字节的密码标识符。 *行动:为标识符指定最多 128 个字节, 密码标识符最多 30 个字节。

如何更新这个字段?

【问题讨论】:

  • 请注意,表格有,而不是字段。

标签: sql oracle ora-00972


【解决方案1】:

您的查询中的问题:您使用了double quotes 来表示字符串值。您必须使用单引号来表示 oracle 中的字符串。双引号用于提供别名或对象名称

您的查询中有单引号,因此您需要在字符串中使用两个单引号来表示实际字符串值的单引号,如下所示:

UPDATE T
   SET
    COMMAND = 'select PIN_ID, PIN_STATUS from inventory where trunc(EXPIRY_DATE) <= trunc(sysdate) and pin_status in (''Delivered'',''GenHold'')'
 WHERE ID = '8';

但是有一个简单的选择 (quoted-string)

UPDATE T
   SET
    COMMAND = q'#select PIN_ID, PIN_STATUS from inventory where trunc(EXPIRY_DATE) <= trunc(sysdate) and pin_status in ('Delivered','GenHold')#'
 WHERE ID = '8';

在这里,我使用q'#&lt;your_string&gt;#' 简单地忽略了所有被视为实际字符串结尾的单引号(否则您必须用两个单引号替换字符串中的所有单引号)。它被称为带引号的字符串,它表示为:

q'<delimiter><your_string><delimeter>'

【讨论】:

    【解决方案2】:

    问题在于引号,请使用以下语句,

    update t set command= 'select PIN_ID, PIN_STATUS from inventory where trunc(EXPIRY_DATE) <= trunc(sysdate) and pin_status in (''Delivered'',''GenHold'')' where id='8';
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-27
      • 2012-12-22
      • 2021-04-05
      • 1970-01-01
      • 2020-07-15
      相关资源
      最近更新 更多