I am having PLS-00103: Encountered the symbol

Solution 1:

Quite a few errors.

  • trigger fires on insert; you don't have to check whether you're inserting (besides, you can't do that as you did)
  • don't compare dates to strings; use date literal or TO_DATE function with appropriate format mask
  • you can't modify :new values in an after trigger; must be before
  • you can't (actually, you shouldn't) end loop in the middle of IF
  • what do you need the loop for, anyway?

When fixed, trigger looks like this and kind of works:

SQL> create or replace trigger a
  2    before insert on upayment
  3    for each row
  4  declare
  5    error_ exception ;
  6    h varchar2(20);
  7    nofound exception ;
  8    cursor y3 is
  9      select payment_date from upayment ;
 10  begin
 11    open y3;
 12    loop
 13      fetch y3 into h;
 14
 15      if y3%notfound then
 16         raise nofound;
 17      else
 18         if :new.payment_date >= date '2022-01-01' then
 19            :new.amount := :new.amount * 1.5;
 20         end if;
 21      end if;
 22    end loop;
 23    close y3;
 24
 25  exception when nofound then
 26    dbms_output.put_line('ERROR');
 27  end;
 28  /

Trigger created.

SQL> desc upayment
 Name                                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 PAYMENT_DATE                                       DATE
 AMOUNT                                             NUMBER

SQL> insert into upayment (payment_date, amount) values (sysdate, 100);
ERROR

1 row created.

SQL>

Though, I guess that you could simplify it (remove cursor, loop, user-defined exception, ... what not) to

SQL> create or replace trigger a
  2    before insert on upayment
  3    for each row
  4  begin
  5    if :new.payment_date >= date '2022-01-01' then
  6       :new.amount := :new.amount * 1.5;
  7    end if;
  8  end;
  9  /

Trigger created.

SQL> insert into upayment (payment_date, amount) values (sysdate, 500);

1 row created.

SQL> select * from upayment;

PAYMENT_DATE            AMOUNT
------------------- ----------
19.01.2022 22:28:03        150
19.01.2022 22:32:57        750

SQL>