PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

FETCH

劉䓄

FETCH -- 䫘橩湺傯昖臵婺檷埡臯

臺濘

FETCH [ direction { FROM | IN } ] cursorname

認麯 direction 埇傖婺䷺潡蔙婋彖幋婔

    NEXT
    PRIOR
    FIRST
    LAST
    ABSOLUTE count
    RELATIVE count
    count
    ALL
    FORWARD
    FORWARD count
    FORWARD ALL
    BACKWARD
    BACKWARD count
    BACKWARD ALL

柟誄

FETCH 嘪䫘橩湺演䘵臯㔗

婔婻橩湺橬婔婻䫌 FETCH 嘪䫘䔇䕩噿蕫䔇嘉䘞㔗橩湺䔇嘉䘞埇傖婘昖臵䂷悩䔇丸婔臯幋嬉潡蔙婘䂷悩婺䔇傂懟臯潡蔙婘䂷悩䔇橔劯婔臯幋劯㔗彔录傺垯幋劯橩湺滇櫆婘丸婔臯幋嬉䔇㔗婘檷埡庖婔底臯幋劯橩湺櫆婘演䘵彄䔇橔劯婔臯婪㔗套悩 FETCH 檷垯庖欔橬埇䫘臯闼幽垄儌啩婘橔劯婔臯劯麵潡蔙婘埉劏檷寂䔇愙喕婋滇啩婘丸婔臯嬉麵㔗FETCH ALLFETCH BACKWARD ALL 儖攂滇檪橩湺䔇嘉䘞櫆婘橔劯婔臯潡蔙婘丸婔臯嬉麵㔗

NEXT, PRIOR, FIRST, LAST, ABSOLUTE, RELATIVE 嘵嚟婘敄嘷婄䓂媘橩湺幋劯檷埡婔婻臯㔗套悩澇橬昄扞臯庖闼幽誫啂婔婻䷺䔇䂷悩溴施橩湺儌嚔啩婘昖臵䂷悩䔇橔劯婔臯幋劯潡蔙丸婔臯幋嬉㔗

FORWARDBACKWARD 嘵嚟婘劏嬉潡蔙劏劯䓂媘䔇誺䘋婺檷埡毺垔䔇臯昄䇽劯檪橩湺垔嘉婘橔劯誫啂䔇臯婪潡蔙滇套悩 count 崓庯埇䫘䔇臯昄彍婘欔橬臯幋嬉潡幋劯㔗

RELATIVE 0, FORWARD 0, BACKWARD 0 鄘襕挗婘婉䓂媘橩湺䔇嬉柊婋檷埡嘷嬉臯幘儌滇麉桄檷埡橔誏彔彔檷埡誺䔇臯㔗鍴麂橩湺垔嘉婘丸婔臯幋嬉潡蔙橔劯婔臯幋劯認婻媘嘩鄘庫臖潊媘蔯婘闼婴䓉愙喕婋婉誫啂傂嘘臯㔗

埗昄

direction

垔幬檷埡䔇桹劏启檷埡䔇臯昄㔗垄埇傖滇婋誄幋婔

NEXT

檷埡婋婔臯(䚺䩕)

PRIOR

檷埡嬉麵婔臯

FIRST

檷埡昖臵䔇丸婔臯(启 ABSOLUTE 1 䕩劯)

LAST

檷埡昖臵䔇橔劯婔臯(启 ABSOLUTE -1 䕩劯)

ABSOLUTE count

檷埡昖臵婺丸 count 臯潡蔙套悩 count 婺蘘儌傯昖臵䂷悩橆儆檷埡丸 abs(count) 臯㔗套悩 count 轙庺庖评啘闼幽垔嘉婘丸婔臯幋嬉启橔劯婔臯幋劯䔇嘉䘞䬹彆滇 ABSOLUTE 0 垔嘉婘丸婔臯幋嬉㔗

RELATIVE count

檷埡锟劯䔇丸 count 臯潡蔙套悩 count 婺蘘儌檷埡嬉麵䔇丸 abs(count) 臯㔗套悩橬昄扞䔇臺RELATIVE 0 麉桄檷埡嘷嬉臯㔗

count

檷埡锟劯䔇 count 臯(启 FORWARD count 婔湙)

ALL

檷埡欔橬嬷嘍䔇臯(启 FORWARD ALL 婔湙)

FORWARD

檷埡婋婔臯(启 NEXT 婔湙)

FORWARD count

檷埡锟劯䔇 count 臯㔗FORWARD 0 麉桄檷埡嘷嬉臯㔗

FORWARD ALL

檷埡欔橬嬷嘍臯

BACKWARD

檷埡嬉麵婔臯(启 PRIOR 婔湙)

BACKWARD count

檷埡嬉麵䔇 count 臯(劏劯欆柟)㔗BACKWARD 0 麉桄檷埡嘷嬉臯㔗

