本篇内容介绍了“怎么判断数据库集合的密集性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
我创建了这个工具函数来显示一个布尔型变量的值:
CREATE OR REPLACE PROCEDURE plch_bpl (val IN BOOLEAN) IS BEGIN DBMS_OUTPUT.put_line ( CASE val WHEN TRUE THEN 'TRUE' WHEN FALSE THEN 'FALSE' ELSE 'NULL' END); END plch_bpl; /
下列的选项中都包含了下面这个函数的实现代码:
CREATE OR REPLACE FUNCTION plch_is_dense (numbers_in IN DBMS_SQL.number_table) RETURN BOOLEAN
我写了另一个帮助过程来测试这个 plch_is_dense 函数:
CREATE OR REPLACE PROCEDURE plch_test_is_dense IS l_numbers DBMS_SQL.number_table; BEGIN l_numbers (1000) := 1; l_numbers (3000) := 1; plch_bpl (plch_is_dense (l_numbers)); l_numbers.delete; l_numbers (2) := 1; l_numbers (3) := 1; plch_bpl (plch_is_dense (l_numbers)); END; /
哪些选项创建的plch_is_dense使得plch_test_is_dense在执行之后会显示这两行文本?
FALSE TRUE
(A)
IS BEGIN RETURN numbers_in.COUNT = (numbers_in.LAST - numbers_in.FIRST); END;
(B)
IS l_number NUMBER; BEGIN FOR indx IN numbers_in.FIRST .. numbers_in.LAST LOOP l_number := numbers_in (indx); END LOOP; RETURN TRUE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN FALSE; END;
(C)
IS l_number NUMBER; BEGIN FOR indx IN 1 .. numbers_in.COUNT LOOP l_number := numbers_in (indx); END LOOP; RETURN TRUE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN FALSE; END;
(D)
IS BEGIN RETURN numbers_in.COUNT = (numbers_in.LAST - numbers_in.FIRST + 1); END;
运行结果如下
(A)
CREATE OR REPLACE FUNCTION plch_is_dense(numbers_in IN DBMS_SQL.number_table) RETURN BOOLEAN IS BEGIN RETURN numbers_in.COUNT =(numbers_in.LAST - numbers_in.FIRST); END; /
SQL> exec plch_test_is_dense; FALSE FALSE PL/SQL procedure successfully completed SQL>
(B)
CREATE OR REPLACE FUNCTION plch_is_dense(numbers_in IN DBMS_SQL.number_table) RETURN BOOLEAN IS l_number NUMBER; BEGIN FOR indx IN numbers_in.FIRST .. numbers_in.LAST LOOP l_number := numbers_in(indx); END LOOP; RETURN TRUE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN FALSE; END; /
SQL> exec plch_test_is_dense; FALSE TRUE PL/SQL procedure successfully completed SQL>
(C)
CREATE OR REPLACE FUNCTION plch_is_dense(numbers_in IN DBMS_SQL.number_table) RETURN BOOLEAN IS l_number NUMBER; BEGIN FOR indx IN 1 .. numbers_in.COUNT LOOP l_number := numbers_in(indx); END LOOP; RETURN TRUE; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN FALSE; END; /
SQL> exec plch_test_is_dense; FALSE FALSE PL/SQL procedure successfully completed SQL>
(D)
CREATE OR REPLACE FUNCTION plch_is_dense(numbers_in IN DBMS_SQL.number_table) RETURN BOOLEAN IS BEGIN RETURN numbers_in.COUNT =(numbers_in.LAST - numbers_in.FIRST + 1); END; /
SQL> exec plch_test_is_dense; FALSE TRUE PL/SQL procedure successfully completed SQL>
10-31答案BD. 对于非密集型的COLLECTION访问不能从1开始,而是要用FIRST方法。访问不存在的元素会引发NO_DATA_FOUND异常。
“怎么判断数据库集合的密集性”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。