您好,我是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
答案 0 :(得分:0)
更多评论(无法发表评论,双关语)。
我不知道你可以拥有相同的列和表名。
在声明子句中,变量名和类型的顺序可以是 互换。在最后一个语句中使用teamID更改fbid。用这些 两个变化,触发器编译。我没有在网上得到任何错误 12。