Vous êtes sur la page 1sur 12

PL/SQL 10 g

PL/SQL Native Compilation

Package specification and body are independent, can be natively compiled. Set PLSQL_NATIVE_LIBRARY_DIR parameter to use native compilation. All other parameters have been obsolete.

The associated compiler commands are stored in the $ORACLE_HOME/plsql/spnc_commands.


PLSQL_CODE_TYPE parameter used to switch ON/OFF.

Native_compilation 13-Sep-13 10:43 AM 1

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

FORALL Support for Non-Consecutive Indexes

FORALL with non-consecutive indexes in collections. The INDICES OF clause allows the FORALL syntax to be used with sparse collections. VALUE OF clause used for collections of indexes pointing to other collections. FORALL i IN INDICES OF l_tab1 INSERT INTO tab1 VALUES l_tab1(i); FORALL i IN VALUES OF l_tab2 INSERT INTO tab1 VALUES l_tab1(i);

FOR_ALL

13-Sep-13 10:43 AM

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

New IEEE Floating-Point Types

BINARY_FLOAT and BINARY_DOUBLE.


Efficient for heavy floating point computations as the work is passed directly to the O/S.
Literal assignments can be performed using the "f" and "d" suffixes. Conversion functions TO_BINARY_FLOAT and TO_BINARY_DOUBLE DECLARE l_binary_float BINARY_FLOAT; l_binary_double BINARY_DOUBLE; BEGIN l_binary_float := 1.1f; l_binary_double := 1.00001d; l_binary_float := TO_BINARY_FLOAT(1.1); l_binary_double := TO_BINARY_DOUBLE(1.00001); END; / Rather than raise exceptions, the resulting values of computations can be tested

[BINARY_FLOAT|BINARY_DOUBLE]_NAN [BINARY_FLOAT|BINARY_DOUBLE]_INFINITY [BINARY_FLOAT|BINARY_DOUBLE]_MAX_NORMAL [BINARY_FLOAT|BINARY_DOUBLE]_MIN_NORMAL [BINARY_FLOAT|BINARY_DOUBLE]_MAX_SUBNORMAL [BINARY_FLOAT|BINARY_DOUBLE]_MIN_SUBNORMAL


13-Sep-13 10:43 AM 3

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

Improved Overloading With Numeric Types

Oracle 10g includes improved overloading of numeric types like:


-- Create package specification. CREATE OR REPLACE PACKAGE numeric_overload_test AS PROCEDURE go (p_number NUMBER); PROCEDURE go (p_number BINARY_FLOAT); PROCEDURE go (p_number BINARY_DOUBLE); END; /
-- Create package body. CREATE OR REPLACE PACKAGE BODY numeric_overload_test AS PROCEDURE go (p_number NUMBER) AS BEGIN DBMS_OUTPUT.put_line('Using NUMBER'); -- Test it. END; PROCEDURE go (p_number BINARY_FLOAT) AS BEGIN DBMS_OUTPUT.put_line('Using BINARY_FLOAT'); END; PROCEDURE go (p_number BINARY_DOUBLE) AS BEGIN DBMS_OUTPUT.put_line('Using BINARY_DOUBLE'); END; END; /
13-Sep-13 10:43 AM 4

SET SERVEROUTPUT ON BEGIN numeric_overload_test.go(10); numeric_overload_test.go(10.1f); numeric_overload_test.go(10.1d); END; /

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

Nested Table Enhancements


Nested_Table

Collections can be assigned directly to the value of another collection of the same type, or to the result of a set expression.
MULTISET MULTISET MULTISET MULTISET MULTISET MULTISET UNION UNION DISTINCT INTERSECT INTERSECT DISTINCT EXCEPT EXCEPT DISTINCT

Comparisons between collections have also improved with the addition of NULL checks, equality operators and set operations including:
Collection_Null

IF (l_col_3 IS NULL) AND (l_col_1 IS NOT NULL) THEN IF (l_col_3 = l_col_1) AND (l_col_3 != l_col_2) THEN IF (SET(l_col_2) SUBMULTISET l_col_1) AND (l_col_1 NOT SUBMULTISET l_col_2) THEN IF l_col_2 IS NOT A SET THEN IF l_col_3 IS NOT EMPTY THEN

13-Sep-13 10:43 AM

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

Compile-Time Warnings

Produce compile-time warnings when code is ambiguous or inefficient. PLSQL_WARNINGS init parameter & DBMS_WARNING package. Anonymous blocks do not produce any warnings.
Set the PLSQL_WARNINGS parameter
SEVERE : Unexpected behavior or wrong results, such as aliasing problems with parameters. PERFORMANCE : Performance problems, passing a VARCHAR2 value to a NUMBER column in an INSERT statement. INFORMATIONAL : Effect on performance or correctness. To make the code more maintainable, such as dead code that can never be executed. ALL : All warning messages.

