Skip to Main Content

APEX

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!

Report based on selection criteria in an Apex collection

Tony AndrewsSep 12 2007 — edited Sep 19 2007

For my current page I have to deal with a horrible "EAV" (Entity-Attribute-Value) table design like this:

Employee ---< Attribute Value >-- Attribute

So you might query who works in dept 10 and earns 20000 and was hired om 01-Jan-2007 like this:

select emp.ename
from emp
join attribute_value a1 on a1.empno = emp.empno and a1.att_name = 'DEPT'
join attribute_value a2 on a2.empno = emp.empno and a2.att_name = 'SALARY'
join attribute_value a3 on a3.empno = emp.empno and a3.att_name = 'HIREDATE'
where a1.att_numeric_value = 10
and   a2.att_numeric_value = 20000
and   a3.att_date_value = date '2007-01-01';

(I said it was horrible!)

But to make matters worse, the form for entering query criteria is also based on the attributes table as a tabular form:

select apex_item.display_and_save(1,att_name) att_name
,      apex_item.text(2,null) att_value
from   attributes
where  att_type = 'EMPLOYEE';

The user may enter values for any number of attributes and run the query. So in my example, there maybe be 0, 1, 2 or 3 criteria to use (or more when new attributes are added to the table).

I can code the report query as a "PL/SQL body returning SQL query" and build a SQL string exactly like my example above - all literal values. Is there any way I could do it that uses bind variables? Given the variable number of bind variables I think I'd need to use DBMS_SQL, but would I be able to integrate that into an Apex report region source? Or is there another way?

I'm open to any suggestions! (Except "redesign the database": much as I'd like to, I can't.)

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2007
Added on Sep 12 2007
10 comments
1,197 views