gpt4 book ai didi

sql - Oracle为什么有一个名为timestamp的字段时创建触发器失败?

转载 作者:行者123 更新时间:2023-12-04 16:57:22 25 4
gpt4 key购买 nike

我刚刚浪费了我生命中过去两个小时试图创建一个基于 this tutorial 的自动递增主键的表。 ,本教程很棒我遇到的问题是,如果我有一个时间戳列和一个在同一个表中称为时间戳的表,则创建目标失败...

为什么在我创建表时 oracle 不将此标记为问题?

这是我输入的命令序列:

  • 创建表:
    CREATE TABLE myTable
    (id NUMBER PRIMARY KEY,
    field1 TIMESTAMP(6),
    timeStamp NUMBER,
    );
  • 创建序列:
    CREATE SEQUENCE test_sequence
    START WITH 1
    INCREMENT BY 1;
  • 创建触发器:
    CREATE OR REPLACE TRIGGER test_trigger  
    BEFORE INSERT
    ON myTable
    REFERENCING NEW AS NEW
    FOR EACH ROW
    BEGIN
    SELECT test_sequence.nextval INTO :NEW.ID FROM dual;
    END;
    /

  • 这是我收到的错误消息:
    ORA-06552: PL/SQL: Compilation unit analysis terminated
    ORA-06553: PLS-320: the declaration of the type of this expression is incomplete or malformed

    没有两行带有“时间戳”一词的任何组合都可以正常工作。我原以为语法足以区分关键字和列名。

    正如我所说,我不明白为什么表创建得很好,但是当我尝试创建触发器时,oracle 失败了......

    澄清

    我知道问题在于有一个名为时间戳的列,它可能是也可能不是关键字。我的问题是为什么当我尝试创建触发器而不是当我创建表时它会发出警报,我至少预计会出现警告。

    也就是说,使用 Oracle 几个小时后,它的错误报告似乎不那么冗长,也许只是因为我使用的是 express 版本。

    如果这是 Oracle 中的一个错误,没有支持契约(Contract)的人将如何报告它?我只是在玩快速版本,因为我必须将一些代码从 MySQL 迁移到 Oracle。

    最佳答案

    关于这个 (227615.1) 摘录的关于 metalink 的注释如下:

    # symptom: Creating Trigger fails
    # symptom: Compiling a procedure fails
    # symptom: ORA-06552: PL/SQL: %s
    # symptom: ORA-06553: PLS-%s: %s
    # symptom: PLS-320: the declaration of the type of this expression is incomplete or malformed
    # cause: One of the tables being references was created with a column name that is one of the datatypes (reserved key word). Even though the field is not referenced in the PL/SQL SQL statements, this error will still be produced.

    fix:

    Workaround:

    1. Rename the column to a non-reserved word.
    2. Create a view and alias the column to a different name.

    关于sql - Oracle为什么有一个名为timestamp的字段时创建触发器失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/284653/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com