aspMedlem sedan aug. 2002747 inlägg
Hej igen,
create trigger TeamCheck
before insert on Teams
referencing new as newRow
for each row
begin
if ((select sum(scored) from Players where teamId = :newRow.playerId) > 0) then
-- Actions...
end if;
end;
Ger felmeddelandet:
Warning: Trigger created with compilation errors.
Det är select-satsen som krånglar till det, om jag i if-satsen skriver 0 > 0 så skapas triggern utan "compilation errors".
Kan tilläggas att jag använder Oracle.
LarsGMedlem sedan dec. 200012 465 inlägg
Vad får du ut om du skriver
sql>show errors trigger TeamCheck;
?
aspMedlem sedan aug. 2002747 inlägg
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identif ier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a strin g literal with character set specification> <a number> <a sing le-quoted SQL string> pipe <en sträng inom alternativa citatte cken med teckenuppsättningsangivelse> <en SQL-sträng
samt
PLS-00103: Encountered the symbol ")" when expecting one of the f ollowing: . , @ ; for <an identifier> <a double-quoted del imited-identifier> group having intersect minus order partitio n start subpartition union where connect SAMPLE_
LarsGMedlem sedan dec. 200012 465 inlägg
Jaha, det verkar vara någon begränsning i Oracle. Ett alternativ är att du tilldelar värdet av select-frågan till en variabel och använder den i din if-sats.
declare a number;
select count(*) into a from ...
if a > 0 then
aspMedlem sedan aug. 2002747 inlägg
Funkar inte heller, jag deklarerar och tilldelar variablen efter begin och innan if-satsen.
PLS-00103: Encountered the symbol "IF" when expecting one of the following: . ( * @ % & - + ; / at for mod remainder rem <a n exponent (**)> and or group having intersect minus order sta rt union where connect || indicator multiset
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: begin function package pragma procedure subtyp e type use <an identifier> <a double-quoted delimited-identifi er> form current cursor The symbol "begin" was substituted for "SELECT" to continue.
aspMedlem sedan aug. 2002747 inlägg
Nu fick jag det att fungera. Jag misstolkade nog var jag skulle placera declare-satserna.
DECLARE
...
BEGIN
SELECT...
IF (...) THEN
END IF
END;