0% found this document useful (0 votes)
3 views

PLSQL_1_3_sg

The document discusses key concepts in PL/SQL, including the necessity of DECLARE sections for variables and cursors, the use of DBMS_OUTPUT.PUT_LINE for displaying output, and the handling of exceptions in SELECT statements. It also differentiates between anonymous blocks and named subprograms like procedures and functions. Additionally, the document mentions tools related to Application Express and SQL Workshop, emphasizing their relevance in the business world.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

PLSQL_1_3_sg

The document discusses key concepts in PL/SQL, including the necessity of DECLARE sections for variables and cursors, the use of DBMS_OUTPUT.PUT_LINE for displaying output, and the handling of exceptions in SELECT statements. It also differentiates between anonymous blocks and named subprograms like procedures and functions. Additionally, the document mentions tools related to Application Express and SQL Workshop, emphasizing their relevance in the business world.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

1

2
3
4
5
DECLARE is not needed if no variables, constants, cursors or user-defined exceptions are required. But
nearly all real-life blocks will need variables and/or cursors, therefore nearly all real-life blocks will need
a DECLARE section.

6
7
8
PUT_LINE is a function in the DBMS_OUTPUT package that displays its argument (in this slide, the value
stored in v_date) on the screen for the user to see.

9
What happens if the SELECT statement finds more than one employee with that last name? There is
only room for one first name and one last name. Without the EXCEPTION section, the DECLARATIVE
section would abort and return an Oracle error message. With the EXCEPTION section, the abort is
handled by the code in the EXCEPTION section and the user (or later, the calling application) sees a
friendlier error message.

10
11
12
13
14
This is an example of a PL/SQL code block that is NOT an anonymous block.

This block creates a PROCEDURE that when called will display today's date.

15
This is an example of a PL/SQL code block that is NOT an anonymous block.

This block creates a FUNCTION that will return tomorrow's date (much like SYSDATE is a function that
returns today's date).

The FUNCTION could also be used to initialize a variable:


DECLARE v_tomorrow DATE := TOMORROW(SYSDATE);
BEGIN
DBMS_OUTPUT.PUT_LINE('Tomorrow is ' || v_tomorrow);
END;

16
This course will focus on Application Express and its SQL Workshop. You also will use Application Builder
in a project. The other tools are all free downloads with excellent documentation available from
www.oracle.com. All of these tools are widely-used in the business world.

17
18
Although not required, the convention is to follow all SQL statements with a forward slash (/), as well as
the anonymous blocks, in SQL script files.

19
20
21
The second DBMS_OUTPUT.PUT_LINE call in the slide shows that number values (v_emp_count) can be
displayed by PUT_LINE in combination with string values.
In this example, the Oracle server has performed an implicit datatype conversion
(TO_CHAR(v_emp_count)) to convert the number to a character string for concatenation.

22
• Anonymous PL/SQL block – unnamed blocks of code not stored in the database and do not exist after
they are executed
• Compiler – software that checks and translates programs written in high-level programming
languages into binary code to execute
• Subprograms – named PL/SQL blocks that are stored in the database and can be declared as
PROCEDURES or FUNCTIONS
• Procedures – subprograms that perform an action and may return one or more values
• Functions – subprograms that return a single value

23
24
25

You might also like