In Oracle 11g, PL/SQL native compilation requires no C compiler, no DBA intervention and is fully supported in a RAC environment. By setting the PLSQL_CODE_TYPE to a value of NATIVE , rather than the default value of INTERPRETED , code is compiled directly to machine code . When the code is called, it is loaded into shared memory, making it accessible for all sessions in that instance. The %_PLSQL_OBJECT_SETTINGS views include the current PLSQL_CODE_TYPE setting for each PL/SQL object.
SQL> CREATE OR REPLACE PROCEDURE test_speed AS
2 v_number NUMBER;
3 BEGIN
4 FOR i IN 1 .. 10000000 LOOP
5 v_number := i / 1000;
6 END LOOP;
7 END;
8 /
Procedure created.
SQL> select name,type,plsql_code_type from user_plsql_object_settings where name ='TEST_SPEED';
NAME TYPE PLSQL_CODE_TYPE
--------- ------------ ------------------
TEST_SPEED PROCEDURE INTERPRETED
SQL> set timing on
SQL> exec test_speed;
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.37
SQL> alter session set plsql_code_type='NATIVE';
Session altered.
Elapsed: 00:00:00.12
SQL> alter procedure test_speed compile;
Procedure altered.
Elapsed: 00:00:01.64
SQL> select name,type,plsql_code_type from user_plsql_object_settings where name ='TEST_SPEED';
NAME TYPE PLSQL_CODE_TYPE
-------- ------------ -------------------
TEST_SPEED PROCEDURE NATIVE
Elapsed: 00:00:00.01
SQL> exec test_speed;
PL/SQL procedure successfully completed.
Elapsed: 00:00:02.14
It is very simple and easy now in 11g. You have to just set PLSQL_CODE_TYPE to NATIVE and rest everything will be taken care by Oracle Database.
Comments
Post a Comment