Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?
    [stevieb]: wtf!? lol
    [stevieb]: I'm checking some other versions. This is a little frightening
    [pryrt]: Sorry, my bad: it was't done downloading when I did the sha1sum... now I match your 309ad... value
    [stevieb]: I'll see how to get in touch with someone and advise that there's an issue. Thanks for helping me confiirm pryrt!

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (12)
    As of 2017-03-29 21:02 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Should Pluto Get Its Planethood Back?



      Results (353 votes). Check out past polls.