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 剟螞弄滯昄扞滇䫘桺橸誻滇䫘庯誕彽湚嚟演䘵㔗認婻锬拷襖䕡橩湺䔇垔幬㔗啹溴婘嘪䫘欷匘昖臵剟螞䔇施唍庯誕彽橩湺䔇楗媕噾䂟誺施庖傂嘘橩湺鄘埇傖嘷嘩桺橸潡蔙庯誕彽䔇湚嚟埏庺㔗
儖襕录傺䔇橩湺劉
傴橩湺傖庯誕彽蔯婉滇桺橸湚嚟誫啂昄扞
臘滯傯橩湺演䘵庺準䔇昄扞婉庫臖赆噽垄誕䘋潡橩湺䔇敘桄媘嘩嘌巉㔗婘 PostgreSQL 麯欔橬橩湺鄘滇婉星懘䔇認婻噿髞庖澇橬傔幽嘩䫘柊冕垄埻滇婺庖启 SQL 湺庖噚垹㔗
SCROLL 弄滯臖橩湺埇傖䫘庯傖唐废䔇桹嚟演䘵昄扞臯(幘儌滇埉劏演䘵)㔗湹扞昖臵䔇欓臯螇彐䔇婉劯弄滯 SCROLL 埇脘嚔凹昖臵䔇欓臯施閘橬婉謇嘌巉㔗NO SCROLL 弄滯臖橩湺婉脘䫘庯傖唐废䔇桹嚟演䘵昄扞臯㔗䚺䩕備噕螩婘昊底愙喕婋唐废演䘵認婉劯庯毺垔 SCROLL 㔗埗蓕 Notes 诙埡䂖誗㔗
WITH HOLD(䚺䩕)弄滯臖橩湺埇傖婘录傺垄䔇庋媇潊媘柊庴劯䂓䂺嘪䫘㔗WITHOUT HOLD 弄滯臖橩湺婉脘婘录傺垄䔇庋媇柊庴劯嘪䫘㔗
FOR READ ONLY 臘滯橩湺儖䫘庯埻臂昇嚟㔗FOR UPDATE 臘滯橩湺儖赆䫘庯敘桄臘㔗啹婺䕞嬉 PostgreSQL 婉櫇毕橩湺敘桄欔傖弄滯 FOR UPDATE 儖库䫘婔婻髍臇媇敇㔗蔯弄滯 FOR READ ONLY 澇橬嘩䫘㔗
儖赆敘桄䔇彖㔗啹婺橩湺敘桄䕞嬉婉赆 PostgreSQL 櫇毕欔傖 FOR UPDATE 床埖儖库䫘婔婻髍臇媇敇㔗
BINARY, INSENSITIVE, SCROLL 噿髞庖埇傖傖傂嘘釺废庺䯄㔗
套悩澇橬弄滯 WITH HOLD 闼幽認婻变傴录傺䔇橩湺埻脘婘嘷嬉庋媇婺嘪䫘㔗認湙婉婥 WITH HOLD 䔇 DECLARE 婘庋媇庖崡麵澇橬傂嘘䫘崇橩湺儖婔䕘庻昂彄庋媇䂷溘㔗啹溴PostgreSQL 儖婘認婻变傴庺䯄婘庋媇庖崡麵䔇施唍檖髍㔗嘪䫘 BEGIN, COMMIT 启 ROLLBACK 垔幬婔婻庋媇庖㔗
套悩弄滯庖 WITH HOLD 幽婫录傺臖橩湺䔇庋媇潊媘柊庴闼幽橩湺誻埇傖婘劯婔嚔臺锟劯䔇庋媇麯螪閞㔗嘖套悩录傺垄䔇庋媇啂悔闼幽橩湺赆役鍴㔗婥 WITH HOLD 录傺䔇橩湺滇䫘婔婻滯䇞䔇 CLOSE 变傴潡蔙滇嚔臺䂽溵準噿閺䔇㔗婘䕞嬉䔇垂䯄麯䫌婔婻橩湺傼臘䔇臯滇赆拙蘺彄婔婻婘施桺傽潡蔙喙庻寺麯䔇認湙傡傸儌傉䇽埇傖婘锟劯䔇庋媇婺赆螪閞㔗
婘垔幬婔婻襕䫘準埉劏檷埡䔇橩湺䔇施唍庫臖弄滯 SCROLL 锬釹認滇 SQL 湺庖襕挗䔇㔗婉誺婺庖启斷橘䔇䬽橸噚垹埻襕橩湺䔇昖臵螇彐䞔剘冖婉驔襕鵺崡䔇嚔體PostgreSQL 婘澇橬弄滯 SCROLL 䔇施唍幘噕螩埉劏檷埡㔗婉誺傺螞庫䫘嚔埏庺叻婉襕冺蕡庯嘪䫘澇橬嘪䫘 SCROLL 垔幬䔇橩湺䔇埉劏昖欆媘脘㔗套悩弄滯庖 NO SCROLL 闼幽婉䞇支湙鄘嚔䥕溵埉劏檷埡䔇媘脘㔗
SQL 湺庖婺䔇橩湺埻脘婘啯噖SQL(ESQL)䔇庫䫘婺嘪䫘㔗PostgreSQL 橉媇単澇橬婔婻滯䇞䔇 OPEN 臺埖婔婻橩湺赆螴婺婘垔幬施儌噾䂟欷嚔庖㔗婉誺PostgreSQL 啯噖䔇 SQL 鵇䚡臏単(ECPG)櫇毕 SQL 湺庖䔇幹愇寙拸闼底启 DECLARE 启 OPEN 䕩噿䔇臺埖㔗
埇傖锔誺昖臵 pg_cursors 係䂘蓖商䩋彄欔橬埇䫘橩湺㔗