【问题标题】:Issue happening when creating a trigger in Oracle SQL (Online)在 Oracle SQL(在线)中创建触发器时发生的问题
【发布时间】:2022-01-11 23:24:43
【问题描述】:

我在 Oracle SQL(在线)中创建触发器时遇到问题。请找出代码的问题。

这些是我的代码。

客户表代码:

CREATE TABLE customers( 
    cusid INT PRIMARY KEY, 
    cusnm VARCHAR(10), 
    cusadd VARCHAR(10) 
)

审核表代码:

CREATE TABLE audits( 
    table_name VARCHAR2(255), 
    transaction_name VARCHAR2(10), 
    by_user VARCHAR2(30), 
    transaction_date DATE 
)

触发码:

CREATE OR REPLACE TRIGGER customers_audit_trg
AFTER
UPDATE OR DELETE
ON customers
FOR EACH ROW

DECLARE
    tx VARCHAR2(10);

BEGIN
    --determine the transaction type
    tx := CASE
        WHEN UPDATING THEN 'UPDATE'
        WHEN DELETING THEN 'DELETE'
    END;
    
    --insert a row into the audit table
    INSERT INTO audits(table_name, transaction_name, by_user, transaction_date)
    VALUES('customers', tx, USER, SYSDATE)
END;
/

错误:

Errors: TRIGGER CUSTOMERS_AUDIT_TRG
Line/Col: 2/8 PLS-00103: Encountered the symbol "=" when expecting one of the following:

   constant exception <an identifier>
   <a double-quoted delimited-identifier> table columns long
   double ref char time timestamp interval date binary national
   character nchar

【问题讨论】:

  • 错误是不同的,在不同的行。请查看db<>fiddle。在插入后添加分号后,不再有错误
  • 如果您的代码有问题,请解释这些问题是什么。我们无法读取您的屏幕,或对此感到介意
  • 发现错误也解决了!感谢您提供链接@astentx。
  • 如果我犯了任何错误,我很抱歉。在@HoneyBadger 提问时我会更加小心。

标签: sql oracle triggers


【解决方案1】:

这只是一个分号丢失的问题。

    --insert a row into the audit table
    INSERT INTO audits(table_name, transaction_name, by_user, transaction_date)
    VALUES('customers', tx, USER, SYSDATE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    • 2012-04-04
    • 2013-12-24
    • 2018-02-07
    相关资源
    最近更新 更多