1

This is what I have been trying-

create or replace type persons_list is varray(10) of varchar(1) not null;

Declare
peoplesList persons_list := persons_list(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a');

Begin
dbms_output.put_line('hello');

End;
/

but I keep getting this error-

Type PERSONS_LIST compiled

LINE/COL  ERROR
--------- -------------------------------------------------------------
3/1       PLS-00103: Encountered the symbol "DECLARE" 
10/0      PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:     ( begin case declare end exception exit for goto if loop mod    null pragma raise return select update while with    <an identifier> <a double-quoted delimited-identifier>    <a bind variable> << continue close current delete fetch lock    insert open rollback savepoint set sql execute commit forall    merge pipe purge 
Errors: check compiler log
Littlefoot
  • 131,892
  • 15
  • 35
  • 57

2 Answers2

0

It is a missing slash, which terminates the CREATE TYPE statement:

SQL> create or replace type persons_list is varray(10) of varchar(1) not null;
  2  /                   --> this is what you are missing

Type created.

SQL> Declare
  2  peoplesList persons_list := persons_list(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a');
  3
  4  Begin
  5  dbms_output.put_line('hello');
  6
  7  End;
  8  /
hello

PL/SQL procedure successfully completed.

SQL>

Alternatively, you don't even have to declare your own type - use one already built-in into Oracle: sys.odcivarchar2list (if there weren't for the last 'a', you could have used sys.odcinumberlist):

SQL> Declare
  2  peoplesList sys.odcivarchar2list := sys.odcivarchar2list(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a');
  3
  4  Begin
  5  dbms_output.put_line('hello');
  6
  7  End;
  8  /
hello

PL/SQL procedure successfully completed.

SQL>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57
0

It is enought to replase first semicolon with a slash at a new line:

create or replace type persons_list is varray(10) of varchar(1) not null
/
Declare
    peoplesList persons_list := persons_list(1, 2, 3, 4, 5, 6, 7, 8, 9, 'a');
Begin
    dbms_output.put_line('hello');
End;
/
Sergey Afinogenov
  • 2,137
  • 4
  • 13