Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the deletion of database collection elements

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "how to understand the deletion of database collection elements". In daily operation, I believe many people have doubts about how to understand the deletion of database collection elements. Xiaobian consulted various materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "how to understand the deletion of database collection elements"! Next, please follow the small series to learn together!

I created a nested table type and procedure:

CREATE OR REPLACE TYPE plch_numbers_t IS TABLE OF NUMBER;/CREATE OR REPLACE PROCEDURE plch_show_numbers ( title_in IN VARCHAR2, numbers_in IN plch_numbers_t)ISBEGIN DBMS_OUTPUT.put_line (title_in); FOR rec IN (SELECT COLUMN_VALUE FROM TABLE (numbers_in)) LOOP DBMS_OUTPUT.put_line (rec.COLUMN_VALUE); END LOOP;END;/

The following options replace the/*BODY*/comments for the following code blocks:

DECLARE l_numbers plch_numbers_t := plch_numbers_t (12, 23, 34, 45, 56 , 67, 78, 89, 90, 100);BEGIN /*BODY*/ plch_show_numbers ('AFTER DELETE', l_numbers);END;/

Which options cause this block to display the following text when executed:

AFTER DELETE23456789

In other words, all even-numbered elements are deleted.

(A)

FOR indx IN 1 .. l_numbers.COUNTLOOP IF MOD (indx, 2) = 0 THEN l_numbers.delete (indx); END IF;END LOOP;SQL> DECLARE 2 l_numbers plch_numbers_t := plch_numbers_t(12, 3 23, 4 34, 5 45, 6 56, 7 67, 8 78, 9 89, 10 90, 11 100); 12 BEGIN 13 FOR indx IN 1 .. l_numbers.COUNT LOOP 14 IF MOD(indx, 2) = 0 THEN 15 l_numbers.delete(indx); 16 END IF; 17 END LOOP; 18 19 plch_show_numbers('AFTER DELETE', l_numbers); 20 END; 21 /AFTER DELETE1234567890PL/SQL procedure successfully completedSQL>

(B)

FOR indx IN 1 .. l_numbers.COUNTLOOP IF MOD (l_numbers (indx), 2) = 0 THEN l_numbers.delete (indx); END IF;END LOOP;SQL> DECLARE 2 l_numbers plch_numbers_t := plch_numbers_t(12, 3 23, 4 34, 5 45, 6 56, 7 67, 8 78, 9 89, 10 90, 11 100); 12 BEGIN 13 FOR indx IN 1 .. l_numbers.COUNT LOOP 14 IF MOD(l_numbers(indx), 2) = 0 THEN 15 l_numbers.delete(indx); 16 END IF; 17 END LOOP; 18 19 plch_show_numbers('AFTER DELETE', l_numbers); 20 END; 21 /AFTER DELETE23456789PL/SQL procedure successfully completedSQL>

(C)

DELETE FROM TABLE (l_numbers) WHERE MOD (index_value, 2) = 0;SQL> DECLARE 2 l_numbers plch_numbers_t := plch_numbers_t(12, 3 23, 4 34, 5 45, 6 56, 7 67, 8 78, 9 89, 10 90, 11 100); 12 BEGIN 13 DELETE FROM TABLE(l_numbers) WHERE MOD(index_value, 2) = 0; 14 15 plch_show_numbers('AFTER DELETE', l_numbers); 16 END; 17 /DECLARE l_numbers plch_numbers_t := plch_numbers_t(12, 23, 34, 45, 56, 67, 78, 89, 90, 100); BEGIN FROM TABLE(l_numbers) WHERE MOD(index_value, 2) = 0; plch_show_numbers ('AFTER Deleted ', l_numbers);END;ORA-06550: Line 13, Column 15: PL/SQL: ORA-00903: Invalid Table Name ORA-06550: Line 13, Column 3: PL/SQL: SQL Statement ignoredSQL>

(D)

FOR rec IN (SELECT * FROM TABLE (l_numbers) WHERE MOD (COLUMN_VALUE, 2) = 0)LOOP l_numbers.delete (rec.COLUMN_VALUE);END LOOP;SQL> DECLARE 2 l_numbers plch_numbers_t := plch_numbers_t(12, 3 23, 4 34, 5 45, 6 56, 7 67, 8 78, 9 89, 10 90, 11 100); 12 BEGIN 13 FOR rec IN (SELECT * FROM TABLE(l_numbers) WHERE MOD(COLUMN_VALUE, 2) = 0) LOOP 14 l_numbers.delete(rec.COLUMN_VALUE); 15 END LOOP; 16 17 plch_show_numbers('AFTER DELETE', l_numbers); 18 END; 19 /AFTER DELETE122334455667788990100PL/SQL procedure successfully completedSQL>

The actual answer is B.

At this point, the study of "how to understand the deletion of database collection elements" is over, hoping to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report