本篇内容介绍了“怎么判断数据库集合的密集性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!我创建了这个工具函
本篇内容介绍了“怎么判断数据库集合的密集性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
我创建了这个工具函数来显示一个布尔型变量的值:
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异常。
“怎么判断数据库集合的密集性”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!
--结束END--
本文标题: 怎么判断数据库集合的密集性
本文链接: https://lsjlt.com/news/63601.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0