Functions in Select and Where

Since Oracle 7.1 it is possible to include stored function calls within an SQL-statement. This is a nice solution, but you have to pay attention to performance since context switching between SQL and PLSQL is expensive. So please use PL/SQL functions carefully in your SQL statements, especially in WHERE clauses. The included functions might be called more often than you think they might be. Decreasing the use of such function calls will improve the overall performance.

Contents

Limit the use of PLSQL methods in the SELECT list

Example:

Original cursor:

The above can be rewritten by taking off the method call in the SELECT statement. Instead the method call is inside plsql code, therefore no context switch is needed.

Limit the use of PLSQL methods in the WHERE clause

There are disadvantages of using PLSQL methods inside the where clause, they are as follows:

Example:

A function call in the where clause could be a performance killer.

Solution:

Move the method call from the cursor into PLSQL

Limit the use of PLSQL methods in VIEWS

Often, it is very easy to place stored functions in the private base method views. This will lead to ”large”, also known as ”fat” views. It is better to place the function calls as columns in the client than placing them in views of the logical unit. Since the views might be taken from anywhere, and very often from the client, the rules from above should be considered when designing views. Please note that the client server communication model in Foundation1 is constructed to use ”thin base views”.