简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM