我想创建一个模式级别的 VARRAY,以便我可以将它作为输入参数传递到过程中
I want to create a VARRAY that is on the schema level, so that I can pass it as an input parameter into a procedure
这是我一直在尝试的-
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;
/
但我一直收到这个错误-
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
它是一个缺少的斜杠,它终止了 CREATE TYPE
语句:
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>
或者,您甚至不必声明自己的类型 - 使用 Oracle 中已经内置的类型:sys.odcivarchar2list
(如果没有最后一个 'a'
,您可以已使用 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>
在新行用斜杠替换第一个分号就足够了:
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;
/
这是我一直在尝试的-
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;
/
但我一直收到这个错误-
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
它是一个缺少的斜杠,它终止了 CREATE TYPE
语句:
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>
或者,您甚至不必声明自己的类型 - 使用 Oracle 中已经内置的类型:sys.odcivarchar2list
(如果没有最后一个 'a'
,您可以已使用 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>
在新行用斜杠替换第一个分号就足够了:
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;
/