Search code examples
firebirdfirebird-3.0

How to get value from table using Firebird trigger


I want to get a value from the table and compare it with inserted value in the Firebird trigger. Here is my code.

SET TERM ^;

CREATE TRIGGER after_in_systab FOR SYSTEMTAB
ACTIVE AFTER INSERT POSITION 0
AS

declare sys_code integer;
select sys_code from system_table;

BEGIN
    /* enter trigger code here */ 
    if(sys_code == NEW.SYSTEM_CODE) then
    insert into logs(log_detail)values('code matched');
    end
    
END^

SET TERM;^

Solution

  • You need to use the INTO clause:

    CREATE TRIGGER after_in_systab FOR SYSTEMTAB
    ACTIVE AFTER INSERT POSITION 0
    AS
      declare sys_code integer;
    BEGIN
      select sys_code from system_table into sys_code;
      if(sys_code == NEW.SYSTEM_CODE) then
      begin
        insert into logs(log_detail)values('code matched');
      end
    END