Еhe code is rather incomprehensible for me.
CREATE OR REPLACE TRIGGER ... BEFORE INSERT ON some_table
REFERENCING NEW AS bs
IF ... THEN
...
ELSE
SET beleg_id_neu= next value for BUCHUNGSBELEG_ID_SEQ;
insert into buchungsbeleg values(beleg_id,1,belegnr,bs.buchh_id,null);
SET bs.beleg_id = beleg_id_neu; --This doesn't "compile"
END IF;
Apparently some_table<>buchungsbeleg.
insert into buchungsbeleg values(beleg_id,1,belegnr,bs.buchh_id,null);
What is beleg_id? It bs.beleg_id may be?
Why this sequence of statements?
insert into buchungsbeleg values(beleg_id,1,belegnr,bs.buchh_id,null);
SET bs.beleg_id = beleg_id_neu;
Its seems correct way is
SET bs.beleg_id = beleg_id_neu;
insert into buchungsbeleg values(bs.beleg_id,1,bs.belegnr,bs.buchh_id,null);
and then it transforming into 2 triggers:
CREATE OR REPLACE TRIGGER ... BEFORE INSERT NO CASCADE ON some_table
REFERENCING NEW AS bs
IF ... THEN
...
ELSE
SET bs.beleg_id = next value for BUCHUNGSBELEG_ID_SEQ;
END IF;
CREATE OR REPLACE TRIGGER ... AFTER INSERT ON some_table
REFERENCING NEW AS bs
IF ... THEN
...
ELSE
insert into buchungsbeleg values(bs.beleg_id,1,bs.belegnr,bs.buchh_id,null);
END IF;