代码之家  ›  专栏  ›  技术社区  ›  Pavunkumar

perl-dbi:fetchrow_arrayref

  •  1
  • Pavunkumar  · 技术社区  · 14 年前

    实际上我已经执行了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;
    

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

    谢谢

    3 回复  |  直到 14 年前
        1
  •  4
  •   Thilo    14 年前

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

    最简单的方法就是

    my $all_rows = $sth->fetchall_arrayref;
    

    fetchrow_arrayref 产生。

        2
  •  1
  •   Sinan Ünür    14 年前

    while 循环。

    1. 取行。
    2. 每当要引用上一行时,请参考保存列表。
        3
  •  0
  •   benzebuth    14 年前

    另一种处理查询结果的方法是循环遍历:

    while(my $res = $sth->fetchrow_arrayref()) {do something}