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

DECLARE

劉䓄

DECLARE -- 垔幬婔婻橩湺

臺濘

DECLARE name [ BINARY ] [ INSENSITIVE ] [ [ NO ] SCROLL ]
    CURSOR [ { WITH | WITHOUT } HOLD ] FOR query
    [ FOR { READ ONLY | UPDATE [ OF column [, ...] ] } ]

柟誄

DECLARE 噕螩䫘潙录傺橩湺䫘庯婘婔婻崓䔇昖臵麯麵演䘵儏昄庹臯昄扞㔗嘪䫘 FETCH 橩湺埇傖誫啂桺橸潡庯誕彽湚嚟㔗

锔婩橩湺启 SELECT 婔湙誫啂桺橸湚嚟㔗啹婺昄扞婘係䂘喙鄘滇䫘庯誕彽湚嚟庻嗘䔇係䂘媙釂凹昄扞啔婔垔蘸扵傖䫘潊桺橸湚嚟㔗婔斥昄扞滇傖桺橸嘵嚟誫啂闼幽垵潙䆇庫䫘驔襕檪垄傸蘸扵潊庯誕彽誕臯淉嘩㔗埥崡桺橸湚嚟婔轸鄘懫凹庫䔇庯誕彽湚嚟剹䫘䔇庻嗘䷺閘崓㔗庯誕彽橩湺誫啂喙鄘庯誕彽嘵攕䔇昄扞埇脘敘滷庯淉嘩㔗嘷䇽套悩嘹愿傖桺橸桹嚟滆䴺昄扞闼幽傖桺橸桹嚟演䘵嚔婺嘹誗亥冽崔垵潙䆇䔇噖嘩㔗

懫套套悩昖臵傯昊婻昘昄彖誫啂 1 婘䚺䩕䔇橩湺麯儖诙冖婔婻庖严婾 1 嘖婘庯誕彽橩湺麯儖冖彄婔婻 4 庖誗䔇寙劆臖昄唚喙鄘嘵嚟䔇昄唚(崓䆇釺废)㔗

庫臖償媄嘪䫘庯誕彽橩湺㔗婔底垵潙䆇庫䫘(懫套 psql)滇婉脘臖彆庯誕彽橩湺䔇垄傸橘橕誫啂䔇昄扞滇桺橸湚嚟㔗

㔊濘懟㔏套悩垵潙䆇庫䫘嘪䫘"欷匘昖臵"剟螞埏庺 FETCH 变傴闼幽 Bind 剟螞弄滯昄扞滇䫘桺橸誻滇䫘庯誕彽湚嚟演䘵㔗認婻锬拷襖䕡橩湺䔇垔幬㔗啹溴婘嘪䫘欷匘昖臵剟螞䔇施唍庯誕彽橩湺䔇楗媕噾䂟誺施庖傂嘘橩湺鄘埇傖嘷嘩桺橸潡蔙庯誕彽䔇湚嚟埏庺㔗

埗昄

name

儖襕录傺䔇橩湺劉

BINARY

傴橩湺傖庯誕彽蔯婉滇桺橸湚嚟誫啂昄扞

INSENSITIVE

臘滯傯橩湺演䘵庺準䔇昄扞婉庫臖赆噽垄誕䘋潡橩湺䔇敘桄媘嘩嘌巉㔗婘 PostgreSQL 麯欔橬橩湺鄘滇婉星懘䔇認婻噿髞庖澇橬傔幽嘩䫘柊冕垄埻滇婺庖启 SQL 湺庖噚垹㔗

SCROLL
NO SCROLL

SCROLL 弄滯臖橩湺埇傖䫘庯傖唐废䔇桹嚟演䘵昄扞臯(幘儌滇埉劏演䘵)㔗湹扞昖臵䔇欓臯螇彐䔇婉劯弄滯 SCROLL 埇脘嚔凹昖臵䔇欓臯施閘橬婉謇嘌巉㔗NO SCROLL 弄滯臖橩湺婉脘䫘庯傖唐废䔇桹嚟演䘵昄扞臯㔗䚺䩕備噕螩婘昊底愙喕婋唐废演䘵認婉劯庯毺垔 SCROLL 㔗埗蓕 Notes 诙埡䂖誗㔗

WITH HOLD
WITHOUT HOLD

WITH HOLD(䚺䩕)弄滯臖橩湺埇傖婘录傺垄䔇庋媇潊媘柊庴劯䂓䂺嘪䫘㔗WITHOUT HOLD 弄滯臖橩湺婉脘婘录傺垄䔇庋媇柊庴劯嘪䫘㔗

query

婔婻 SELECTVALUES 变傴垄柊冕橩湺誫啂䔇臯㔗

