FORALL statement in Oracle

Source: Internet
Author: User

You can use the FORALL statement to Perform Batch INSERT, UPDATE, and DELETE operations in Oracle.

Syntax:

  1. -- Syntax 1:
  2. FORALL subscript variable (can only be referenced as subscript)INLower limit... Upper Limit
  3. SQL statement;-- Only one SQL statement is allowed.
  4. -- Syntax 2:
  5. FORALL subscript variableININDICESOF(Skip the element without a value assignment, for exampleDELETE,NULLValue) Set
  6. [BETWEENLower limitANDUpper Limit]
  7. SQL statement;
  8. -- Syntax 3:
  9. FORALL subscript variableIN VALUES OFSet (use the values in the set as subscript variables)
  10. SQL statement;

 

  1. Create TableTb1 (
  2. Id number (5 ),
  3. NameVarchar2 (50)
  4. );

Syntax 1 Demo:

  1. -- Batch insert demo
  2. Declare
  3. Type tb_table_typeIs Table OfTb1 % rowtype
  4. Index ByBinary_integer;
  5. Tb_table tb_table_type;
  6. Begin
  7. ForIIn1. 10 loop
  8. Tb_table (I). id: = I;
  9. Tb_table (I ).Name: ='Name'| I;
  10. EndLoop;
  11. Forall IIn1. tb_table.Count
  12. Insert IntoTb1ValuesTb_table (I );
  13. End;
  14. -- Batch modification demonstration
  15. Declare
  16. Type tb_table_typeIs Table OfTb1 % rowtype
  17. Index ByBinary_integer;
  18. Tb_table tb_table_type;
  19. Begin
  20. ForIIn1. 10 loop
  21. Tb_table (I). id: = I;
  22. Tb_table (I ).Name: ='Names'| I;
  23. EndLoop;
  24. Forall IIn1. tb_table.Count
  25. UpdateTb1 tSetRow = tb_table (I)WhereT. id = tb_table (I). id;
  26. End;
  27. -- Batch Delete demo
  28. Declare
  29. Type tb_table_typeIs Table OfTb1 % rowtype
  30. Index ByBinary_integer;
  31. Tb_table tb_table_type;
  32. Begin
  33. ForIIn1. 10 loop
  34. Tb_table (I). id: = I;
  35. Tb_table (I ).Name: ='Names'| I;
  36. EndLoop;
  37. Forall IIn1. tb_table.Count
  38. DeleteTb1WhereId = tb_table (I). id;
  39. End;

For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12

Related Article

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.