FORALL
Description
The
FORALLstatement runs one DML statement multiple times, with different values in theVALUESandWHEREclauses. (Oracle PL/SQL Language Reference FORALL Statement).
FORALL index IN bounds_clause [ SAVE ] [ EXCEPTIONS ] dml_statement ;Snowflake Scripting has no direct equivalence with the FORALL statement, however can be emulated with different workarounds to get functional equivalence.
Sample Source Patterns
Setup Data
Oracle
CREATE TABLE table1 (
column1 NUMBER,
column2 NUMBER
);
INSERT INTO table1 (column1, column2) VALUES (1, 2);
INSERT INTO table1 (column1, column2) VALUES (2, 3);
INSERT INTO table1 (column1, column2) VALUES (3, 4);
INSERT INTO table1 (column1, column2) VALUES (4, 5);
INSERT INTO table1 (column1, column2) VALUES (5, 6);
CREATE TABLE table2 (
column1 NUMBER,
column2 NUMBER
);
INSERT INTO table2 (column1, column2) VALUES (1, 2);CREATE TABLE error_table (
ORA_ERR_NUMBER$ NUMBER,
ORA_ERR_MESG$ VARCHAR2(2000),
ORA_ERR_ROWID$ ROWID,
ORA_ERR_OPTYP$ VARCHAR2(2),
ORA_ERR_TAG$ VARCHAR2(2000)
);
--departments
CREATE TABLE parent_table(
Id INT PRIMARY KEY,
Name VARCHAR2(10)
);
Insert into parent_table values (10, 'IT');
Insert into parent_table values (20, 'HR');
Insert into parent_table values (30, 'INFRA');
--employees
CREATE TABLE source_table(
Id INT PRIMARY KEY,
Name VARCHAR2(20) NOT NULL,
DepartmentID INT REFERENCES parent_table(Id)
);
INSERT into source_table VALUES (101, 'Anurag111111111', 10);
INSERT into source_table VALUES (102, 'Pranaya11111111', 20);
INSERT into source_table VALUES (103, 'Hina11111111111', 30);
--a copy of source
CREATE TABLE target_table(
Id INT PRIMARY KEY,
Name VARCHAR2(10) NOT NULL,
DepartmentID INT REFERENCES parent_table(Id)
);
INSERT into target_table VALUES (101, 'Anurag', 10);Snowflake
1. FORALL With Collection of Records
Oracle
The three cases below have the same transformation to Snowflake Scripting and are functionally equivalent.
Snowflake
2. FORALL With INSERT INTO
Oracle
Snowflake
3. FORALL With Multiple Fetched Collections
Oracle
Snowflake
4. FORALL With Record of Collections
Oracle
Snowflake
5. FORALL With Dynamic SQL
Oracle
Snowflake
6. FORALL With Literal SQL
Oracle
Snowflake
7. FORALL With Parametrized Cursors
Oracle
Snowflake
8. FORALL Without LOOPS
Oracle
Snowflake
9. FORALL With UPDATE Statements
Oracle
Snowflake
10. FORALL With DELETE Statements
Oracle
Snowflake
11. FORALL With PACKAGE References
Oracle
Snowflake
The transformation above only works if the variable defined in the package is a record of collections.
12. FORALL With MERGE Statements
Oracle
Snowflake
The transformation above only works if the SELECT statement inside the MERGE is selecting from DUAL table.
13. Default FORALL transformation
Oracle
Snowflake
14. Multiple FORALL inside a LOOP clause
Oracle
Snowflake
15. Multiple FORALL inside different LOOP clauses
Oracle
Snowflake
16. FORALL with MERGE INTO with LOG ERRORS
This pattern is not yet implemmented
Oracle
Snowflake
17. FORALL with INSERT with LOG ERRORS
This pattern is not yet implemmented
Oracle
Snowflake
Related EWIs
Last updated
Was this helpful?