Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Dynamic SQL Select String VS non-dynamic USING Clause

PD81Sep 7 2009 — edited Sep 8 2009
This isn’t a question, I just wanted to share a solution to a problem I have encountered several times.

e.g. You have ‘n’ number of variables, of which any combination could be used in a SQL string. But it’s difficult to execute the SQL string with USING without an unpleasant CASE statement.

Solution: Reference all ‘n’ bind variables in the FROM clause of the SQL in an in-line-view. And specify all variables in the USING Clause.
When building the SQL String, specify the view.variable rather than directly referencing bind variables
This eliminates the requirement to check which variables have been populated.

-----
<h6>
t_select := ‘SELECT tab.cola, tab.colb’;

t_from := ‘FROM (SELECT :1 cola, :2 colb, :3 colc, :4 cold, :5 cole) parms, tablea tab’;

t_where := ‘WHERE tab.cola = parms.cola’;


OPEN c t_select||t_from||t_where USING v1, v2, v3, v4, v5;
</h6>
-----

I hope this is useful to someone...

PeteD
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 6 2009
Added on Sep 7 2009
1 comment
344 views