문제

Is there an equivalent to the perl fetchrow_array when connecting to Oracle using Python?

I am essentially trying to translate the following perl code into python for use with cx_Oracle... I need to create keyed dictionaries in place of the hash, I'm guessing (I don't know perl really at all), but first I would like to put the return into array form so that I can concatenate the columns.

# read the data and place into a species hash (sphash) and a data hash (tmphash)
my (@lnarr, %sphash, %tmphash, $tmpln, $tmpsel, $x, $datetime) ;
while (@lnarr = $csr->fetchrow_array) {
 # $line =~ s/\s//g ;  #remove spaces and newline character
 # @lnarr = split /,/, $line ;
  $datetime = $lnarr[4].'-'.$lnarr[5] ;
  $tmpln = join '_', $lnarr[8], $lnarr[9] ;
  $sphash{$lnarr[7]} = 'x';
  $tmphash{$lnarr[0].'_'.$lnarr[1].'_'.$lnarr[2].'_'.$lnarr[3].'_'.$datetime.'_'.$lnarr[6]}{$lnarr[7]} .= $tmpln ;
}
도움이 되었습니까?

해결책

cx_Oracle conforms to the Python DB API 2.0. Therefore it must support cursor.fetchone(), which should be the exact equivalent to Perl's fetchrow_array().

In other words: cx_Oracle is just the database driver, the API you interact with is the Python DB API.

http://www.orafaq.com/wiki/Python should get you started using cx_Oracle.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top