本篇內(nèi)容介紹了“怎么判斷數(shù)據(jù)庫集合的密集性”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!
10年積累的網(wǎng)站設計、網(wǎng)站建設經(jīng)驗,可以快速應對客戶對網(wǎng)站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡服務。我雖然不認識你,你也不認識我。但先建設網(wǎng)站后付款的網(wǎng)站建設流程,更有永昌免費網(wǎng)站建設讓你可以放心的選擇與我們合作。
我創(chuàng)建了這個工具函數(shù)來顯示一個布爾型變量的值:
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; /
下列的選項中都包含了下面這個函數(shù)的實現(xiàn)代碼:
CREATE OR REPLACE FUNCTION plch_is_dense (numbers_in IN DBMS_SQL.number_table) RETURN BOOLEAN
我寫了另一個幫助過程來測試這個 plch_is_dense 函數(shù):
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; /
哪些選項創(chuàng)建的plch_is_dense使得plch_test_is_dense在執(zhí)行之后會顯示這兩行文本?
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方法。訪問不存在的元素會引發(fā)NO_DATA_FOUND異常。
“怎么判斷數(shù)據(jù)庫集合的密集性”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!