您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么判斷數據庫集合的密集性”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
我創建了這個工具函數來顯示一個布爾型變量的值:
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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。