Is there a way to select/fill an Oracle Collection ("IS TABLE OF") in a normal select from jdbc i.e. no procedure with declared variable for bulk collect or anonymous block in Oracle12c?
The problems is selecting objects with collection of objects since I can't find a way to fill the collection and therefore it puts every object in a separate collection instead of collecting them in one (i.e., "a single-row query returned more than one row").
Long Story: Most of out services/apis have dynamic search parameters and then they are translated to SQL statements.
A java code does parse the limited "search/where", sanitize and parameterize them then select an objects from oracle, so in most of the time it execute much faster than oracle's hard parse, however i can't find a solution for filling objects with list of objects.
The current work around is calling procedures and leaving them to do bulk collect in declared objects then returning them, however because of the dynamic nature of the "search" clause most of them do EXECUTE IMMEDIATE which is quite heavy for CPU of the database.
Other solutions such as multiple queries per every row to fetch it's list or left join and fetch everything in single ResultSet
just increase the time exponentially, since the fetches are for usually for huge number of columns, rows and nested lists :<
CREATE OR REPLACE TYPE SUB_TYPE_OBJ Force AS OBJECT
(
SVAR1 VARCHAR2(100 CHAR);
SVAR2 DATE,
SVAR3 VARCHAR2(100 CHAR)
);
CREATE OR REPLACE TYPE SUB_TYPE_LST IS TABLE OF SUB_TYPE_OBJ;
CREATE OR REPLACE TYPE MAIN_TYPE_OBJ Force AS OBJECT
(
MVAR1 VARCHAR2(100 CHAR),
MVAR2 VARCHAR2(100 CHAR),
MVAR3 SUB_TYPE_OBJ,
MVAR4 SUB_TYPE_LST
);
SELECT MAIN_TYPE_OBJ (
tab1.val1,
tab1.val2,
(SELECT SUB_TYPE_OBJ( table2.val1, table2.val2, table2.val3) obj FROM table2 WHERE tab1.val1 = tab2.val1),
(SUB_TYPE_LST ( (SELECT SUB_TYPE_OBJ( table3.val1, table3.val2, table3.val3) obj FROM table3 DYNAMIC_WHERE_WITH_LIMITED_FUNCTIONALITY)))
/* if it return more than one row everything breaks :( */
), CNT
FROM (
SELECT table1.*, COUNT(*) OVER(table1.val1) AS CNT FROM table1
WHERE DYNAMIC_WHERE_WITH_LIMITED_FUNCTIONALITY
ORDER BY val1 ASC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) tab1;
if table3 returns more than one row we get the "a single-row query returned more than one row" because I'm just creating a bunch of lists instead of one containing all objects, but I cant figure out how to do it;
Any ideas are appreciated, but please exclude DBMS_SQL or NoSQL for now :).