I want to grab a count of distinct ASN_NO's from my query to later check in my stored procedure if i find more than one and throw an error.
Instead of trying to open the cursor(which i was also failing at doing properly), i thought maybe i could do it with temp table selects and store the value while i'm populating the cursor. Maybe this isn't possible, but my error makes no sense to me.
Here is my simplified code, i broke the count statement out to identify better where exactly the error was.
V_ASN_COUNT NUMBER;
OPEN O_CURSOR FOR
WITH O_LIST AS(
SELECT *
FROM AN_ORDER_INFO OI, AN_SHIPMENT_INFO SI
-- where bunch of stuff
),
COUNT_ASN_NO AS (
SELECT COUNT(DISTINCT ASN_NO) AS "ASN_COUNT"
FROM O_LIST
),
SAVE_ASN_COUNT AS (
SELECT ASN_COUNT
INTO V_ASN_COUNT
FROM COUNT_ASN_NO -- error on this line, not enough values, its just 1:1, i dont get it?
)
SELECT * FROM O_LIST;
IF(V_ASN_COUNT > 1) THEN
RAISE MULTIPLE_ASNS;
END IF;
Or perhaps i need to open the cursor afterwards and do something like this, except i know this is wrong, i get "expecting BULK INTO" error:
OPEN O_CURSOR;
LOOP
FETCH COUNT(DISTINCT ASN_NO) INTO V_ASN_COUNT;
EXIT WHEN ASN_NO%NOTFOUND;
END LOOP;
CLOSE O_CURSOR;