BACKWARD ALL

檷埡欔橬嬉麵䔇臯(劏劯欆柟)

count

count 埇脘滇婔婻橬严埙䔇昘昄婩麟喿垔襕檷埡䔇臯昄启桹劏㔗凹庯 FORWARDBACKWARD 䔇愙喕弄滯婔婻婥蘘埙䔇 count 京昽庯櫹埻 FORWARDBACKWARD 䔇桹劏㔗

cursorname

婔婻欷嚔䔇橩湺䔇劉䓄

膷庺

潊媘垯潊施婔婻 FETCH 变傴誫啂婔婻嘵套婋麵䔇湺螄

FETCH count

認麯䔇 count 滇檷埡䔇臯昄(埇脘滇镽)㔗臙濘懟婘 psql 麯变傴湺了垂鍙婪婉嚔滆䴺啹婺 psql 䫘檷埡䔇臯昄傼敪庖㔗

濘懟

套悩嘹愿嘪䫘 FETCH NEXT 幋崡䔇傂嘘 FETCH 埻䓉潡蔙滇婥蘘昄螇昄䔇 FETCH FORWARD 㔗闼幽垔幬橩湺䔇施唍庫臖婥婪 SCROLL 锬釹㔗凹庯䞔剘䔇昖臵PostgreSQL 嚔噕螩闼底澇橬婥 SCROLL 锬釹垔幬䔇橩湺幘埇傖埉劏檷埡嘖滇橔喘婉襕冺蕡認婻臯婺㔗套悩橩湺垔幬庖 NO SCROLL 闼幽婉噕螩埉劏檷埡㔗

ABSOLUTE 檷埡婉嚔懫䫘䕩凹嘉䓂䓂媘彄驔襕䔇昄扞臯敘媆啹婺婋北䔇垂䯄媙釂镉寖欔橬婺閘䔇臯㔗蘘昄䔇䂺凹檷埡䫔躿敘俘俘昖臵媙釂婔䕘臂彄䂷儆欉脘欆彄橔劯婔臯䇽劯傯闼麯嚔哋埉劏镉寖㔗婉誺啂锔彄昖臵嚔崘(懫套 FETCH ABSOLUTE 0)冽媆㔗

婘橩湺婺敘桄昄扞誻婉赆 PostgreSQL 櫇毕㔗

嘪䫘 DECLARE 臺埖垔幬婔婻橩湺㔗MOVE 臺埖櫹埻橩湺嘉䘞蔯婉演䘵昄扞㔗

冋床

婋麵䔇冋床䫘婔婻橩湺虘誺婔婻臘㔗

BEGIN WORK;

-- 傺䆋婔婻橩湺:
DECLARE liahona SCROLL CURSOR FOR SELECT * FROM films;

-- 檷埡崘5臯彄橩湺liahona麯:
FETCH FORWARD 5 FROM liahona;

 code  |          title          | did | date_prod  |   kind   |  len
-------+-------------------------+-----+------------+----------+-------
 BL101 | The Third Man           | 101 | 1949-12-23 | Drama    | 01:44
 BL102 | The African Queen       | 101 | 1951-08-11 | Romantic | 01:43
 JL201 | Une Femme est une Femme | 102 | 1961-03-12 | Romantic | 01:25
 P_301 | Vertigo                 | 103 | 1958-11-14 | Action   | 02:08
 P_302 | Becket                  | 103 | 1964-02-03 | Drama    | 02:28

-- 檷埡嬉麵臯:
FETCH PRIOR FROM liahona;

 code  |  title  | did | date_prod  |  kind  |  len
-------+---------+-----+------------+--------+-------
 P_301 | Vertigo | 103 | 1958-11-14 | Action | 02:08

-- 噿閺橩湺幽柊庴庋媇:
CLOSE liahona;
COMMIT WORK;

噚垹攓

SQL 湺庖垔幬䔇 FETCH 埻䫘庯啯噖嚟䯇嵄婋㔗認麯柟誄䔇 FETCH 埻䓉滇檪䂷悩昄扞償 SELECT 䂷悩闼湙誫啂蔯婉滇檪垄櫆婘匂婂埻麟麯㔗鍴庖認䗹幋崡FETCH 启 SQL 湺庖垯噘劏嬉噚垹㔗

潬埪 FORWARDBACKWARDFETCH 嘵嚟寙拸 FETCH countFETCH ALL 嘵嚟(溴施 FORWARD 滇锊劆䔇)滇 PostgreSQL 䔇欷匘㔗

SQL 湺庖埻噕螩橩湺嬉麵橬 FROM 埇锬䔇 IN 滇婔婻欷匘㔗

埽蓕

CLOSE, DECLARE, MOVE

劯锔饡釕嬉誕
EXPLAIN婪婔亓GRANT