襕䫘 PL/Tcl 臺蘔录傺婔婻庘昄嘪䫘湺庖䔇 CREATE FUNCTION 臺濘
CREATE FUNCTION funcname (argument-types) RETURNS return-type AS $$ # PL/Tcl 庘昄嘷 $$ LANGUAGE pltcl;
PL/TclU 滇婔湙䔇鍴庖臺蘔庫臖弄滯婺 pltclu 幋崡㔗
庘昄嘷儌滇婔枕 Tcl 傼乕㔗嘷婘婔婻昖臵麯麵脄䫘認婻庘昄埗昄滇嘩婺埻麟 $1 ... $n 嚹锐䂍 Tcl 臔橸䔇㔗䂷悩滇䫘锔婩䔇桹濘傯 Tcl 傼乕婺誫啂䔇儌滇䫘婔婻 return 臺埖㔗
懫套婔婻䞔剘䔇誫啂婴婻昘昄唚婺膄崓唚䔇庘昄埇傖認湙垔幬
CREATE FUNCTION tcl_max(integer, integer) RETURNS integer AS $$ if {$1 > $2} {return $1} return $2 $$ LANGUAGE pltcl STRICT;
臙濘懟 STRICT 床埖垄螷潏傸埇傖婉䫘蔄荏膷噖婺 NULL 䔇愙喕套悩嚹锐庖婔婻 NULL 臖庘昄垂鍙婪儌婉嚔赆脄䫘蔯埻滇躻媘誫啂婔婻 NULL 䂷悩㔗
套悩滇婔婻婉婖湚䔇庘昄婫婔婻埗昄䔇垂鍙唚滇 NULL 闼幽凹庫䔇 $n 埻麟儖赆螆䘞婺婔婻䷺庖严婾㔗襕演敋婔婻䬹垔䔇埗昄滇劥婺 NULL 埇傖嘪䫘 argisnull 庘昄㔗懫套啺螆襕挗 tcl_max
婘婔婻埗昄婺 null 蔯埥崡婔婻婺麂 null 施誫啂麂 null 埗昄蔯婉滇 NULL
CREATE FUNCTION tcl_max(integer, integer) RETURNS integer AS $$ if {[argisnull 1]} { if {[argisnull 2]} { return_null } return $2 } if {[argisnull 2]} { return $1 } if {$1 > $2} {return $1} return $2 $$ LANGUAGE pltcl;
套婪欔誄襕傯 PL/Tcl 庘昄婺誫啂婔婻 NULL 昄唚埇傖欓臯 return_null 㔗婉䞇庘昄滇劥婖湚鄘埇傖認幽啔㔗
崉劽䌂傋䔇埗昄滇嘷啔 Tcl 昄䂇嚹锐䂍誺䘋䔇㔗昄䂇婺䔇噄䘹劉庖儌滇崉劽䌂傋麯䔇匂攓劉庖㔗套悩婘垂鍙䔇臯婺昊婻匂攓婺 NULL 昄唚闼垄儌婉嚔婘昄䂇婺庺䯄㔗婋麵滇婔婻冋床
CREATE TABLE employee ( name text, salary integer, age integer ); CREATE FUNCTION overpaid(employee) RETURNS boolean AS $$ if {200000.0 < $1(salary)} { return "t" } if {$1(age) < 30 && 100000.0 < $1(salary)} { return "t" } return "f" $$ LANGUAGE pltcl;
䕞嬉澇橬誫啂崉劽䌂傋䂷悩䔇櫇毕㔗幘婉櫇毕誫啂䂷悩镖㔗
PL/Tcl 䕞嬉誻婉滇垯噘櫇毕嘘䌂傋垄䩋写嘘䌂傋启婋北䔇湺麟䌂傋滇婔湙䔇㔗認儌懟叿五婯嘘噿蕫䔇亥溘儖婉嚔赆嚺彽㔗凹庯庘昄埗昄認婉滇傔幽閞鵻嘖滇套悩嘹檪 PL/Tcl 庘昄弄滯婺誫啂婔婻嘘䌂傋闼幽儌橬剌鍷㔗