As we all know (hopefully), we should always deploy named program units (procedures/functions) within packages. Its a great method of encapsulation of logic.
However, not many are aware that its not just procedures and functions that can have a public (package spec) and private (package body) component.
Cursors can also be defined in the same way as the following example shows:
CREATE PACKAGE my_pkg AS
CURSOR c_recent_hires RETURN emp%ROWTYPE;
...
END emp_stuff;
/
CREATE PACKAGE BODY my_pkg AS
CURSOR c_recent_hires RETURN emp%ROWTYPE IS
SELECT * FROM emp
WHERE hiredate > sysdate-30;
...
END emp_stuff;
/




Got some thoughts? Leave a comment