0% found this document useful (0 votes)
2 views

Efficient way to use Aggregate functions in Valueset

The document discusses a requirement to sum balance values using value sets, highlighting limitations such as character restrictions and the inability to use aggregate functions. It presents a common but inefficient solution involving hierarchical queries and proposes a more efficient method using lookup tables to improve performance and scalability. The new approach significantly reduced processing time for HCM Extracts from 7 hours to 15 minutes.

Uploaded by

ashish raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Efficient way to use Aggregate functions in Valueset

The document discusses a requirement to sum balance values using value sets, highlighting limitations such as character restrictions and the inability to use aggregate functions. It presents a common but inefficient solution involving hierarchical queries and proposes a more efficient method using lookup tables to improve performance and scalability. The new approach significantly reduced processing time for HCM Extracts from 7 hours to 15 minutes.

Uploaded by

ashish raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

I came across an interesting requirement where we had to get the summed-up balance values from

value sets instead of using the DBIs.

PFB my Analysis:

Limitations with value sets:


But Value sets have 2 major limitations:
1) The length of SELECT and FROM clauses are restricted to 240 characters
2) We cannot use aggregate functions

Commonly used solution:


Since we have to get the summed up balance value using a function, we cannot do it directly
because of the above restrictions.

WHERE clause has 4000 characters limit and we can call the balance value function there. But to
select that value, the common solution is to use a hierarchical query at the top to get values from 1
to say 99999 and match the value with the balance value.

Here is the link: https://community.oracle.com/thread/4196156


Eg:
SELECT value
FROM ( inline table using CONNECT_BY to generate values from
0 to 9999999) tab
WHERE tab.value = (SELECT SUM(balance_value) * 100
FROM xx
,yy
,zz
)

Why this solution is not performance efficient:


1) We cannot handle decimals directly, and hence we have to multiply the balance value by
100 to make it an integer and then match the value with the outer table.
2) We are dealing with the outer table (tab) that has 9999999 rows, to have an upper limit of
99999.99. In case of yearly dimensions, the limit may go up. So, this is not a scalable
solution.
3) HIERARCHICAL queries can cause performance issues.
Efficient Solution:
Since we are dealing with numbers here, each position can only have these values:
0,1,2,3,4,5,6,7,8,9, Decimal Point. We can create a lookup to hold these values

And here is the query to get the balance value:

SELECT a.lookup_code || b.lookup_code || c.lookup_code ||


d.lookup_code || e.lookup_code || f.lookup_code ||
g.lookup_code || h.lookup_code || i.lookup_code dat
FROM hr_lookups a
,hr_lookups b
,hr_lookups c
,hr_lookups d
,hr_lookups e
,hr_lookups f
,hr_lookups g
,hr_lookups h
,hr_lookups i
WHERE a.lookup_type = 'XXTRN_DIGITS'
AND b.lookup_type = 'XXTRN_DIGITS'
AND c.lookup_type = 'XXTRN_DIGITS'
AND d.lookup_type = 'XXTRN_DIGITS'
AND e.lookup_type = 'XXTRN_DIGITS'
AND f.lookup_type = 'XXTRN_DIGITS'
ANDg.lookup_type = 'XXTRN_DIGITS'
ANDh.lookup_type = 'XXTRN_DIGITS'
ANDi.lookup_type = 'XXTRN_DIGITS'
AND(a.lookup_code
,b.lookup_code
,c.lookup_code
,d.lookup_code
,e.lookup_code
,f.lookup_code
,g.lookup_code
,h.lookup_code
,i.lookup_code
) IN ( SELECT SUBSTR(bal_val_tb.bal_val, 1, 1)
,SUBSTR(bal_val_tb.bal_val, 2, 1)
,SUBSTR(bal_val_tb.bal_val, 3, 1)
,SUBSTR(bal_val_tb.bal_val, 4, 1)
,SUBSTR(bal_val_tb.bal_val, 5, 1)
,SUBSTR(bal_val_tb.bal_val, 6, 1)
,SUBSTR(bal_val_tb.bal_val, 7, 1)
,SUBSTR(bal_val_tb.bal_val, 8, 1)
,SUBSTR(bal_val_tb.bal_val, 9, 1)
FROM (SELECT LPAD(TO_CHAR(1000.12),9,'0')
bal_val /* replace with actual functions and tables to get the
required balance value */
FROM dual
) bal_val_tb
)

Why this solution is more Efficient:


1) We are not using hierarchical query and hence this approach would be faster than the
previous one.
2) We can increase the limit easily just by adding one more instance of the lookup table,
thereby making it scalable.
3) For a Customer, this approach reduced the HCM Extracts Run time from 7 hours to just 15
minutes!

You might also like