You can use the FORALL statement to Perform Batch INSERT, UPDATE, and DELETE operations in Oracle.
Syntax:
- -- Syntax 1:
- FORALL subscript variable (can only be referenced as subscript)INLower limit... Upper Limit
- SQL statement;-- Only one SQL statement is allowed.
- -- Syntax 2:
- FORALL subscript variableININDICESOF(Skip the element without a value assignment, for exampleDELETE,NULLValue) Set
- [BETWEENLower limitANDUpper Limit]
- SQL statement;
- -- Syntax 3:
- FORALL subscript variableIN VALUES OFSet (use the values in the set as subscript variables)
- SQL statement;
- Create TableTb1 (
- Id number (5 ),
- NameVarchar2 (50)
- );
Syntax 1 Demo:
- -- Batch insert demo
- Declare
- Type tb_table_typeIs Table OfTb1 % rowtype
- Index ByBinary_integer;
- Tb_table tb_table_type;
- Begin
- ForIIn1. 10 loop
- Tb_table (I). id: = I;
- Tb_table (I ).Name: ='Name'| I;
- EndLoop;
- Forall IIn1. tb_table.Count
- Insert IntoTb1ValuesTb_table (I );
- End;
- -- Batch modification demonstration
- Declare
- Type tb_table_typeIs Table OfTb1 % rowtype
- Index ByBinary_integer;
- Tb_table tb_table_type;
- Begin
- ForIIn1. 10 loop
- Tb_table (I). id: = I;
- Tb_table (I ).Name: ='Names'| I;
- EndLoop;
- Forall IIn1. tb_table.Count
- UpdateTb1 tSetRow = tb_table (I)WhereT. id = tb_table (I). id;
- End;
- -- Batch Delete demo
- Declare
- Type tb_table_typeIs Table OfTb1 % rowtype
- Index ByBinary_integer;
- Tb_table tb_table_type;
- Begin
- ForIIn1. 10 loop
- Tb_table (I). id: = I;
- Tb_table (I ).Name: ='Names'| I;
- EndLoop;
- Forall IIn1. tb_table.Count
- DeleteTb1WhereId = tb_table (I). id;
- End;
For more information about Oracle, see Oracle topics page http://www.bkjia.com/topicnews.aspx? Tid = 12