You should take a look at ref cursors.