在 Oracle SQL 中创建触发器时出现问题(在线)
Issue happening when creating a trigger in Oracle SQL (Online)
我在 Oracle SQL(在线)中创建触发器时遇到问题。请找出代码的问题。
这些是我的代码。
客户table代码:
CREATE TABLE customers(
cusid INT PRIMARY KEY,
cusnm VARCHAR(10),
cusadd VARCHAR(10)
)
审核table代码:
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
这只是一个缺少分号的问题。
--insert a row into the audit table
INSERT INTO audits(table_name, transaction_name, by_user, transaction_date)
VALUES('customers', tx, USER, SYSDATE);
我在 Oracle SQL(在线)中创建触发器时遇到问题。请找出代码的问题。
这些是我的代码。
客户table代码:
CREATE TABLE customers(
cusid INT PRIMARY KEY,
cusnm VARCHAR(10),
cusadd VARCHAR(10)
)
审核table代码:
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
这只是一个缺少分号的问题。
--insert a row into the audit table
INSERT INTO audits(table_name, transaction_name, by_user, transaction_date)
VALUES('customers', tx, USER, SYSDATE);