0

When I try try implement the trigger statement, I got the error message "Encountered the symbol "Update"" but I don't what why it happened

CREATE OR REPLACE TRIGGER Trigger1
before DELETE OR UPDATE OR INSERT ON condition
FOR EACH ROW
WHEN (SYSDATE NOT BETWEEN
to_date(to_char(SYSDATE, 'DD.MM.RRRR') || '06:00', 'DD.MM.RRRR HH24:MI' )
AND to_date(to_char(SYSDATE, 'DD.MM.RRRR') || '12:00', 'DD.MM.RRRR-HH24:MI')) BEGIN
RAISE_APPLICATION_ERROR (-20001,
'You can only change my data between 06:00 and 12:00 ! ');
END;

update condition
set name='abc', description='xyz'
where condition_id=1;
Duy Nguyen
  • 15
  • 7
  • 1
    I added the oracle tag, which is a guess based on your use of RAISE_APPLICATION_ERROR. If this is not correct, please fix the tags. Always tag your questions appropriately. This will get you better answers, because people who know a subject will follow the tags, and your question is more likely to be found by the right people if you tag it well. – Bill Karwin Nov 29 '16 at 05:57
  • http://stackoverflow.com/questions/1079949/when-do-i-need-to-use-a-semicolon-vs-a-slash-in-oracle-sql/10207695#10207695 –  Nov 29 '16 at 07:00
  • thanks for adding the tag, I am learaning pl/sql from Oracle but I forgot to include it – Duy Nguyen Nov 29 '16 at 08:02
  • 1
    As a general rule, never omit the error prefix (ORA-... or whatever) when posting questions. – Álvaro González Nov 29 '16 at 08:47
  • 1
    `to_date(to_char(sysdate, 'DD.MM.RRRR') || '06:00', 'DD.MM.RRRR HH24:MI')` can be written as `trunc(sysdate) + 6/24`. – William Robertson Nov 29 '16 at 16:15
  • Shouldn't we add the SQLPLUS tag here ? I don't think other clients have the same requirements – iDevlop Jun 01 '22 at 10:09

2 Answers2

2

PL/SQL code needs to be terminated by a / character within most Oracle development environments (e.g. SQL*Plus or SQL Developer). Since you didn't terminate your CREATE TRIGGER statement, it's interpreting the next update condition ... statement as part of the PL\SQL code when you are executing it, but since it's been placed after the closing END; statement it's invalid.

Adding a / after the closing END; should clear things up for you.

Sentinel
  • 6,379
  • 1
  • 18
  • 23
  • Isn't that a specific requirement for SQLPLUS ? When using other clients they seem less finicky – iDevlop Jun 01 '22 at 10:08
1

Put / at the next line after the trigger decleration

David דודו Markovitz
  • 42,900
  • 6
  • 64
  • 88