PL/SQL Conditional Compilation
来源:互联网 发布:学数控编程的学校 编辑:程序博客网 时间:2024/05/22 13:21
该特性与C语言的类似。从Oracle 9.2.0.6开始被引入,9.2.0.6默认关闭该特性,可以通过一个参数打开。10gR1默认是打开,可以关闭。10gR2或以上默认打开,不可以关闭。常用于以下场景:
- 代码使用Oracle某新特性实现某个需求;为了兼容老版本Oracle,需要用另一个方法实现。在编译时,可以针对Oracle版本,选择性的编译。
- 在开发时,打开Tracing, 生产服务器上关闭Tracing。
Conditional Compilation有三种元素:
Selective Directives:
$IF $THEN $ELSEIF $ELSE $END
Inquiry Directives: 用$$引用
NLS_Length_Semantics
PLSQL_Optimize_Level: 0-3. 11gR2, 默认2. 1: PL/SQL 优化器基本不改变代码。0: 不改变代码,同时将代码中BINARY_INTEGER和PLS_INTEGER替换为效率稍低的类型。10g+Oracle使用这个级别会有性能损失。
PLSQL_Code_Type
PLSQL_Debug:deprecated.
PLSQL_Warnings: 11gR2默认'DISABLE:ALL', 表示忽略所有Warning信息。
alter session set plsql_warnings='ENABLE:SEVERE'将severe信息作为Warning。
alter session set plsql_warnings='ENABLE:INFORMATIONAL'alter system set plsql_warnings='enable:performance', 'enable:severe';PLSQL_CCFLAGS 。码农可以用PLSQL_CCFLAGS自定义一些控制参数,如:ALTER SESSION SET PLSQL_CCFLAGS = 'debug:TRUE'
PLSQL_UNIT: 当前代码段
PLSQL_LINE:代码行
Error Directives: $ERROR,指令预编译器报错。
两个辅助PL/SQL包
DBMS_DB_VERSION
DBMS_PREPROCESSOR:用户可以看到预编译完毕的代码
例子1: 使用$error编译时报错
begin$if true $then $error 'Error: Go to ' || $$plsql_unit || ' at line ' || $$plsql_line$endend;例子2:$error 结合plsql_ccflags
ALTER SESSION SET PLSQL_CCFLAGS = 'current_user_type:0'CREATE OR REPLACE PACKAGE user_typesIS administrator CONSTANT PLS_INTEGER := 1; enduser CONSTANT PLS_INTEGER := 2;END user_types; CREATE OR REPLACE PROCEDURE show_infoISBEGIN $IF $$current_user_type = user_types.administrator $THEN DBMS_OUTPUT.PUT_LINE ('Administrator!'); $elsif $$current_user_type = user_types.enduser $THEN DBMS_OUTPUT.PUT_LINE ('End user!'); $ELSE $ERROR 'Current user type of ' || $$current_user_type || ' is not known.' $END $ENDend show_info;show errors;11/6 PLS-00179: $ERROR: Current user type of 0 is not known.例子3: Oracle数据库版本相关
CREATE OR REPLACE PROCEDUREcrunch_numbersIS n $IF DBMS_DB_VERSION.VER_LE_9_2 $THEN NUMBER; $ELSE BINARY_FLOAT; $ENDBEGIN $IF DBMS_DB_VERSION.VER_LE_9_2 $THEN n := 1.0; $ELSE n := 1.0f; $END DBMS_OUTPUT.put_line ( n );END crunch_numbers;
例子4: DEV环境,打开Tracing
alter session set plsql_ccflags = 'tracing:true';create or replace procedure p1asbegin $if $$tracing = true $then dbms_output.put_line('xx'); $end null;end;本文部分例子借鉴了Oracle Magazine
http://www.oracle.com/technetwork/issue-archive/2006/06-jul/o46plsql-096385.html
DBMS_PREPROCESSOR.print_post_processed_source:
set serveroutput on;exec DBMS_PREPROCESSOR.PRINT_POST_PROCESSED_SOURCE('PROCEDURE',NULL, UPPER('crunch_numbers'));
- PL/SQL Conditional Compilation
- PL/SQL中的条件编译(Conditional Compilation)
- Conditional Compilation
- JScript: Conditional Compilation
- 9.5.1 Conditional compilation symbols
- 9.5.4 Conditional compilation directives
- Conditional Compilation In Java @ JDJ
- IE 条件编译 conditional compilation
- Java 条件编译 Conditional Compilation
- Oracle PL/SQL 优化与调整 – PL/SQL Native Compilation 说明
- java 条件编译(Conditional Compilation)
- Compilation of Views and PL/SQL Program Units【每日一译】--2013-1-10
- #if #elif #endif 的使用--------条件编译(conditional compilation)
- Oracle PL/SQLWarning: Function created with compilation errors.
- Order a column conditional in SQL
- PL SQL
- pl/sql
- pl/sql
- Linux 时间同步配置【转自偶像大神dave】
- web测试--http状态码
- POJ 1611 The Suspects(并查集)
- sscanf的使用说明(感觉好强大)
- Oracle 表连接方式(内连接/外连接/自连接) 详解
- PL/SQL Conditional Compilation
- SpecDD:混合的敏捷开发方法模型概述
- 各大电脑主板U盘快速启动项快捷键大全2014
- 码率、帧率
- Medoo Avg的使用:计算字段的值的平均数
- 使用普通按钮代替input file
- Box2D C++教程6-定制器(Fixtures)
- 磁盘的块大小(Block Size)和扇区大小(Sector Size)
- 马来西亚民航局官员暗示1名持假护照者为黑人