共计 4027 个字符,预计需要花费 11 分钟才能阅读完成。
这篇文章主要介绍“怎么使用 CONSTANT 变量与 INDEX BY 数组”,在日常操作中,相信很多人在怎么使用 CONSTANT 变量与 INDEX BY 数组问题上存在疑惑,丸趣 TV 小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么使用 CONSTANT 变量与 INDEX BY 数组”的疑惑有所帮助!接下来,请跟着丸趣 TV 小编一起来学习吧!
我创建了如下包头:
CREATE OR REPLACE PACKAGE plch_pkg
AUTHID DEFINER
TYPE names_t IS TABLE OF VARCHAR2 (20)
INDEX BY PLS_INTEGER;
END plch_pkg;
/
哪些选项在执行之后会显示 3 ?
(A)
DECLARE
l_names CONSTANT plch_pkg.names_t
:= plch_pkg.names_t (Horton , Hears , A Who) ;
BEGIN
DBMS_OUTPUT.put_line (l_names.COUNT);
/
SQL DECLARE
2 l_names CONSTANT plch_pkg.names_t
3 := plch_pkg.names_t (Horton , Hears , A Who) ;
4 BEGIN
5 DBMS_OUTPUT.put_line (l_names.COUNT);
6 END;
7 /
DECLARE
l_names CONSTANT plch_pkg.names_t
:= plch_pkg.names_t (Horton , Hears , A Who) ;
BEGIN
DBMS_OUTPUT.put_line (l_names.COUNT);
ORA-06550: 第 3 行, 第 10 列:
PLS-00222: 在此范围中不存在名为 NAMES_T 的函数
ORA-06550: 第 2 行, 第 14 列:
PL/SQL: Item ignored
ORA-06550: 第 5 行, 第 26 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 5 行, 第 4 列:
PL/SQL: Statement ignored
SQL
(B)
DECLARE
l_names CONSTANT plch_pkg.names_t
:= plch_pkg.names_t () ;
BEGIN
l_names (1) := Horton
l_names (2) := Hears
l_names (3) := A Who
DBMS_OUTPUT.put_line (l_names.COUNT);
/
SQL DECLARE
2 l_names CONSTANT plch_pkg.names_t
3 := plch_pkg.names_t () ;
4 BEGIN
5 l_names (1) := Horton
6 l_names (2) := Hears
7 l_names (3) := A Who
8 DBMS_OUTPUT.put_line (l_names.COUNT);
9 END;
10 /
DECLARE
l_names CONSTANT plch_pkg.names_t
:= plch_pkg.names_t () ;
BEGIN
l_names (1) := Horton
l_names (2) := Hears
l_names (3) := A Who
DBMS_OUTPUT.put_line (l_names.COUNT);
ORA-06550: 第 3 行, 第 29 列:
PLS-00222: 在此范围中不存在名为 NAMES_T 的函数
ORA-06550: 第 2 行, 第 14 列:
PL/SQL: Item ignored
ORA-06550: 第 5 行, 第 4 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 5 行, 第 4 列:
PL/SQL: Statement ignored
ORA-06550: 第 6 行, 第 4 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 6 行, 第 4 列:
PL/SQL: Statement ignored
ORA-06550: 第 7 行, 第 4 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 7 行, 第 4 列:
PL/SQL: Statement ignored
ORA-06550: 第 8 行, 第 26 列:
PLS-00320: 此表达式的类型声明不完整或格式不正确
ORA-06550: 第 8 行, 第 4 列:
PL/SQL: Statement ignored
SQL
(C)
CREATE OR REPLACE FUNCTION plch_dr_seuss_names
RETURN plch_pkg.names_t
l_return plch_pkg.names_t;
BEGIN
l_return (1) := Horton
l_return (2) := Hears
l_return (3) := A Who
RETURN l_return;
END plch_dr_seuss_names;
DECLARE
l_names CONSTANT plch_pkg.names_t
:= plch_dr_seuss_names () ;
BEGIN
DBMS_OUTPUT.put_line (l_names.COUNT);
/
SQL CREATE OR REPLACE FUNCTION plch_dr_seuss_names
2 RETURN plch_pkg.names_t
3 IS
4 l_return plch_pkg.names_t;
5 BEGIN
6 l_return (1) := Horton
7 l_return (2) := Hears
8 l_return (3) := A Who
9 RETURN l_return;
10 END plch_dr_seuss_names;
11 /
Function created
SQL DECLARE
2 l_names CONSTANT plch_pkg.names_t
3 := plch_dr_seuss_names () ;
4 BEGIN
5 DBMS_OUTPUT.put_line (l_names.COUNT);
6 END;
7 /
PL/SQL procedure successfully completed
SQL
(D)
CREATE OR REPLACE FUNCTION plch_dr_seuss_names (
name1_in IN VARCHAR2
, name2_in IN VARCHAR2
, name3_in IN VARCHAR2)
RETURN plch_pkg.names_t
l_return plch_pkg.names_t;
BEGIN
l_return (1) := name1_in;
l_return (2) := name2_in;
l_return (3) := name3_in;
RETURN l_return;
END plch_dr_seuss_names;
DECLARE
l_names CONSTANT plch_pkg.names_t
:= plch_dr_seuss_names (Horton , Hears , A Who) ;
BEGIN
DBMS_OUTPUT.put_line (l_names.COUNT);
/
SQL CREATE OR REPLACE FUNCTION plch_dr_seuss_names (
2 name1_in IN VARCHAR2
3 , name2_in IN VARCHAR2
4 , name3_in IN VARCHAR2)
5 RETURN plch_pkg.names_t
6 IS
7 l_return plch_pkg.names_t;
8 BEGIN
9 l_return (1) := name1_in;
10 l_return (2) := name2_in;
11 l_return (3) := name3_in;
12 RETURN l_return;
13 END plch_dr_seuss_names;
14 /
Function created
SQL DECLARE
2 l_names CONSTANT plch_pkg.names_t
3 := plch_dr_seuss_names (Horton , Hears , A Who) ;
4 BEGIN
5 DBMS_OUTPUT.put_line (l_names.COUNT);
6 END;
7 /
PL/SQL procedure successfully completed
SQL
答案 CD. ORACLE 只对嵌套表 (NESTED TABLE) 和可变数组 (VARRAY) 提供构造函数 (constructor function), ASSOCIATED ARRAY (即 INDEX BY 表) 则没有这个构造函数,必须采用自定义函数。常量在声明的部分必须赋值,不能够在块中赋值。
到此,关于“怎么使用 CONSTANT 变量与 INDEX BY 数组”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注丸趣 TV 网站,丸趣 TV 小编会继续努力为大家带来更多实用的文章!
正文完