Oracle 10 Gb new feature -- selective compilation

Source: Internet
Author: User
Oracle 10 Gb new feature -- selective compilation

Author: Fuyuncat

Source: Www.hellodba.com

Oracle10g provides a new feature that is very convenient for developers-selective compilation. That is, only part of the code in PL/SQL can be compiled through the condition. If you are familiar with C ++, you will feel very cordial about this feature, because it is very similar to the conditional Macros in C ++. When 9i is used, developers add their debugging information to the program, which is often not deleted after release. This information affects readability and system performance in severe cases. With this feature, this problem can be solved.

The following is a simple example:

 

Create a function with conditional macros:

SQL> CREATE OR REPLACE FUNCTION F_TESTDEBUG
  2  RETURN NUMBER IS
  3    v_count number;
  4  BEGIN
  5    select count(*) into v_count from user_tables;
  6  
  7    $IF $$my_debug $THEN 
  8       DBMS_OUTPUT.PUT_LINE('Tables number is: ' || v_count);
  9    $END
 10  
 11    return v_count;
 12  END;
 13  /

 

Function created

 

Activate debug information (controlled by the variable $ my_debug ):

SQL> ALTER FUNCTION F_TESTDEBUG COMPILE PLSQL_CCFLAGS = 'my_debug:TRUE' REUSE SETTINGS;
 
Function altered

 

Run the function:

SQL> set serveroutput on

SQL> declare

2 v_res number;

3 begin

4 v_res: = f_testdebug;

5 end;

6/

 

Tables number is: 22

 

PL/SQL procedure successfully completed

 

At this time, we can see that the debug information is printed out.

 

Let's remove the debugging information:

SQL> alter function f_testdebug compile plsql_ccflags = 'my _ Debug: false' reuse settings;

 

Function altered

 

Execute the function:

SQL> declare

2 v_res number;

3 begin

4 v_res: = f_testdebug;

5 end;

6/

 

PL/SQL procedure successfully completed

 

We can see that the debugging information is gone.

 

Of course, we do not need to use alter in actual release (unless on-site debugging). You can define the my_debug variable in the header of the release script.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.