Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Oracle Db Link Error ORA-01001: invalid cursor

by poj (Abbot)
on Jan 11, 2017 at 14:34 UTC ( #1179396=note: print w/replies, xml ) Need Help??


in reply to Re^4: Oracle Db Link Error ORA-01001: invalid cursor
in thread Oracle Db Link Error ORA-01001: invalid cursor

I would perhaps try running the first 2 queries and storing the results before running the 3rd query. As an example

#!perl use strict; use warnings; use DBI; my $localDB = _dbh(); # build list of ids my $sql1 = << 'SQL1'; SELECT ID FROM A_TEMP2 SQL1 my $sth1 = $localDB->prepare($sql1); $sth1->execute(); my $records = $sth1->fetchall_arrayref(); $sth1->finish; # build list of dblinks my $sql2 = << 'SQL2'; SELECT DBLINK FROM A_TEMP3 WHERE ID = ? SQL2 my $sth2 = $localDB->prepare($sql2); for (@$records){ my $id = $_->[0]; $sth2->execute($id); while ( (my $dblink) = $sth2->fetchrow_array() ){ push @{$_->[1]},$dblink; # many links per id } } $sth2->finish; # process each id-dblink pair for (@$records){ my $id = $_->[0]; for my $dblink (@{$_->[1]}){ my $sql3 = << "SQL3"; SELECT 1 FROM DUAL\@$dblink SQL3 my $sth3 = $localDB->prepare($sql3); if ($DBI::err){ print "Error with PREPARE for $dblink\n"; print $DBI::errstr."\n"; } else { $sth3->execute(); if ($DBI::err){ print "Error with EXECUTE for $dblink\n"; print $DBI::errstr."\n"; } else { my @f = $sth3->fetchrow_array; print "id=$id dblink=$dblink : @f\n"; } } } } $localDB->disconnect; sub _dbh { my $host = "hostname"; my $sid = 'sid'; my $user = 'user'; my $pwd = 'password'; my $dsn = "dbi:Oracle:host=$host;sid=$sid"; my $dbh = DBI->connect($dsn, $user, $pwd, { AutoCommit => 0, PrintError => 0, RaiseError => 0, TraceLevel => 0, # increase as req }) or die "$!"; return $dbh }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2021-09-28 23:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?