怎么判断数据库集合的密集性
短信预约 -IT技能 免费直播动态提醒
本篇内容介绍了“怎么判断数据库集合的密集性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
我创建了这个工具函数来显示一个布尔型变量的值:
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异常。
“怎么判断数据库集合的密集性”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341