Using native compilation
In this recipe, we will see how to instruct the database to compile our stored procedures in native form—rather than interpreted—to speed up the execution time.
Getting ready
To be sure that our database is not using native compilation by default, we can execute the following command from a SQL*Plus Session:
SHOW PARAMETER PLSQL_CODE_TYPE
If the result is NATIVE
, we can execute the following statement to return to the original default value:
ALTER SYSTEM SET PLSQL_CODE_TYPE = INTERPRETED;
How to do it...
The following steps will demonstrate how to use native compilation:
Connect to the
SH
schema:CONNECT sh@TESTDB/sh
Create the function
C_N_K
, which calculates the number of k-combinations in a set of n elements:CREATE OR REPLACE FUNCTION C_N_K (N IN NUMBER, K IN NUMBER) RETURN NUMBER IS N_FAT NUMBER := 1; K_FAT NUMBER := 1; N_K_FAT NUMBER := 1; BEGIN FOR J IN 1..N LOOP N_FAT := N_FAT * J; END LOOP; FOR J IN 1..K LOOP K_FAT := K_FAT * J; END...