Delete type is table type in Oracle

Source: Internet
Author: User

Recently, I encountered a problem in writing the stored procedure. I always encountered an error when using batch data insertion. It was said that the uniqueness constraint was violated. Finally, I checked the stored procedure and found that the type table data was not deleted. The stored procedure is as follows:

  1. Type type_char2 is table of NVARCHAR2 (30) index by binary_integer; -- defines the temporary table type of a string
  2. V_card_id type_char2;
  3. -- The following is a cursor.
  4. Cursor cur_bt_data is
  5. Select * from test ....;
  6. -- Traversal cursor
  7. For bt_row in cur_bt_data loop
  8. For I in 1 .. bt_row.confirm_quanlity loop
  9. V_card_id (I):=To_number(Bt_row.iccid_start) + I-1;
  10. End loop;
  11. Forall I in 1 .. v_card_id.count
  12. Insert/* + append */
  13. Into demo
  14. (Card_id ,....)
  15. Values
  16. (V_card_id (I ),...);
  17. Commit;
  18. End loop; -- [END] for 'cur _ bt_data'

V_card_id (I) in the query is found. If the number of bt_row.confirm_quanlity queried is the same, the data should be reinitialized. If the number is different, for example, the number of the previous query is large, the number of the next time is small. If v_card_id is not initialized, duplicate results may appear. All temporary tables must be cleared in each loop.

After checking the relevant information, you only need to useV_card_id.deleteDelete the temporary table.

Modify as follows:

  1. For bt_row in cur_bt_data loop
  2. V_card_id.delete;
  3. For I in 1 .. bt_row.confirm_quanlity loop
  4. ..........

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.