【问题标题】:SQL Trigger error (ORA-00942: table or view does not exist)SQL 触发器错误(ORA-00942:表或视图不存在)
【发布时间】:2020-02-25 02:54:42
【问题描述】:

我创建了这个 sql 触发器:

CREATE OR REPLACE TRIGGER create_event_from_task BEFORE INSERT ON llx_projet_task
BEGIN
    INSERT INTO llx_actioncomm (priority, fulldayevent, location, label, fk_element, elementtype, fk_project, datep, datef, percentage, note)
    SELECT 0, 0, '', 'prova', id, 'project_task', fk_project, date_start, date_end, progress, description
    FROM inserted;
END;
/

但是当我执行时说这个错误:

Errors: TRIGGER CREATE_EVENT_FROM_TASK
Line/Col: 2/2 PL/SQL: SQL Statement ignored
Line/Col: 4/7 PL/SQL: ORA-00942: table or view does not exist

谁能帮帮我?

【问题讨论】:

  • 除非您有一个名为inserted 的表,否则Oracle 没有内置表。错误消息似乎很清楚。
  • 您是否检查了名为“inserted”的表与您的触发器在同一架构中?如果存在“插入”表,您可能应该给它一个 grant 以供您的触发器检测。
  • 假设您是 SQL Server 用户(如下所述),请小心使用触发器——Oracle 和 SQL Server 在触发器的行为方式上有着明显不同的机制。

标签: oracle plsql database-trigger


【解决方案1】:

我认为由于触发器内的选择查询而出现此错误。检查调用触发器的用户是否有权从“插入”表中执行选择。

https://www.tekstream.com/resource-center/ora-00942-table-or-view-does-not-exist/

Ora-00942 表示您正在尝试执行引用不存在的表或视图的 SQL 语句。 “表或视图不存在”错误有多种可能的原因,包括:

1) Referencing a table or view that does not exist
2) Using an unauthorized synonym
3) Using an expression of view where a table is required
4) Attempting to use a table without proper permission or privilege

【讨论】:

    【解决方案2】:

    inserted 是 SQL Server 的一部分。我想你想要:

    BEGIN
        INSERT INTO llx_actioncomm (priority, fulldayevent, location, label, fk_element, elementtype, fk_project, datep, datef, percentage, note)
            SELECT 0, 0, '', 'prova', :new.id, 'project_task', 
                   :new.fk_project, :new.date_start, :new.date_end, 
                   :new.progress, :new.description
            FROM dual;
    END;
    

    【讨论】:

    • 或者干脆insert into (...) values (..., :new.fk_project, :new.date_start, ...)
    猜你喜欢
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 2019-01-22
    • 2016-11-05
    相关资源
    最近更新 更多