Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Custom Function Help Needed?
I am trying to create a function that will essentially "SUM" a string. Unfortunately the built in SUM function works only on numeric datatypes. I can't simply concat || values because the values I'm trying to aggregate aren't within a single row, but rather span multiple rows in a column.
As an example, imagine a query that is:
select region, sum(sales_rep) from foo group by region
I'd like this to return each region and the next cell should be a comma delimited list of all sales_reps in that particular region.
Region sum(sales_rep)
------ --------------
WEST Joe, Bill, Bob East Lisa, Steve, Mary
Only problem is that everything needs to be hardcoded in the function, particularly the input parameters. I'd like to simulate a dynamic group by here based on whatever other columns are in the select list for the query? Does anyone have a creative idea on this?
One idea I had (if this is possible) was that if I could dynamically send as a parameter to my custom function the full text of the select statement...then inside of the function, I could parse that statement to determine the appropriate level of grouping. But in order to do this (again, it has to be dynamic because I can't hard code the statement as I would like to use this function in different scenarios), I need some kind of keyword or variable that will allow me to feed in the sql statement as a parameter to the function) Additionally, the application is end-user driven...so I have no idea what the users will be querying (it's a decision support app where people will be drilling up/down and all around) .
If anyone has any creative ideas to this dilemma, I'd very much appreciate it if you could share your thoughts.
Thanks in advance,
Gavin