使用 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 ;
}
最佳答案
cx_Oracle符合Python DB API 2.0 。因此它必须支持cursor.fetchone()
,它应该完全等于 Perl's fetchrow_array()
.
换句话说:cx_Oracle 只是数据库驱动程序,您与之交互的 API 是 Python DB API。
http://www.orafaq.com/wiki/Python应该可以帮助您开始使用 cx_Oracle。
关于python - Perl 到 Python 和 cx_Oracle、fetchrow_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751109/