1

使用 Python 连接到 Oracle 时是否有等效于 perl fetchrow_array 的方法?

我实际上是在尝试将以下 perl 代码转换为 python 以与 cx_Oracle 一起使用...我需要创建键控字典来代替哈希,我猜(我根本不知道 perl),但首先我想将返回值转换为数组形式,以便我可以连接列。

# 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 ;
}
4

1 回答 1

3

cx_Oracle符合Python DB API 2.0。因此它必须支持cursor.fetchone(),这应该与Perl 的fetchrow_array().

换句话说:cx_Oracle 只是数据库驱动程序,您与之交互的 API 是 Python DB API。

http://www.orafaq.com/wiki/Python应该让您开始使用 cx_Oracle。

于 2012-12-06T19:43:11.643 回答