我试图在SQL中执行一个触发器来检查2个不同的表上的值并比较它们是否相等,然后我可以在另一个表中插入一个值。
我有以下代码:
create or replace TRIGGER "CHECK_COMMUNITY"
BEFORE INSERT OR UPDATE ON Supply
FOR EACH ROW
BEGIN
SELECT [Client].*, [Office].* FROM Client INNER JOIN Office ON
[Client].[Community] = [Office].[Community]
WHERE
[Supply].[id_client] = [Client].[id_client]
AND [Suply].[id_office] = [Office].[id_office];
END;
我有3个表,如果客户端和Office表的社区相等,我想在插入后检查Supply。
我把它放在SQl中,但收到了以下错误:
Error ORA-00936: missing expression
在
SELECT [Client].*, [Office].* FROM Client INNER JOIN Office ON
由于
答案 0 :(得分:0)
Triggers以执行以响应以下任何事件:
数据库操作(DML)语句(DELETE,INSERT或UPDATE)。
数据库定义(DDL)语句(CREATE,ALTER或DROP)。
数据库操作(SERVERERROR,LOGON,LOGOFF,STARTUP或SHUTDOWN)。
你的Trigger主体只包含一个select语句,它输出结果但不知道如何处理它。
使用:
create or replace TRIGGER "CHECK_COMMUNITY"
BEFORE INSERT OR UPDATE ON Supply
FOR EACH ROW
BEGIN
Create table <table-name> as
SELECT [Client].*, [Office].* FROM Client INNER JOIN Office ON
[Client].[Community] = [Office].[Community]
WHERE
[Supply].[id_client] = [Client].[id_client]
AND [Suply].[id_office] = [Office].[id_office];
END;
或
create or replace TRIGGER "CHECK_COMMUNITY"
BEFORE INSERT OR UPDATE ON Supply
FOR EACH ROW
BEGIN
insert into table <table-name>
SELECT [Client].*, [Office].* FROM Client INNER JOIN Office ON
[Client].[Community] = [Office].[Community]
WHERE
[Supply].[id_client] = [Client].[id_client]
AND [Suply].[id_office] = [Office].[id_office];
END;
应该运作良好