Académique Documents
Professionnel Documents
Culture Documents
Write PL/SQL code to create a procedure for inserting a new prospect customer into the
prospect table.
2. Create a script that uses substitution variables and the procedure created in question above to
enter a new prospect.
SET SERVEROUTPUT ON
SET HEADING OFF
SET VERIFY OFF
BEGIN
new_prospect('&p_name', '&p_make', '&p_model', '&p_year',
'&p_color', '&p_trim', '&p_code');
COMMIT;
END;
3. Add to question 1 a user-defined excetion that would print "Car is too old" if the prospect is
asking for a car older that 6 years (2013) as well as a system-defined exception for handling all
other errors such as referential integrity, wrong data etc..
4. Write a function that calculates and returns the number of customers, who are asking for a
certain make and model
RETURN v_count;
END;
/
5. Create a script that uses substitution variables and the function created in question above.
SET SERVEROUTPUT ON
SET HEADING OFF
SET VERIFY OFF
ACCEPT p_make PROMPT 'Enter make: '
ACCEPT p_model PROMPT 'Enter model: '
BEGIN
DBMS_OUTPUT.put_line('There are :' || countProspect('&p_make', '&p_model') ||
'
customers looking for ' || '&p_make' || ' ' || '&p_model' );
END;
/
6. Create a log table for keeping the logs of the changes made in the prospect table and write a
trigger that would write all data changes to that log table
1. You would use a BEFORE trigger for all but one of the following. Which one is it?
a. to enforce data consistency
b. to create an audit table
c. to insert a sequence value into a column
d. to correct mixed-case customer names
5. While using SELECT INTO statements where are the database columns specified?
a. After the SELECT and before INTO
b. After the SELECT and after INTO
c. After the SELECT and FROM clause and before INTO clause
d. After the SELECT ,FROM clause and INTO clause and before WHERE clause
b
7. Which of the following is incorrect about functions?
a. A function is a module that returns a value.
b. A function is a standalone executable statement.
c. A function can be said to have a datatype.
d. A function can be used in place of an expression in a PL/SQL statement.
1. To print output to the console from a PL/SQL block, you can use the procedures in the
_____________ package.
DBMS_OUTPUT
2. To repeatedly execute a statement or set of statements when you’re using PL/SQL, you can
code a simple loop, a WHILE loop, or a/an ______________ loop.
FOR
3. Assume that this is the start of the code for creating a stored procedure:
in_param NUMBER,
cr_param NUMBER
AS
..........
Then, code the statement that you would use within a script to call the stored procedure and
pass the values 47 and 200 to it.
__________________________________
4. When you create a scalar-valued function, you use the ________________ statement to specify
the value that’s returned by the function.
RETURN
5. To enforce data consistency, you can create a trigger that is fired _____________ each row in a
table is updated.
BEFORE
A FOR is used when the number of iteration is known in advance. A WHILE loop generally is
used when the number of iterations is not known in advance.
The INTO clause is used to tell PL/SQL where to put data retrieved from a SELECT statement
9. What is an Exception?
An Exception is an identifier within PL/SQL that can be used to trap for a specific condition.
Exceptions are typically associated with an error. Exceptions are either raised automatically by
PL/SQL or they can be raised explicitly.
An Exception Handler is a section of PL/SQL code that is there purely to deal with any raised
exceptions.
A named cursor is a construct within PL/SQL that is used to retrieve data from the database.
13. What is the difference between stored subprograms such as procedures, functions and triggers,
and anonymous blocks?
Stored programs are stored within the database in compiled form and executed on the database,
whereas anonymous blocks are usually held in a host file and are parsed and compiled at
runtime, they are explicitly executed in a client tool, typically SQL*Plus
A trigger is a named PL/SQL block that fires implicitly when a particular database event occurs.