PLSQL Language Referenc-PL/SQL集合和記錄-使用Multiset Conditions比較巢狀表

LuiseDalian發表於2014-03-12

使用Multiset Conditions比較巢狀表

可以使用SQL Multiset Conditions來比較巢狀表和測試它們的屬性。

DECLARE

    TYPE nested_typ IS TABLE OF NUMBER;

    nt1 nested_typ := nested_typ(1,2,3); nt2 nested_typ := nested_typ(3,2,1);

    nt3 nested_typ := nested_typ(2,3,1,3); nt4 nested_typ := nested_typ(1,2,4);

   PROCEDURE testify (truth BOOLEAN := NULL, quantity NUMBER := NULL) IS

    BEGIN

        IF truth IS NOT NULL THEN

            DBMS_OUTPUT.PUT_LINE (

            CASE truth

                WHEN TRUE THEN 'True'

                WHEN FALSE THEN 'False'

            END);

        END IF;

        IF quantity IS NOT NULL THEN DBMS_OUTPUT.PUT_LINE(quantity); END IF;

  END;

BEGIN

    testify(truth => (nt1 IN (nt2, nt3, nt4)));        -- 條件

    testify(truth => (nt1 SUBMULTISET OF nt3));      -- 條件

testify(truth => (nt1 NOT SUBMULTISET OF nt4));  -- 條件

--測試集合成員的個數

    testify(truth => (4 MEMBER OF nt1));             -- 條件

    testify(truth => (nt3 IS A SET));                -- 條件

    testify(truth => (nt3 IS NOT A SET));            -- 條件

    testify(truth => (nt1 IS EMPTY));                -- 條件

    -- cardinality返回巢狀表中元素的個數

    testify(quantity => (CARDINALITY(nt3)));         -- 函式

    testify(quantity => (CARDINALITY(SET(nt3))));    -- 2個函式

END;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17013648/viewspace-1107995/,如需轉載,請註明出處,否則將追究法律責任。

相關文章