python - Perl 到 Python 和 cx_Oracle、fetchrow_array

标签 python oracle perl cx-oracle

使用 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/

相关文章:

python - 沿着 dim1 追踪 max,并在 dim3 中改变索引

python - 匹配来自两个单独文件的行

oracle - 如何使用 Oracle.ManagedDataAccess.EntityFramework 提供程序从不同架构中选择表?

java - Hibernate 在从注解创建表时不会创建索引

c - semget : how to avoid concurrent access to semaphore group on its creating/initialization?

multithreading - Perl 线程 - 捕获退出

python - df.mean() 和 df ['column' ].mean() 结果的差异

python - Pygubu 从 UI 文件加载新窗口

oracle - 未找到 javax.xml.ws.WebServiceException : Provider com. sun.xml.internal.ws.spi.ProviderImpl

ruby - Perl 和 Ruby 模块在同一个存储库中?