I'm working on a school project and am having issues getting my program to work. The biggest bottleneck I have right now is that an array assignment is giving me a PLS-00330 error.
SET SERVEROUTPUT ON SIZE UNLIMITED
SET VERIFY OFF
DECLARE
lv_input1 VARCHAR2(100);
lv_input2 VARCHAR2(100);
lv_input3 VARCHAR2(100);
list VARCHAR2(300);
type lv_strings is varray(3) of varchar2(300);
COUNT NUMBER;
xnum NUMBER;
xdate DATE;
xstring VARCHAR2(30);
BEGIN
--count := 1;
lv_strings(1) := '&1';
lv_strings(2) := '&2';
lv_strings(3) := '&3';
--TYPE list IS TABLE OF VARCHAR2(300);
FOR i IN 1..lv_strings.COUNT LOOP
IF REGEXP_LIKE(lv_strings(i),'^[[:digit:]]*$') OR
REGEXP_LIKE(lv_strings(i),'^[0-9]{2,2}-[[:alpha:]]{3,3}-([0-9]{2,2}|[0-9]{4,4})$') OR
REGEXP_LIKE(lv_strings(i),'^[[:alnum:]]*$') THEN
xnum := lv_strings(i);
END IF;
END LOOP;
--dbms_output.put_line('[' xnum '] ' '[' xstring '] ' '[' xdate ']');
dbms_output.put_line(xnum);
END;
/
SPOOL OFF
QUIT;
CodePudding user response:
Several problems going on here. 1) you were trying to use lv_strings as a variable, but it is a type. I changed the declaration, so now ls_strings_typ is the type, and lv_strings is a variable of that type. 2) lv_strings then needs a constructor. 3) lv_strings needs elements allocated
DECLARE
lv_input1 VARCHAR2(100);
lv_input2 VARCHAR2(100);
lv_input3 VARCHAR2(100);
list VARCHAR2(300);
type lv_strings_typ is varray(3) of varchar2(300); --1
COUNT NUMBER;
xnum NUMBER;
xdate DATE;
xstring VARCHAR2(30);
lv_strings lv_strings_typ := lv_strings_typ(); -- 1,2
BEGIN
--count := 1;
lv_strings.EXTEND (3); --3
lv_strings(1) := '&1';
CodePudding user response:
lv_strings
is a collection type. You'd need to declare a local variable of that type that would actually store data. You'd need to initialize that local collection. And then you'd need to extend
it. This compiles (no idea if it actually does what you want since you haven't told us what it is supposed to do)
DECLARE
lv_input1 VARCHAR2(100);
lv_input2 VARCHAR2(100);
lv_input3 VARCHAR2(100);
list VARCHAR2(300);
type lv_strings is varray(3) of varchar2(300);
l_strings lv_strings := new lv_strings();
COUNT NUMBER;
xnum NUMBER;
xdate DATE;
xstring VARCHAR2(30);
BEGIN
--count := 1;
l_strings.extend(3);
l_strings(1) := '&1';
l_strings(2) := '&2';
l_strings(3) := '&3';
--TYPE list IS TABLE OF VARCHAR2(300);
FOR i IN 1..l_strings.COUNT LOOP
IF REGEXP_LIKE(l_strings(i),'^[[:digit:]]*$') OR
REGEXP_LIKE(l_strings(i),'^[0-9]{2,2}-[[:alpha:]]{3,3}-([0-9]{2,2}|[0-9]{4,4})$') OR
REGEXP_LIKE(l_strings(i),'^[[:alnum:]]*$') THEN
xnum := l_strings(i);
END IF;
END LOOP;
--dbms_output.put_line('[' xnum '] ' '[' xstring '] ' '[' xdate ']');
dbms_output.put_line(xnum);
END;
/
Personally, I can't think of a time that I'd want to use a varray
rather than a nested table or an associative array. But maybe you're just learning all the collection types.