Escolar Documentos
Profissional Documentos
Cultura Documentos
UTL_MAIL
13-Sep-13 10:29 AM
PL/SQL 10 g
Define your own string delimiters to remove the need to double up any single quotes. Any character that is not present in the string can be used as the delimeter.
SET SERVEROUTPUT ON BEGIN -- Orginal syntax. DBMS_OUTPUT.put_line('This is Tim''s string!');
-- New syntax. DBMS_OUTPUT.put_line(q'#This is Tim's string!#'); DBMS_OUTPUT.put_line(q'[This is Tim's string!]'); END; / This is Tim's string! This is Tim's string! This is Tim's string! PL/SQL procedure successfully completed.
13-Sep-13 10:29 AM
PL/SQL 10 g
SQL*Plus will now display your DBMS_OUTPUT after the result of a SELECT statement from procedures, triggers, and functions. DBMS_OUTPUT displays right after the execution of a SELECT statement and does not require you to take additional action for this display.
dbms_select
DESCRIBE
9i DESCRIBE an object that was INVALID, Oracle would just tell you the object was invalid. When you DESCRIBE an INVALID object, Oracle will attempt to re-compile and validate it. If successful validates, it shows the structure of the object.
desc
10g
13-Sep-13 10:29 AM
PL/SQL 10 g
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.
PL/SQL 10 g
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:29 AM
PL/SQL 10 g
PL/SQL 10 g
PL/SQL 10 g
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:29 AM
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:29 AM
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.
13-Sep-13 10:29 AM
10
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.
PL/SQL 10 g
13-Sep-13 10:29 AM
12
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:29 AM
13
PL/SQL 10 g
UTL_MAIL
UTL_Mail
PL/SQL 10 g
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:29 AM
15