pl-sql_l1_exercises_0 (1)
pl-sql_l1_exercises_0 (1)
1. Create a trigger in your local schema without REPLACE keyword. What could happen when are
you going to modify the same trigger? (Any type of trigger may be INSERT/UPDATE/DELETE).
3. DML operations are allowed on tables only during Normal office hours of 8.30 am until 6.00pm
from Monday to Friday. Create a trigger to meet these requirements (Hint: Conditional
Predicate).
4. Create a stored procedure named Update_emp_sal to update the salary amount. This procedure
accepts two parameters. The job ID for which salary has to be updated, and the new minimum
salary for this job ID.
5. Create a row trigger named update_sal_emp_tri on the JOBS table that invokes the procedure
UPDATE_EMP_SAL when the minimum in the JOBS is updated for a specified job ID.
7. Write a trigger on salary column of employee table to ensure Salary is not increased by more
than 10% at a time and it is never decreased.
8. You need to create a trigger on the EMPLOYEE table that monitors every row that is changed
and places this information into the AUDIT_TABLE.
i. AUDIT_TABLE structure
ii. who varchar2(8),
iii. dated date.
9. Presume a trigger named update_sal_emp_tri is in scott schema. You need to delete this
database trigger from this schema. Which command can be used to remove this trigger? Try
creating a new trigger and delete it.
10. The OLD and NEW qualifiers can be used in which type of trigger? Give an example.
11. Create a row level BEFORE UPDATE trigger on the EMP table. This trigger contains a SELECT
statement on the EMP table to ensure that the new salary value falls within the minimum and
maximum salary for a given job title.
What happens when you try to update a salary value in the EMP table? Explain why this
trigger fails?
12. Write a stored procedure to populate the customer statistics table. Declare a cursor to query all
the customer last names, the traded date, and the total stock market value for the traded date.
Use a sub-query with a MAX (trade_date) function to guarantee the current stock market value
for the traded date. In the PL/SQL body, use the “FOR LOOP” statement to read the cursor
information one record at a time. Then insert the summary statistics data into the customer
statistics table. Use “commit” to save the transaction. In the exception section, add the “no data
found” exception and use the “dbms_output” package to display the error message. Add the
“invalid number” exception to detect any invalid input data into the insert command. Add the
“Others” exception to detect other problems. Always use the “others” exception in case you
miss some other exceptions. Then run your created procedure. Verify that your table was
populated.
13. Write a PL/SQL stored procedure to add a record into the department table (dept). You use
three input parameters to pass the department's columns (Department number “DEPTNO,”
department name “DNAME,” and department location “LOC”); and use one output parameter
to check the status of the insert transaction. You should use the Procedure Builder. Note that
you should use the "p_" prefix to name the parameters. You use this parameter as an output
parameter to check the status of your transaction. Use comments in your programs. Use double
dashes for a single line comment. And use “/*” ended with “*/” for a multiple lines comment. In
the “EXCEPITON” section, define the exception. Use the “duplicate value on index” exception,
the “invalid number” exception, and the “OTHERS” exception. Use the others in case you are
missing other exceptions.
14. Write a procedure to remove a department record. Make sure to define one input parameter
for the department number; and an output parameter as a status parameter. You will use this
parameter to test the status of the deleted transaction. In the PL/SQL body, delete the
department record where its department number matches with the input department number
parameter. Save the deleted transaction and assign "OK" to the status output parameter for a
successful deleted transaction.
(p_fname IN customers.first_name%TYPE,
p_lname IN customers.last_name%TYPE)
RETURN VARCHAR2
IS
No variables
BEGIN
EXCEPTION
Do nothing…
NULL;
END full_name;
16. Write a stored procedure to pass the table name and get back the number of records that table
contains. The SELECT statement must be created dynamically, since you don’t know what table
you are getting statistics from. You should write your function so that your client can display the
tables’ name, plus the number of records contained each table.
17. Write a PL/SQL block to populate the department table statistics into the “dept_stat” table for a
specific department.
Statistics Information:
The Department Number,
The total number of employees in each department,
The total salary paid in each department, and
The average salary paid in each department.
d:\users\temp>C:
c:>cd sqldeveloper
18.