'How to Run group of Query with condition SQL Oracle
I was writing A SQL File containing different sections like the example below. On running whole file it should run the particular section if the input value is equal to section name:
Def input_var=1;
--//if condition to run 1,2,3 section as per input variable
-------------Section 1-------
--begin
update table1 Set status='RN' where status='IP';
Delete table1 where status='E';
update table2 Set status='RN' where status='IP';
Delete table2 where status='E';
--end
-------------Section 2-------
--begin
update table3 Set status='RN' where status='IP';
Delete table3 where status='E';
update table4 Set status='RN' where status='IP';
Delete table4 where status='E';
--end
..... multiple section
Solution 1:[1]
You got few options. Simplest might be to just if/else it:
BEGIN
IF ( section = 1 )
THEN
Update table1 Set status='RN' where status='IP';
Delete table1 where status='E';
Update table2 Set status='RN' where status='IP';
Delete table2 where status='E';
ELSIF( section = 2 )
THEN
Update table3 Set status='RN' where status='IP';
Delete table3 where status='E';
Update table4 Set status='RN' where status='IP';
Delete table4 where status='E';
ELSIF( section = 3 )
THEN
<code>
ELSE
<code>
END IF;
END;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gnqz |
