Sie sind auf Seite 1von 2

Practices and Solutions for Lesson 4

Practice 4: Interacting with the Oracle Server


In this practice, you use PL/SQL code to interact with the Oracle Server.
1) Create a PL/SQL block that selects the maximum department ID in the
table and stores it in the variable. Display the
maximum department ID.
a) Declare a variable of type in the declarative section.
b) Start the executable section with the keyword and include a
statement to retrieve the maximum from the
table.
c) Display and end the executable block.
d) Execute and save your script as . The sample output is
as follows:

2) Modify the PL/SQL block that you created in step 1 to insert a new department into
the table.
a) Load the script. Declare two variables:
of type and
of type
Assign 'Education' to in the declarative section.
b) You have already retrieved the current maximum department number from the
table. Add 10 to it and assign the result to .
c) Include an statement to insert data into the ,
, and columns of the table.
Use values in and for and
, respectively, and use for .
d) Use the SQL attribute to display the number of rows that are
affected.
e) Execute a statement to check whether the new department is inserted.
You can terminate the PL/SQL block with “/” and include the statement
in your script.
f) Execute and save your script as . The sample output is
as follows:

Oracle Database 11g: PL/SQL Fundamentals A - 28


Practice 4: Interacting with the Oracle Server (continued)

3) In step 2, you set to . Create a PL/SQL block that updates the


to for the new department.
Note: If you successfully completed step 2, continue with step 3a. If not, first execute
the solution script .
a) Start the executable block with the keyword. Include the
statement to set the to for the new department (
=280).
b) End the executable block with the keyword. Terminate the PL/SQL block
with “/” and include a statement to display the department that you
updated.
c) Include a statement to delete the department that you added.
d) Execute and save your script as . The sample output is
as follows:

Oracle Database 11g: PL/SQL Fundamentals A - 29

Das könnte Ihnen auch gefallen