Suppose you have a table (in Oracle):
CREATE TABLE CUSTOMER
(
customer_id NUMBER,
gender CHAR(1)
);
And suppose you have a table type:
CREATE TYPE NUMBER_TABLE_TYPE AS TABLE OF NUMBER;
Is it possible to write a GROUP BY
query such that, for each group, that group's primary key fields are stored in a NUMBER_TABLE_TYPE
? For example:
DECLARE
CURSOR gender_cursor IS
SELECT
gender,
/* The CUSTOMER_IDS column will be of type NUMBER_TABLE_TYPE: */
SOME_MAGICAL_AGGREGATE_FUNCTION(customer_id) AS customer_ids
FROM
CUSTOMER
GROUP BY
gender;
customer_ids NUMBER_TABLE_TYPE;
BEGIN
FOR gender IN gender_cursor LOOP
customer_ids := gender.customer_ids;
FOR i IN customer_ids.FIRST .. customer_ids.LAST LOOP
dbms_output.put_line(customer_ids(i));
END LOOP;
END LOOP;
END;
I know that this should be accomplished by having two cursors (one for the gender group, and another that queries each group's customers). I am just curious to see if this can be done. :)