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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

dynamic statement in where clause???

DeclanBMar 3 2010 — edited Mar 3 2010
Hi all,

I am writing a procedure and the query will be different based on the input parameters.

I'm wondering how I can do this inside the where clause? simplified example

select *
from tableA a, tableB b
where a.id = b.id
/* if input parameter = 'abc' then */
and a.total = b.total
/* if input parameter = 'xyz' then */
and a.total != b.total

I was thinking case statement but from what i read it cannot be used in this situation

Thanks
This post has been answered by 728534 on Mar 3 2010
Jump to Answer

Comments

L. Fernigrini

Consider using PL/Scope

PL/Scope Enhancements in Oracle Database 12c Release 2 (12.2) (0 Bytes)It is simpler than parsing code.

User_RI4C6

How its work I admit that I am a beginner in the world of plsql and I told myself that it is possible to do it with regexp

User_H3J7U

it can be for example standard package, ULT_HTTP
UTL_HTTP Constants

L. Fernigrini

undefined (0 Bytes)You need to set some session settings like this:

ALTER SESSION SET PLSCOPE_SETTINGS='IDENTIFIERS:ALL, STATEMENTS:ALL';

Then compile the package, and then query the dictionary tables being populated when you compile PL/SQL and have set PLSCOPE settings.
In the article I mentioned there is an example :
image.pnghere you would see that variable L_NUM and L_STR are declared on lunes 6 and 7, and that they reference the NUMBER and CHARACTER datatypes. You can modify the query in the example to filter only "VARIABLE" as TYPE; "DECLARATION" as USAGE and then get the associated REFERENCE row to get the datatype.

L. Fernigrini

Poster mentioned ANY package, documentation exists only for Oracle provided packages.

User_RI4C6

Wow very cool, Thank you very much for the help.!

1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 31 2010
Added on Mar 3 2010
5 comments
542 views