定义一个游标
begin;
DECLARE tbase_cur SCROLL CURSOR FOR SELECT * from tbase ORDER BY id;
注意:
游标需要放在一个事务中使用
提取下一行数据
FETCH NEXT from tbase_cur ;
id | nickname |
1 | hello TBase |
FETCH NEXT from tbase_cur ;
id | nickname |
2 | TBase 好 |
提取前一行数据
FETCH PRIOR from tbase_cur ;
id | nickname |
1 | hello TBase |
FETCH PRIOR from tbase_cur ;
提取最后一行
FETCH LAST from tbase_cur ;
id | nickname |
5 | TBase swap |
提取第一行
FETCH FIRST from tbase_cur ;
id | nickname |
1 | hello TBase |
提取该查询的第 x 行
FETCH ABSOLUTE 2 from tbase_cur ;
id | nickname |
2 | TBase 好 |
FETCH ABSOLUTE -1 from tbase_cur ;
id | nickname |
5 | TBase swap |
提取当前位置后的第 x 行
FETCH ABSOLUTE 1 from tbase_cur ;
id | nickname |
1 | hello TBase |
FETCH RELATIVE 2 from tbase_cur ;
id | nickname |
3 | TBase 好 |
向前提取 x 行数据
FETCH FORWARD 2 from tbase_cur ;
id | nickname |
1 | hello TBase |
2 | TBase 好 |
FETCH FORWARD 2 from tbase_cur ;
id | nickname |
3 | TBase 好 |
4 | TBase default |
向前提取剩下的所有数据
FETCH FORWARD all from tbase_cur ;
id | nickname |
3 | TBase 好 |
4 | TBase default |
5 | TBase swap |
向后提取 x 行数据
FETCH BACKWARD 2 from tbase_cur ;
id | nickname |
5 | TBase swap |
4 | TBase default |
向后提取剩下的所有数据
FETCH BACKWARD all from tbase_cur ;
id | nickname |
3 | TBase 好 |
2 | TBase 好 |
1 | hello TBase |