15.10 - Example: Invoking an SQL UDF Within a Trigger Definition - Teradata Database

Teradata Database SQL Data Definition Language Syntax and Examples

prodname
Teradata Database
vrm_release
15.10
created_date
December 2015
category
Programming Reference
featnum
B035-1144-151K

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); );