本篇内容介绍了“怎么判断数据库集合的密集性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
10年积累的网站设计、网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先建设网站后付款的网站建设流程,更有永昌免费网站建设让你可以放心的选择与我们合作。
我创建了这个工具函数来显示一个布尔型变量的值:
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异常。
“怎么判断数据库集合的密集性”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!