-
Select against functions or procedures
Hi all,
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 ?
Any help would be greatly appreciated.
Best Regards,
Setya
-
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.
-
Select against functions of procedures
Hi,
Thanks for your suggestions.
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.
Regards,
Setya
-
But you can use a where clause on a view.
So make sure that what ever you are filtering by is in a column.
-
Originally Posted by Setya
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|