PL/SQL 問題澄清(2)
这个基础问题,您可以选对么,如下:
我创建了如下包头:
CREATE OR REPLACE PACKAGE plch_pkg
AUTHID DEFINER
IS
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);
END;
/
(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);
END;
/
(C)
CREATE OR REPLACE FUNCTION plch_dr_seuss_names
RETURN plch_pkg.names_t
IS
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);
END;
/
(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
IS
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);
END;
答案:CD
解释:ORACLE只对嵌套表(NESTED TABLE)和可变数组(VARRAY)提供构造函数(constructor function), ASSOCIATED ARRAY (即INDEX BY表)则没有这个构造函数,必须采用自定义函数。常量在声明的部分必须赋值,不能够在块中赋值。