在SQL Developer上运行时,下面的代码下面的代码不会提供精确的输出。 而不是给出此输出:
Index 3 exists but no value assigned.
它给了我:
Index 3 does not exist.
我不相信 - 它如何与所说的上述语句不匹配。
DECLARE
TYPE nt_type IS TABLE OF NUMBER;
nt nt_type := nt_type(10, 20, 30, 40, 50);
BEGIN
DBMS_OUTPUT.PUT_LINE('Before DELETE: Count = ' || nt.COUNT); -- Output: 5
nt.DELETE(3); -- Deletes the 3rd element (value 30)
DBMS_OUTPUT.PUT_LINE('After DELETE: Count = ' || nt.COUNT); -- Output: 4
IF nt.EXISTS(3) THEN
DBMS_OUTPUT.PUT_LINE('Index 3 exists but no value assigned.');
ELSE
DBMS_OUTPUT.PUT_LINE('Index 3 does not exist.');
END IF;
-- Display all elements including sparse indexes
FOR i IN 1..nt.LAST LOOP
IF nt.EXISTS(i) THEN
DBMS_OUTPUT.PUT_LINE('Element at index ' || i || ' = ' || COALESCE(TO_CHAR(nt(i)), 'NULL'));
END IF;
END LOOP;
END;
/
指望输出:
Before DELETE: Count = 5
After DELETE: Count = 4
Index 3 exists but no value assigned.
Element at index 1 = 10
Element at index 2 = 20
Element at index 3 = NULL
Element at index 4 = 40
Element at index 5 = 50
MySQL开发人员输出
Before DELETE: Count = 5
After DELETE: Count = 4
Index 3 does not exist.
Element at index 1 = 10
Element at index 2 = 20
Element at index 4 = 40
Element at index 5 = 50
.extend
方法。但是,一旦您到达从未分配过的位置,您就无法不先将其分配给它,因为这就是分配内存的原因。