Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

LESSON 1.

D. Pre-list;
Answer the following questions concisely.
In your own words, describe why a procedural language like PL/SQL is needed.
ANSWER:
PL/SQL is most useful to write triggers and stored procedures. Stored procedures are
units of procedural code stored in a compiled form within the database. Why a procedural
language like PL/SQL is needed for the reasons that users allowed to access data for a large
database application, it allows logic and control to be combined with basic SQL statements,
making it possible to create more useful programs.
PL/SQL provides high security level. PL/SQL is a highly structured and readable
language. Its constructs express the intent of the code clearly. Also, PL/SQL is a straightforward
language to learn. The PL/SQL language allows you to submit a complete block of statements
to the database at once. This minimizes network traffic while maintaining good application
performance. Because it can query, transform, and update data in a database, PL/SQL allows
programmers to work more efficiently.

F. ASSESSMENT;

1. Identify the vocabulary word for each definition below:

Procedural Programming language features such as reusable/callable program units,


Constructs modular blocks, cursors, constants, variables, assignment statements,
conditional control statements, and loops
Oracle Corporations standard procedural language for relational databases
PL/SQL which allows basic program logic and control flow to be combined with SQL
statements

2. Encircle the programming language meeting the criteria


Criteria Language

3GL PL/SQL S
Q
L
4GL PL/SQL S
Q
L
Is proprietary to Oracle Corporation PL/SQL S
Q
L
Nonprocedural PL/SQL S
Q
L
Procedural PL/SQL S
Q
L
Is ANSI-compliant PL/SQL S
Q
L

3. List some examples of procedural constructs in PL/SQL.


ANSWER:
PL/SQL is a modern, block-structured programming language. It provides several features
that make developing powerful database applications very convenient. The procedural code
includes VARIABLES, CONSTANTS, CURSORS, CONDITIONAL LOGIC, and ITERATION.

4. In the following code, identify (circle or highlight) examples of these procedural


constructs: variable, conditional control statement, reusable/callable program unit, and
an assignment statement.

DECLARE
v_first_name varchar2(40);
v_last_name varchar2(40);
v_first_letter varchar2(1);

BEGIN
SELECT first_name, last_name INTO v_first_name, v_last_name
FROM students
WHERE student_id = 105;
v_first_letter := get_first_letter(v_last_name);
IF 'N' > 'v_first_letter' THEN
DBMS_OUTPUT.PUT_LINE('The last name for ' || v_first_name || ' ' || v_last_name ||
' is between A and M');
ELSE
DBMS_OUTPUT.PUT_LINE('The last name for ' || v_first_name || ' ' || v_last_name ||
' is between N and Z');
END IF;
END;
LESSON 1.2

B. Analysis

Identify the vocabulary word for each definition below:

The ability for PL/SQL programs to run anywhere an Oracle server


PORTABILITY runs.

BLOCKS The basic unit of PL/SQL programs- also known as modules.

An error that occurs in the database or in a user’s program during


EXCEPTION runtime.

D. Application

Try It / Solve It

1. Why is it more efficient to combine SQL statements into PL/SQL blocks?


ANSWER:
It is more efficiently to use SQL statements within PL/SQL blocks because network traffic
can be decreased significantly and an application becomes more efficient as well.
When an SQL statement is issued on the client computer the request is made to the
database on the server, and the result set is sent back to the client. As a result, a single SQL
statement causes two trips on the network. If multiple SELECT statement are issued, the
network traffic can increase significantly very quickly.

2. Why is it beneficial to use PL/SQL with an Oracle database? List at least three reasons.
ANSWER:
There are many benefits to using the PL/SQL programming language with an Oracle database.
 Integration of procedural constructs with SQL
 Modularized program development
 Improved performance
 Integration with Oracle tools
 Portability
 Exception handling
3. How is PL/SQL different from C and Java? List three differences.
ANSWER:

 PL/SQL requires a database or Oracle tool.


 PL/SQL allows for some object-oriented programming techniques, but is not as
extensive as Java.
 PL/SQL is the most efficient language to use with an Oracle database.
 PL/SQL is portable to other operating systems, as long as it is running a compatible
Oracle database (that is, a database with the same version).
 PL/SQL is easier to learn than C and Java.

4. List three examples of what you can build with PL/SQL code.
ANSWER:
Using PL/SQL, you can build:
 Create Web and other applications
 Manage application data (write programs for DDL or DML)
 Manage the Oracle database (write programs for security, for managing database jobs)
 Create custom reports
LESSON 1.3

F. Analysis

Complete the following chart defining the syntactical requirements for a PL/SQL block:
Optional or Mandatory? Describe what is included in this
section

DECLARE OPTIONAL Declarations of all variables,


constants, cursors, and user-
defined exceptions.
BEGIN MANDATORY Contains SQL statements and
PL/SQL statements.
EXCEPTION OPTIONAL Actions to perform when errors
occur.
END; MANDATORY END; (end with semicolon)

H. Application

Vocabulary
Identify the vocabulary word for each definition below:

Unnamed blocks of code not stored in the database and do not


Anonymous PL/SQL Block exist after they are executed

A program that computes and returns a single value


Function
Named PL/SQL blocks that are stored in the database and can be
Subprograms declared as procedures or functions

Software that checks and translates programs written in high-level


Compiler programming languages into binary code to execute

A program that performs an action, but does not have to return a


Procedure value

Try It / Solve It
1. Which of the following PL/SQL blocks executes successfully? For the blocks that fail,
explain why they fail
A. BEGIN
END;
ANSWER:

Fails because the executable section must contain at least one statement.
(After begin we must have something or NULL.)

B. DECLARE amount INTEGER(10); END;


ANSWER:

Fails because there is no executable section BEGIN is missing.

C. DECLARE
BEGIN
END;
ANSWER:

Fails because the executable section must contain at least on statement.


(The same with the Letter A.)

D. DECLARE amount NUMBER(10);


BEGIN
DBMS_OUTPUT.PUT_LINE(amount);
END;

ANSWER:

PL/SQL procedure successfully completed.

2. Fill in the blanks:

A. PL/SQL blocks that have no names are called ANONYMOUS BLOCKS.

B. PROCEDURES and FUNCTIONS are named blocks and are stored in the
database.
3. In Application Express, create and execute a simple anonymous block that outputs “Hello
World.”
ANSWER:

BEGIN
DBMS_OUTPUT.PUT_LINE ('Hello World');
END;

4. Create and execute a simple anonymous block that does the following:

• Declares a variable of datatype DATE and populates it with the date that is six
months from today
• Outputs “In six months, the date will be: <insert date>.”
ANSWER:

 
DECLARE v_timestamp DATE;
BEGIN
SELECT ADD_MONTHS(SYSDATE,6) INTO v_timestamp FROM
DUAL;
DBMS_OUTPUT.PUT_LINE('In six months, the date will be: '||v_timestamp);
END;

You might also like