gpt4 book ai didi

perl dbi : fetchrow_arrayref

转载 作者:行者123 更新时间:2023-12-02 17:54:17 26 4
gpt4 key购买 nike

实际上我已经执行了postgres查询,假设它返回了10行。现在我有了语句处理程序( $sth )。

print Dumper $sth->fetchrow_arrayref;
print Dumper $sth->fetchrow_arrayref;
print Dumper $sth->fetchrow_arrayref;
print Dumper $sth->fetchrow_arrayref;
print Dumper $sth->fetchrow_arrayref;

现在,我已经从语句处理程序中获取了 5 行( $sth 。现在我想返回$sth 指向第 1 行的引用指针......

我该怎么办......?

谢谢

最佳答案

你不能那样做。数据库游标设计为像流一样逐行读取,无需倒带。

如果要跳转,需要将数据复制到内存中的数组中。

最简单的方法是这样做

my $all_rows = $sth->fetchall_arrayref;

它为您提供一个 arrayref,每行一个条目,每行的格式与生成的 fetchrow_arrayref 相同。

关于perl dbi : fetchrow_arrayref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3995686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com