Here's the problem.
I created a stored procedure that took in a number of parameters. Those parameters were then checked to see if they contained the value of "ALL". If they did they were basically disregarded in the WHERE clause of the SELECT statement being created (by using the DECODE function).
The procedure is being used now in production but it is sloppy and my boss would like it cleaned up and commented so that others can use it as a sort of template.
This is what happens in the procedure:
[ol]
[li]Declare all internal variables
[li]Check parameters for relevance (discussed above)
[li]Select into a variable to get the TOTAL num of results
[li]Open a ref cursor to SELECT the results I currently want...
There are 3 SELECT statements nested here...
[ol]
[li]<<INNERMOST>> Same SELECT statement used to get total number of results
[li]<<INNER>> Wraps the previous and throws in ROWNUM in the SELECT portion to get count of records (1 - ?)
[li]<<OUTTER>> This one wraps the previous and takes ROWNUM values of 2 specified parameters (page_size and current_page)
[/ol]
[li]The cursor is a ref cursor so it is returned to the caller
[/ol]
What I want to do is reuse the initial SELECT statement instead of retyping it... seems very inefficient.
Is there anyway to Open a CURSOR... throw the primary SELECT statement into it.
Use cursor_name%ROWCOUNT ... I know that would work to find total results. But I would like to know if I could use the cursor as the FROM source for that later nastier SELECT statement?
Any comments are eager anticipated!! THANKS MUCH.
I hope this helped! ;-)
- Casey Winans
I created a stored procedure that took in a number of parameters. Those parameters were then checked to see if they contained the value of "ALL". If they did they were basically disregarded in the WHERE clause of the SELECT statement being created (by using the DECODE function).
The procedure is being used now in production but it is sloppy and my boss would like it cleaned up and commented so that others can use it as a sort of template.
This is what happens in the procedure:
[ol]
[li]Declare all internal variables
[li]Check parameters for relevance (discussed above)
[li]Select into a variable to get the TOTAL num of results
[li]Open a ref cursor to SELECT the results I currently want...
There are 3 SELECT statements nested here...
[ol]
[li]<<INNERMOST>> Same SELECT statement used to get total number of results
[li]<<INNER>> Wraps the previous and throws in ROWNUM in the SELECT portion to get count of records (1 - ?)
[li]<<OUTTER>> This one wraps the previous and takes ROWNUM values of 2 specified parameters (page_size and current_page)
[/ol]
[li]The cursor is a ref cursor so it is returned to the caller
[/ol]
What I want to do is reuse the initial SELECT statement instead of retyping it... seems very inefficient.
Is there anyway to Open a CURSOR... throw the primary SELECT statement into it.
Use cursor_name%ROWCOUNT ... I know that would work to find total results. But I would like to know if I could use the cursor as the FROM source for that later nastier SELECT statement?
Any comments are eager anticipated!! THANKS MUCH.
I hope this helped! ;-)
- Casey Winans