Skip to content
Advertisement

FOR loop in Oracle SQL or Apply SQL to multiple Oracle tables

My SQL is a bit rusty, so I don’t know whether the following is even possible:

I have multiple tables t_a, t_b, t_c with the same column layout and I want to apply the same operation to them, namely output some aggregation into another table. For a table t_x this would look like this:

I now want to execute something like a FOR loop around this:

Is this possible in SQL? Or would I need to build a wrapper in another language for this?

Advertisement

Answer

For the FOR loop you need to use PL/SQL like this:(*)

Look also at this SO question: How to use Oracle PL/SQL to create…

(*) @Littlefoot describes in the 2nd part of his answer valuable background to this program.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement