I have some tables with the same structure and I want to make a select in a group of them.
Rather than just making a loop to all of those tables, I would like to put a subquery after the FROM of the main query.
Is it possible or it will fail?
Thanks!
(Using Oracle)
Additional info: I don’t have the name of the table right away! They’re stored in another table. Is it possible to have a subquery that I could put after the FROM of my main query?
Oracle doesn’t do this sort of thing in SQL. You’ll need to use PL/SQL and assemble a dynamic query.
This will assemble a query like this
The UNION ALL is a set operator which combines the output of several queries in a single result set without removing duplicates. The columns in each query must match in number and datatype.
Because the generated statement will be executed automatically there’s no real value in formatting it (unless the actual bits of the query are more complicated and you perhaps need to debug it).
Ref Cursors are PL/SQL contructs equivalent to JDBC or .Net ResultSets. Find out more.