"AS" 和 "IS" 在声明嵌套 table 类型时有什么区别?
What is difference between "AS" and "IS" at declaring nested table type?
所以,如果尝试这个匿名块:
DECLARE
TYPE nums IS TABLE OF integer;
nnum nums;
BEGIN
nnum := nums(1,2);
dbms_output.put_line( nnum.COUNT );
END;
这有效,但是当这里:TYPE nums IS TABLE OF
我将 IS
替换为 AS
,oracle 给出错误:
ORA-06550: Encountered the symbol "TABLE" when expecting ...
我在文档中看到,"AS" 和 "IS" 都在声明嵌套的 table 类型时使用。
甚至,from here To declare nested table types, use the CREATE TYPE ... AS TABLE OF statement
为什么我在使用 "AS" 时出错?这里有什么区别?
CREATE TYPE
不等于 PL/SQL 块中的类型声明。
type creation allows you to use AS
or IS
, but the PL/SQL type declaration's syntax only recognises the IS
[3].
AS
和 IS
在创建 PL/SQL 对象(如 函数、过程和包 [=31] 时是 同义词 =].但是,当您在 PL/SQL 块中声明嵌套的 table 类型时, 不是同义词 。
因此,就您在创建对象类型时使用的关键字而言,它们是同义词。当您创建 RECORD 类型 时,您会发现相同的区别,您只能使用 IS
而不能使用 AS
。
例如,您可以使用 AS
:
创建一个 OBJECT 类型
SQL> create type nums AS object
2 (
3 id integer
4 )
5 /
Type created.
SQL>
SQL> create type nnum AS table of nums
2 /
Type created.
SQL>
但是,如果您创建 RECORD 类型 或 在 PL/SQL 块 中声明它,同样会失败。
所以,如果尝试这个匿名块:
DECLARE
TYPE nums IS TABLE OF integer;
nnum nums;
BEGIN
nnum := nums(1,2);
dbms_output.put_line( nnum.COUNT );
END;
这有效,但是当这里:TYPE nums IS TABLE OF
我将 IS
替换为 AS
,oracle 给出错误:
ORA-06550: Encountered the symbol "TABLE" when expecting ...
我在文档中看到,"AS" 和 "IS" 都在声明嵌套的 table 类型时使用。
甚至,from here To declare nested table types, use the CREATE TYPE ... AS TABLE OF statement
为什么我在使用 "AS" 时出错?这里有什么区别?
CREATE TYPE
不等于 PL/SQL 块中的类型声明。
type creation allows you to use AS
or IS
, but the PL/SQL type declaration's syntax only recognises the IS
[3].
AS
和 IS
在创建 PL/SQL 对象(如 函数、过程和包 [=31] 时是 同义词 =].但是,当您在 PL/SQL 块中声明嵌套的 table 类型时, 不是同义词 。
因此,就您在创建对象类型时使用的关键字而言,它们是同义词。当您创建 RECORD 类型 时,您会发现相同的区别,您只能使用 IS
而不能使用 AS
。
例如,您可以使用 AS
:
SQL> create type nums AS object
2 (
3 id integer
4 )
5 /
Type created.
SQL>
SQL> create type nnum AS table of nums
2 /
Type created.
SQL>
但是,如果您创建 RECORD 类型 或 在 PL/SQL 块 中声明它,同样会失败。