Databases Reference
In-Depth Information
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:
1.
Connect to the SH schema:
CONNECT sh@TESTDB/sh
2.
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 LOOP;
FOR J IN 1..(N - K) LOOP
N_K_FAT := N_K_FAT * J;
END LOOP;
RETURN (N_FAT / (N_K_FAT * K_FAT));
END;
/
 
Search WWH ::




Custom Search