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

oracle connection

by johnpat123 (Initiate)
on Jun 01, 2012 at 17:41 UTC ( #973825=perlquestion: print w/ replies, xml ) Need Help??
johnpat123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am trying to create a sub procedure which will connect to an oracle db and select some data. The issue is that the data it retrieves is different each time. Meaning the sql string changing based on the parameters passed into this procedure. so the following commented out 'while' line works, but it is hard coded. Is there a way to put a variavle in fetch whch can contain different variables each time?

$xxx = "$DBNAME,$USERNAME,$PROFILE";

#while (my ( $DBNAME,$USERNAME,$PROFILE )=$sth->fetchrow())

while (my ( '$xxx' )=$sth->fetchrow())

{

....

thanks!

Comment on oracle connection
Re: oracle connection
by Eliya (Vicar) on Jun 01, 2012 at 18:00 UTC

    You could put them in a hash. For example, pass the names to the routine (e.g. proc( [qw(foo bar)] )), and then say in the routine

    my $names = shift; ... @v{@$names} = $sth->fetchrow()

    (The @v{...} is a hash slice, which means you can assign multiple entries in one go.)

    You can then access the "variables" as $v{foo} and $v{bar}.

      You can also directly ask DBI to return you a hash:

      my $hash = $sth->fetchrow_hashref();

        Sure you can (presuming the query produces the desired column names).

        I was mainly trying to answer the general case, i.e. the typical "beginner's" problem of wanting to dynamically create variables like

        $xxx = "$DBNAME,$USERNAME,$PROFILE"; my ( '$xxx' ) = ( ... );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://973825]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-04-16 07:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (417 votes), past polls