Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to DBI: Identify schema objects for a statement by Errto

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (17)
    As of 2014-10-30 17:39 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      For retirement, I am banking on:










      Results (208 votes), past polls