I have a module where I would like to take a given $dbh in DBI, and a given SQL statement, and programatically obtain the list of database objects (tables and views) that this query accesses. I could use SQL::Statement but I worry that I will need to support SQL syntax features that it doesn't (for example, subselects in the FROM clause). So I would like to somehow pass the statement to the database itself and get the information that way. For example, I would feed it
SELECT * FROM foo
JOIN bar ON foo.a = bar.a
JOIN (SELECT * FROM baz where something_or_other) as mysub1 ON foo.z =
+ mysub1.z
WHERE foo.b in (SELECT y+1 FROM quux)
and it would give me back a list like
('foo','bar','baz','quux')
My database is Oracle, so if no generic solution exists, I could happily live with an Oracle-specific one.
As an addendum, I should add that I also looked at using EXPLAIN PLAN and just querying the object names from the plan table, but I discovered that if my query uses views it would give me the underlying table names, whereas what I need are the view names.