Is it possible to create a stored procedure/function that returns records so that I can just call by the following query :
SELECT * FROM MyProcedure()
I know I can do this in SQL Server, but how to do this in Oracle ?
If it is impossible, what is your suggestion when you have a situation where you find queries that are duplicated across several caller and want to put them in 1 place to be reusable ?
Try creating a view. In a view you can have references to stored procedures if there is something that needs to be calculated and only a function will work. You can not select from a function. You can also create a stored procedure that returns a ref cursor.
Using Views is no option in our case since they can not accept parameters.
Calling stored proc. that returns a ref cursor needs more than 1 step which is impossible to apply because I need to put the function/stored proc in statement like Oracle MERGE.
If it is impossible, what is your suggestion when you have a situation where you find queries that are duplicated across several caller and want to put them in 1 place to be reusable ?
What I personally do is use Dynamic SQL. Instead of SELECT * FROM SomeFunc(), it becomes more like:
l_v_SQL := 'SELECT * FROM '||SomeBuildSQLFunc();
OPEN l_v_RefCur FOR l_v_SQL;
This has many advantages, including the ability to tweak the 'common' SQL in special cases. I can pass some parameters in that the function can act upon to modify the SQL for any special cases.
Bookmarks