user6300260
user6300260

Reputation:

SQL I don't understand what is wrong with my trigger

I'm having a hard time understanding this error:

Error at line 3: PLS-00103: Encountered the symbol "&" when expecting one of the following:

) , * & - + / at mod remainder rem and or as || multiset

  1. CREATE OR REPLACE TRIGGER class_trigger
  2. BEFORE INSERT ON Class FOR EACH ROW
  3. BEGIN
  4. IF (type = 'vl' && mass < 15000) THEN
  5. mass := 15000;

The code is:

CREATE OR REPLACE TRIGGER class_trigger
BEFORE INSERT ON Class FOR EACH ROW
BEGIN

  IF (type = 'vl' && mass < 15000) THEN
  mass := 15000;
  END IF;

END;

What is wrong with my code? I'm using Oracle's APEX. Thanks.

Upvotes: 2

Views: 110

Answers (1)

You have two problems:

  1. PL/SQL uses AND as the logical operator for the boolean AND operation, not &&.

  2. When accessing fields which are passed to the trigger, you must qualify them with the :OLD or :NEW pseudo-row names.

Thus, you'd need to rewrite your trigger as:

CREATE OR REPLACE TRIGGER class_trigger
  BEFORE INSERT ON Class
  FOR EACH ROW
BEGIN
  IF :NEW.TYPE = 'vl' AND
     :NEW.mass < 15000
  THEN
    :NEW.MASS := 15000;
  END IF;
END class_trigger;

Upvotes: 6

Related Questions