题目:
我执行了这些语句:
CREATE OR REPLACE TYPE plch_numbers_nt IS TABLE OF NUMBER;
/
CREATE OR REPLACE TYPE plch_numbers_vat IS VARRAY (10) OF NUMBER;
/
CREATE OR REPLACE PACKAGE plch_pkg
IS
TYPE plch_numbers_nt IS TABLE OF NUMBER;
END;
/
CREATE OR REPLACE TYPE plch_numbers_aat IS TABLE OF NUMBER
INDEX BY PLS_INTEGER;
/
然后我写了如下的不完整代码块:
DECLARE
l_count PLS_INTEGER;
l_numbers /*TYPE*/ := /*TYPE*/ (1, 2, 3, 4, 5);
BEGIN
SELECT COUNT (COLUMN_VALUE)
INTO l_count
FROM TABLE (l_numbers);
DBMS_OUTPUT.put_line (l_count);
END;
/
哪些选项可用来取代 /*TYPE*/ 注释,从而使得代码块执行之后会显示"5"?
(A)
plch_numbers_nt
(B)
plch_numbers_vat
(C)
plch_pkg.plch_numbers_nt
(D)
plch_numbers_aat
答案:
A: plch_numbers_nt是在SCHEMA级别定义的嵌套表类型(NESTED TABLE)所以可被SQL引擎识别并用TABLE()函数转换为表
B: plch_numbers_vat是在SCHEMA级别定义的可变数组类型(VARRAY)所以可被SQL引擎识别并用TABLE()函数转换为表
C: plch_pkg.plch_numbers_nt是在包级别定义的,无法被SQL引擎识别
D: 关联数组只能在PLSQL中使用,实际上plch_numbers_aat不能成功创建,会报错:
SQL> CREATE OR REPLACE TYPE plch_numbers_aat IS TABLE OF NUMBER
2 INDEX BY PLS_INTEGER;
3 /
Warning: Type created with compilation errors.
Elapsed: 00:00:04.76
SQL> SHOW ERR
Errors for TYPE PLCH_NUMBERS_AAT:
LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 PL/SQL: Compilation unit analysis terminated
1/26 PLS-00355: use of pl/sql table not allowed in this context