Given a declared PLSQL Procedure
PROCEDURE GET_DISTINCT_TIMES(dtypes IN VARCHAR2, start IN NUMBER, end IN NUMBER
distinct_times_cursor OUT SYS_REFCURSOR)
Where:
- 'Dtypes' is a comma delimited string, with each value corresponding to a general type of data I want to retrieve. One data type may correspond to one or many different tables where distinct times need to be retrieved
- 'Start' & 'End' are the two times I am querying between
I have written implementations that dynamically create the SQL using Unions to pull out only unique time values from each table. However, due to the dynamic nature of the 'Dtypes' argument, I am forced to generate this SQL in a loop control, and have not been able to figure a way to implement bind variables.
I believe that losing the benefit of bind variables may have caused the queries to take longer than necessary
So I am wondering, is there a way to either:
- Associate bind variables with a dynamically created SQL string when the number of bind variables is completely variable with the arguments passed in to the procedure.
- Take a different approach, where for each dtype - execute another stored procedure, or SQL Statement, store the recordset for each query, then merge the unique results and assign a cursor to the new results
Admittedly, I am quite new with PLSQL programming and haven't had the opportunity yet to grab a good reference/book on the language. Any comments, insights, or suggested readings would be appreciated too.