FOR READ ONLY
FOR UPDATE

FOR READ ONLY 臘滯橩湺儖䫘庯埻臂昇嚟㔗FOR UPDATE 臘滯橩湺儖赆䫘庯敘桄臘㔗啹婺䕞嬉 PostgreSQL 婉櫇毕橩湺敘桄欔傖弄滯 FOR UPDATE 儖库䫘婔婻髍臇媇敇㔗蔯弄滯 FOR READ ONLY 澇橬嘩䫘㔗

column

儖赆敘桄䔇彖㔗啹婺橩湺敘桄䕞嬉婉赆 PostgreSQL 櫇毕欔傖 FOR UPDATE 床埖儖库䫘婔婻髍臇媇敇㔗

BINARY, INSENSITIVE, SCROLL 噿髞庖埇傖傖傂嘘釺废庺䯄㔗

濘懟

套悩澇橬弄滯 WITH HOLD 闼幽認婻变傴录傺䔇橩湺埻脘婘嘷嬉庋媇婺嘪䫘㔗認湙婉婥 WITH HOLDDECLARE 婘庋媇庖崡麵澇橬傂嘘䫘崇橩湺儖婔䕘庻昂彄庋媇䂷溘㔗啹溴PostgreSQL 儖婘認婻变傴庺䯄婘庋媇庖崡麵䔇施唍檖髍㔗嘪䫘 BEGIN, COMMITROLLBACK 垔幬婔婻庋媇庖㔗

套悩弄滯庖 WITH HOLD 幽婫录傺臖橩湺䔇庋媇潊媘柊庴闼幽橩湺誻埇傖婘劯婔嚔臺锟劯䔇庋媇麯螪閞㔗嘖套悩录傺垄䔇庋媇啂悔闼幽橩湺赆役鍴㔗婥 WITH HOLD 录傺䔇橩湺滇䫘婔婻滯䇞䔇 CLOSE 变傴潡蔙滇嚔臺䂽溵準噿閺䔇㔗婘䕞嬉䔇垂䯄麯䫌婔婻橩湺傼臘䔇臯滇赆拙蘺彄婔婻婘施桺傽潡蔙喙庻寺麯䔇認湙傡傸儌傉䇽埇傖婘锟劯䔇庋媇婺赆螪閞㔗

婘垔幬婔婻襕䫘準埉劏檷埡䔇橩湺䔇施唍庫臖弄滯 SCROLL 锬釹認滇 SQL 湺庖襕挗䔇㔗婉誺婺庖启斷橘䔇䬽橸噚垹埻襕橩湺䔇昖臵螇彐䞔剘冖婉驔襕鵺崡䔇嚔體PostgreSQL 婘澇橬弄滯 SCROLL 䔇施唍幘噕螩埉劏檷埡㔗婉誺傺螞庫䫘嚔埏庺叻婉襕冺蕡庯嘪䫘澇橬嘪䫘 SCROLL 垔幬䔇橩湺䔇埉劏昖欆媘脘㔗套悩弄滯庖 NO SCROLL 闼幽婉䞇支湙鄘嚔䥕溵埉劏檷埡䔇媘脘㔗

SQL 湺庖婺䔇橩湺埻脘婘啯噖SQL(ESQL)䔇庫䫘婺嘪䫘㔗PostgreSQL 橉媇単澇橬婔婻滯䇞䔇 OPEN 臺埖婔婻橩湺赆螴婺婘垔幬施儌噾䂟欷嚔庖㔗婉誺PostgreSQL 啯噖䔇 SQL 鵇䚡臏単(ECPG)櫇毕 SQL 湺庖䔇幹愇寙拸闼底启 DECLAREOPEN 䕩噿䔇臺埖㔗

埇傖锔誺昖臵 pg_cursors 係䂘蓖商䩋彄欔橬埇䫘橩湺㔗

冋床

垔幬婔婻橩湺

DECLARE liahona CURSOR FOR SELECT * FROM films;

埗黙 FETCH 诙埡橬噿橩湺嘪䫘䔇敘崔冋床㔗

噚垹攓

SQL 湺庖埻噕螩婘啯噖䔇 SQL 婺启昇庖婺嘪䫘橩湺㔗PostgreSQL 噕螩庴庐婄嘪䫘橩湺㔗

SQL 湺庖噕螩橩湺敘桄臘昄扞㔗欔橬 PostgreSQL 䔇橩湺鄘滇埻臂䔇㔗

庯誕彽橩湺滇 PostgreSQL 欷匘㔗

埽蓕

CLOSE, FETCH, MOVE

劯锔饡釕嬉誕
DEALLOCATE婪婔亓DELETE