Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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?


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

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




Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://973825]
Approved by Corion
[LanX]: maybe better /msg discipulus ?
[atcroft]: I thought I saw them on, and just wanted to let them know.
[LanX]: hmm ... or even better /msg /msg [discipulus]

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2018-02-24 20:39 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (311 votes). Check out past polls.