Professional Documents
Culture Documents
Packages 5 PDF
Packages 5 PDF
PL/SQL
11-2
Using Oracle-Supplied Packages
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 3
Using Oracle-Supplied Packages
Purpose
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 4
Using Oracle-Supplied Packages
Purpose
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 5
Using Oracle-Supplied Packages
Using Oracle-Supplied Packages
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 6
Using Oracle-Supplied Packages
List of Some Oracle-Supplied Packages
Tab Function
Enables manipulation of Oracle Large Object column
DBMS_LOB
datatypes: CLOB, BLOB and BFILE
Used to request, convert, and release locks in the
DBMS_LOCK
database through Oracle Lock Management services
DBMS_OUTPUT Provides debugging and buffering of messages
HTP Writes HTML-tagged data into database buffers
Enables reading and writing of operating system text
UTL_FILE
files
UTL_MAIL Enables composing and sending of e-mail messages
Enables scheduling of PL/SQL blocks, stored
DBMS_SCHEDULER
procedures, and external procedures or executables
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 7
Using Oracle-Supplied Packages
The DBMS_OUTPUT Package
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 8
Using Oracle-Supplied Packages
How the DBMS_OUTPUT Package Works
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 9
Using Oracle-Supplied Packages
How the DBMS_OUTPUT Package Works
PUT
PUT_LINE
NEW_LINE
BEGIN
DBMS_OUTPUT...; Output
END; GET_LINE
GET_LINES
Buffer
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 10
Using Oracle-Supplied Packages
Using DBMS_OUTPUT: Example 1
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 11
Using Oracle-Supplied Packages
Using DBMS_OUTPUT: Example 2
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 12
Using Oracle-Supplied Packages
DBMS_OUTPUT Is Designed for
Debugging Only
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 13
Using Oracle-Supplied Packages
DBMS_OUTPUT Is Designed for
Debugging Only
• For example:
CREATE OR REPLACE PROCEDURE do_some_work (...) IS
BEGIN
... DBMS_OUTPUT.PUT_LINE('string'); ...
END;
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 14
Using Oracle-Supplied Packages
DBMS_OUTPUT Is Designed for
Debugging Only
BEGIN do_some_work;
END; -- Test the procedure
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 15
Using Oracle-Supplied Packages
DBMS_OUTPUT Is Designed for
Debugging Only
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 16
Using Oracle-Supplied Packages
The UTL_FILE Package
BEGIN
UTL_FILE...;
END;
UTL_FILE O/S text file
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 17
Using Oracle-Supplied Packages
File Processing Using the UTL_FILE
Package
Close the
• Writing or appending to a file text file
PUT(f,buf) FCLOSE(f)
PUT_LINE(f,buf)
Open for Put lines into More to
write/append the text file write? No
f:=FOPEN(dir,file,'w')
f:=FOPEN(dir,file,'a') Yes
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 18
Using Oracle-Supplied Packages
File Processing Using the UTL_FILE
Package
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 19
Using Oracle-Supplied Packages
Exceptions in the UTL_FILE Package
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 20
Using Oracle-Supplied Packages
Exceptions in the UTL_FILE Package
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 21
Using Oracle-Supplied Packages
FOPEN and IS_OPEN Function
Parameters
Example:
PROCEDURE read(dir VARCHAR2, filename VARCHAR2) IS
file UTL_FILE.FILE_TYPE;
BEGIN
IF NOT UTL_FILE.IS_OPEN(file) THEN
file := UTL_FILE.FOPEN (dir, filename, 'r');
END IF; ...
END read;
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 22
Using Oracle-Supplied Packages
Using UTL_FILE Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 23
Using Oracle-Supplied Packages
Using UTL_FILE Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 24
Using Oracle-Supplied Packages
Using UTL_FILE Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 25
Using Oracle-Supplied Packages
Using UTL_FILE Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 26
Using Oracle-Supplied Packages
Using UTL_FILE Invocation and Output
Report Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 27
Using Oracle-Supplied Packages
The UTL_MAIL Package
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 28
Using Oracle-Supplied Packages
The UTL_MAIL.SEND Procedure Example
BEGIN
UTL_MAIL.SEND('database@oracle.com',
'joe43@yahoo.com',
message => 'Friday’s meeting will be at 10:30 in
Room 6',
subject => 'Our PL/SQL meeting');
END;
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 29
Using Oracle-Supplied Packages
The UTL_MAIL.SEND_ATTACH_RAW
Procedure
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 30
Using Oracle-Supplied Packages
The UTL_MAIL.SEND_ATTACH_RAW
Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 31
Using Oracle-Supplied Packages
The UTL_MAIL.SEND_ATTACH_RAW
Example
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 32
Using Oracle-Supplied Packages
The UTL_MAIL.SEND_ATTACH_VARCHAR2
Procedure
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 33
Using Oracle-Supplied Packages
UTL_MAIL.SEND_ATTACH_VARCHAR2:
Example
BEGIN
send_mail_with_text('This document is designed to help in
creating a project ...');
END;
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 34
Using Oracle-Supplied Packages
Terminology
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 35
Using Oracle-Supplied Packages
Summary
PLSQL S11L2 Copyright © 2016, Oracle and/or its affiliates. All rights reserved. 36
Using Oracle-Supplied Packages