BJCooperIT
Programmer
I have been trying to teach myself a bit about using PL/SQL tables. So, with the help of Google searches, I wrote a script to generate the days of the current month. This script correctly populates a PL/SQL table with 1 through 31 for October.
What I find confusing is that if I change the LIMIT to 31, I receive a "subscript beyond count" error. Since the cursor only returns 31 rows, why does the limit need to be larger?
Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: www.EmuProductsPlus.com
Code:
DECLARE
TYPE dom_tabtyp IS TABLE OF NUMBER;
dom_tab dom_tabtyp;
CURSOR get_days IS
SELECT ROWNUM
FROM all_objects
WHERE ROWNUM BETWEEN 1
AND to_char(last_day(SYSDATE),'dd');
BEGIN
-- Populate PL/SQL table
OPEN get_days;
LOOP
FETCH get_days BULK COLLECT INTO dom_tab LIMIT 10000;
EXIT WHEN get_days%NOTFOUND;
END LOOP;
CLOSE get_days;
-- Display Beginning and Ending Day with total # of rows
dopl(dom_tab(1) ||'-'||
dom_tab(dom_tab.COUNT) ||', rows='||
dom_tab.COUNT);
END;
/
OUTPUT: 1-31, rows=31
What I find confusing is that if I change the LIMIT to 31, I receive a "subscript beyond count" error. Since the cursor only returns 31 rows, why does the limit need to be larger?
Beware of false knowledge; it is more dangerous than ignorance. ~George Bernard Shaw
Consultant Developer/Analyst Oracle, Forms, Reports & PL/SQL (Windows)
My website: www.EmuProductsPlus.com