Chris,
thanks for your answer.
I thought I could remove much of the complexity from my question but, fair enough, here's the big picture:
I'm working in a spatial context.
I enter a sql statement in a third party software :
ex: select Pk, GEOM1 from table1
table1 contains two SDO_GEOMETRY fields :
GEOM1 and GEOM2
At runtime, third party software "completes" the query by wrapping my query in a subquery and adding a spatial where clause. Here's is the third party's log so you have a clear idea of whats happening :
SELECT * FROM (select Pk, GEOM1 from TABLE1
) VTABLE WHERE SDO_FILTER(GDO_GEOMETRY_S, ?, 'mask=anyinteract querytype=WINDOW') = 'TRUE'
Setting parameter 1 as MDSYS.SDO_GEOMETRY(2003,32198,NULL,MDSYS.SDO_ELEM_INFO_ARRAY(1,1003,3),MDSYS.SDO_ORDINATE_ARRAY(-372906.49583491014,786286.4324127169,-372233.6570917371,787207.4219100565))
Using value of parameter 1, I need to calculate the extent of the bbox. Depending on the result, I need to use GEOM1 or GEOM2 for the query.
There's probably another solution but from my research I'd go with a TABLE() function. That way I could build the resultset at runtime.
Query would be
select Pk, GEOM1 from TABLE(CustomFuntion())
The query launched by the third party would then be :
SELECT * FROM (select Pk, GEOM1 from TABLE(CustomFunction())
) VTABLE WHERE SDO_FILTER(GEOM1, ?, 'mask=anyinteract querytype=WINDOW') = 'TRUE'
I think that I could just alias the SDO_GEOMETRY field (AS GEOM1) to make it work.
While I was writing this response, I stumble upon this thread :
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9526156000346490143 Which is basically what I'm trying to achieve. I particularly like this line :
Depending on the level of interception etc, you might want to consider things at the database level ? eg RLS, sql translation, query rewrite, or advanced rewrite ?
Thanks