"Johnson, Shaunn" <[EMAIL PROTECTED]> writes: > Howdy: > > Can someone give me an example of using > place holders with the DBI module? > > I am trying to use the results of one query > and embed that into another query later. For > example: the result of the first query > (say, select distinct user_name from t_table) > should go into the second (say select table_owner, > table_columns, table_def from master_table where > table_owner = ? ). > > But I don't know exactly *how* the list from the > first query gets passed down to the place > holder '?'. > > I'm still working on the script - right now, I > can do either part independently, but I don't know > how to pass the results from one to the other. > I was hoping the place holder feature in the DBI > module could help. > > Suggestions? Thanks!
Hrm. Well, assuming you've looked under 'Placeholders and Bind Values' in `perldoc DBI`, here's your example, assuming you've already got a '$dbh': my $query =<<EOQ; SELECT table_owner, table_columns, table_def FROM master_table WHERE table_owner = ? AND table_columns <= ? EOQ my $sth = $dbh->prepare($query); $sth->execute('Bill', 32); while (my ($owner, $columns, $def) = $sth->fetchrow) { # ...whatever... } So this should get all of the tables owned by 'Bill' with 32 or fewer columns. When the query is run, the question marks are replaced by the params to 'execute', in order. The technical details are best left to perldoc DBI - if you haven't read it, do so now...you'll be glad you did. -RN -- Robin Norwood Red Hat, Inc. "The Sage does nothing, yet nothing remains undone." -Lao Tzu, Te Tao Ching -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]