Example: Invoking an SQL UDF in a Trigger Definition - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

This example invokes the SQL UDF common_value_expression from the WHEN clause of the definition of the row trigger trig_insert_after_update.

     CREATE TRIGGER trig_insert_after_update
       AFTER UPDATE OF b1 ON t1
       REFERENCING OLD AS OldRow NEW AS NewRow
     FOR EACH ROW
       WHEN (test.common_value_expression(OldRow.a1, NewRow.b1) >.10)
       INSERT INTO t2
       VALUES (NewRow.a1, NewRow.b1, NewRow.c1);

The next example invokes the SQL UDF common_value_expression in the triggered statement of the row trigger trig_insert.

     CREATE TRIGGER trig_insert 
       AFTER INSERT ON t1
       REFERENCING NEW AS n
     FOR EACH ROW (
       INSERT INTO t2 
       VALUES (n.a1, test.common_value_expression(n.b2, 1), n.c1); );