j*****g 发帖数: 223 | 1 【 以下文字转载自 Linux 讨论区 】
【 原文由 jinfeng 所发表 】
in mysql or postgresql i have vast amount of records (rows) in a table
WHAT I WANT:
each time fetch one record(row) back.
i vaguely know there exists something called "cursor," can any
big shrimp explain a little bit?
WHAT I DON'T WANT:
use select * from the table, then traverse the result row by row.
the table has too many rows, i guess using select * will hamper
the performance. tell me if my guess is wrong
//bow 100times! :) | D****N 发帖数: 430 | 2 BEGIN trTransaction; /* cursor only valid in transactions */
DECLARE curMyCursor CURSOR
FOR SELECT * FROM tMyTable;
FETCH FORWARD 1 IN curMyCursor; /* fetch first row */
FETCH NEXT IN curMyCursor; /* fetch next row */
/* and so on */
CLOSE curMyCursor;
COMMIT trTransaction;
See synopsis of FETCH statement for postgresql...
http://www.se.postgresql.org/docs/postgres/sql-fetch.htm
Don't think mysql has cursor (and transaction) functions :(
【在 j*****g 的大作中提到】 : 【 以下文字转载自 Linux 讨论区 】 : 【 原文由 jinfeng 所发表 】 : in mysql or postgresql i have vast amount of records (rows) in a table : WHAT I WANT: : each time fetch one record(row) back. : i vaguely know there exists something called "cursor," can any : big shrimp explain a little bit? : WHAT I DON'T WANT: : use select * from the table, then traverse the result row by row. : the table has too many rows, i guess using select * will hamper
|
|