ALTER SYSTEM SET PLSQL_WARNINGS='ENABLE:ALL'; ALTER SESSION SET PLSQL_WARNINGS='DISABLE:PERFORMANCE'; show parameter plsql_warnings
compile_time_warnings

13-Sep-13 10:43 AM

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

-- For debugging during development. ALTER SYSTEM SET PLSQL_WARNINGS='ENABLE:ALL'; -- To focus on one aspect. ALTER SESSION SET PLSQL_WARNINGS='ENABLE:PERFORMANCE'; ALTER PROCEDURE hello COMPILE -- Recompile with extra checking. PLSQL_WARNINGS='ENABLE:PERFORMANCE'; -- To turn off all warnings. ALTER SESSION SET PLSQL_WARNINGS='DISABLE:ALL'; -- PLW-06002 warnings to produce errors that halt compilation.

ALTER SESSION SET PLSQL_WARNINGS='ENABLE:SEVERE','DISABLE:PERFORMANCE', 'ERROR:06002';

13-Sep-13 10:43 AM

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

DBMS_WARNING Package

Control PL/SQL warning messages by calling subprograms. Different warning settings apply to different subprograms.
Procedure with unnecessary code that could be removed. CREATE OR REPLACE PROCEDURE dead_code AS x number := 10; BEGIN if x = 10 then x := 20; else x := 100; -- dead code (never reached) end if; END dead_code; / -- By default, the procedure compiles with no errors or warnings.
-- Now enable all warning messages, just for this session.

CALL DBMS_WARNING.SET_WARNING_SETTING_STRING ('ENABLE:ALL' ,'SESSION');


-- Check the current warning setting.

select dbms_warning.get_warning_setting_string() from dual;


-- Recompile the procedure, warning about the dead code.

ALTER PROCEDURE dead_code COMPILE;


View - [USER|DBA|ALL]_PLSQL_OBJECT_SETTINGS The errors can be queried using the %_ERRORS views.
13-Sep-13 10:43 AM 8

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

Implicit Conversion Between CLOB and NCLOB


10g supports implicit conversions between CLOBs and NCLOBs and vice-versa. Use conversion functions TO_CLOB and TO_NCLOB explicitly for clarity.

13-Sep-13 10:43 AM

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

UTL_COMPRESS

UTL_COMPRESS package provides an API to allow compression and decompression of binary data (RAW, BLOB and BFILE). It uses the Lempel-Ziv compression algorithm which is equivalent to functionality of the gzip utility.
-- Initialize both BLOBs to something. l_original_blob:=
TO_BLOB(UTL_RAW.CAST_TO_RAW('1234567890123456789012345678901234567890'));

l_compressed_blob := TO_BLOB('1'); l_uncompressed_blob := TO_BLOB('1'); -- Compress the data. UTL_COMPRESS.lz_compress (src => l_original_blob, dst => l_compressed_blob); -- Uncompress the data. UTL_COMPRESS.lz_uncompress (src => l_compressed_blob, dst => l_uncompressed_blob);

UTL_Compress

13-Sep-13 10:43 AM

10

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

UTL_MAIL

Provides a simple API to allow email to be sent from PL/SQL.


In prior versions this was possible using the UTL_SMTP package, but this required knowledge of the SMTP protocol. The package also supports sending mails with RAW and VARCHAR2 attachments. Run the following scripts:
CONN sys/password AS SYSDBA @$ORACLE_HOME/rdbms/admin/utlmail.sql @$ORACLE_HOME/rdbms/admin/prvtmail.plb

Set SMTP_OUT_SERVER parameter


ALTER SYSTEM SET smtp_out_server='smtp.domain.com SCOPE=SPFILE; UTL_MAIL.send( sender => 'me@domain.com', recipients => 'person1@domain.com,person2@domain.com', cc => 'person3@domain.com', bcc => 'myboss@domain.com', subject => 'UTL_MAIL Test', message => 'If you get this message it worked!');
13-Sep-13 10:43 AM 11

UTL_Mail

Copyright i-flex solutions Training Department, 2005. All rights reserved.

PL/SQL 10 g

Flashback Query Functions

Translate between a date and time, and the System Change Number. SCN provide a precise way to see the data as it was at that moment. TIMESTAMP_TO_SCN Returns the SCN associated with that timestamp. SCN_TO_TIMESTAMP Returns the timestamp associated with that SCN.

flashback_fun

13-Sep-13 10:43 AM

12

Copyright i-flex solutions Training Department, 2005. All rights reserved.