10-10. Deleting a Record from a Collection
Problem
You need to randomly select employees from a collection. Using a random generator may select the same employee more than once, so you need to remove the record from the collection before selecting the next employee.
Solution
Invoke the built-in DELETE
method on the collection. For example, the following code creates a collection of employees and then randomly selects one from the collection. The selected employee is removed from the collection using the DELETE
method. This process is repeated until three employees have been selected.
DECLARE
CURSOR driver IS
SELECT last_name
FROM employees;
TYPE rec_type IS TABLE OF driver%ROWTYPE INDEX BY BINARY_INTEGER;
recs rec_type; j INTEGER; ...
Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.