Stored Functions in DML Statements
Stored functions may also be called from INSERT, UPDATE, and DELETE statements. While most of the restrictions outlined earlier apply equally to stored functions called from DML statements, there is one major difference: since the parent DML statement is changing the state of the database, stored functions invoked from DML statements do not need to abide by the WNDS restriction. However, such stored functions may not read or modify the same table as the parent DML statement.
Like queries, DML statements may call stored functions where expressions are allowed, including:
The VALUES clause of an INSERT statement.
The SET clause of an UPDATE statement.
The WHERE clause of an INSERT, UPDATE, or DELETE statement.
Any subqueries called from a DML statement may also call stored functions as well under the same set of restrictions as the parent DML statement.
Often, sets of complimentary stored functions are called from both queries and DML statements. For example, we saw earlier how the pkg_util.translate_date function could be called from a query to translate from the Oracle date format stored in the database to the format needed by a Java client. Similarly, the overloaded pkg_util.translate_date function may be used within an update statement to perform the reverse translation, as in:
UPDATE cust_order SET expected_ship_dt = pkg_util.translate_date(:1) WHERE order_nbr = :2;
where :1 and :2 are placeholders for the UTC timedate and order number passed ...