PL/SQL 中的条件编译:一次编写,多次执行
| 1 create or replace function myfunc 2 return varchar2 3 as 4 begin 5 $if $$ppval $then 6 return 'PPVAL was TRUE'; 7 $else 8 return 'PPVAL was FALSE'; 9 $end 10* end; |
| SQL> alter session set plsql_ccflags = 'PPVAL:TRUE'; Session altered. |
| SQL> alter function myfunc compile; Function altered. SQL> select myfunc from dual; MYFUNC ------------------------------------- PPVAL was TRUE |
| SQL> alter session set plsql_ccflags = 'PPVAL:FALSE'; Session altered. SQL> select myfunc from dual; MYFUNC --------------------------------------------------------- PPVAL was TRUE |
| Function altered. SQL> select myfunc from dual; MYFUNC --------------------------------------------------- PPVAL was FALSE |
| alter function calculate_interest compile plsql_ccflags = 'ACTIVE_STATUS_ONLY:TRUE' reuse settings; alter function apply_interest compile plsql_ccflags = FOREIGN_ACCOUNTS:TRUE' reuse settings; |
| create or replace package debug_pkg is debug_flag constant boolean := FALSE; end; |
| create or replace procedure myproc as begin $if debug_pkg.debug_flag $then dbms_output.put_line ('Debug=T'); $else dbms_output.put_line ('Debug=F'); $end end; |
| SQL> exec myproc Debug=F |
| create or replace package debug_pkg is debug_flag constant boolean := TRUE; end; |
| SQL> exec myproc Debug=T |
| ERROR at line 1: ORA-20000:ORU-10027:buffer overflow, limit of 1000000 bytes ORA-06512:at "SYS.DBMS_OUTPUT", line 32 ORA-06512:at "SYS.DBMS_OUTPUT", line 97 ORA-06512:at "SYS.DBMS_OUTPUT", line 112 ORA-06512:at line 2 |
| SQL> show serveroutput serveroutput ON size 2000 format WORD_WRAPPED |
| SQL> show serveroutput serveroutput ON SIZE UNLIMITED FORMAT WORD_WRAPPED |
| ERROR at line 1: ORA-20000:ORU-10028:line length overflow, limit of 255 chars per line ORA-06512:at "SYS.DBMS_OUTPUT", line 35 ORA-06512:at "SYS.DBMS_OUTPUT", line 115 ORA-06512:at line 2 |