您好,我是 Oracle 数据库的新手并测试了一些功能。现在我有问题,而不是触发器。
这是我的代码:
CREATE TABLE team(
teamid integer PRIMARY KEY,
team VARCHAR2(100)
);
CREATE TABLE player(
playerid integer PRIMARY KEY,
player VARCHAR2(100),
position VARCHAR2(100),
teamid integer REFERENCES team(teamid)
);
INSERT ALL
INTO team (teamid, team) VALUES (1, 'FC Bayern Muenchen')
INTO team (teamid, team) VALUES (2, 'Manchester United')
SELECT * FROM DUAL;
INSERT ALL
INTO player (playerid, player, position, teamid) VALUES (1, 'Manuel Neuer', 'goalkeeper', 1)
INTO player (playerid, player, position, teamid) VALUES (2, 'Dante', 'defense', 1)
INTO player (playerid, player, position, teamid) VALUES (3, 'Cesc Fabregas', 'midfield', 2)
INTO player (playerid, player, position, teamid) VALUES (4, 'Lionel Messi', 'striker', 2)
INTO player (playerid, player, position, teamid) VALUES (5, 'Arjen Robben', 'midfield', 1)
SELECT * FROM DUAL;
CREATE VIEW view_player AS
SELECT p.playerid,p.player,p.position, t.team FROM player p
INNER JOIN team t
ON p.teamid = t.teamid;
我得到了两个表的自动增量的序列和触发器。这是我的而不是触发器:
CREATE OR REPLACE TRIGGER view_player_insert
INSTEAD OF INSERT ON view_player
FOR EACH ROW
DECLARE
NUMBER anzTeams;
NUMBER teamID;
BEGIN
SELECT count(*) INTO anzTeams FROM team WHERE team=:NEW.team;
IF anzTeams > 0
THEN
INSERT INTO team(team) VALUES (:NEW.team);
END IF;
SELECT teamid INTO teamID FROM team WHERE team=:NEW.team;
INSERT INTO player(player,position,fbid) VALUES (:NEW.player,:NEW.position,teamID);
END;
我用我的而不是触发器得到了这个异常:
第 12 行中的异常:PL/SQL:SQL 语句被忽略
我想我有一个语法错误,但我不知道是谁。我希望你能帮帮我 :)
Greetz Ulti