In this chapter, UDFs and triggers were discussed. DB2's support for advanced SQL PL logic in UDFs and triggers allows you to encapsulate both simple and complex logic at the database server to simplify application development.
Both scalar UDFs and table UDFs are illustrated by examples. UDFs can be directly used in the SQL statements. Invoking SQL procedures in UDFs enables you to use all DB2 SQL PL features directly or indirectly.
Triggers are an ideal mechanism to facilitate global enforcement of business logic for all applications and users. Examples of BEFORE, AFTER, and INSTEAD OF triggers were illustrated, and the purpose and limitations of using each type were discussed. Both UDFs and SQL procedures can be invoked in the triggers. Similarly, invoking SQL procedures in triggers enables you to use all DB2 SQL PL features directly or indirectly.
You should give extra attention when invoking SQL procedures from UDFs and triggers. The considerations for data access control, transaction control, and read and write conflicts should be carefully reviewed.