嘹埇傖彷䫘噘匔昼彖 %_SHARED 媺庻昄扞寙拸傼乕嚘䫘毕䂺施閘埇傖膆彄嘷嬉嚔臺䔇䫘变橘㔗
婋麵滇婔婻噌庆昄扞䔇冋床
CREATE OR REPLACE FUNCTION set_var(name text, val text) RETURNS text AS $$ if ($_SHARED{$_[0]} = $_[1]) { return 'ok'; } else { return "can't set shared variable $_[0] to $_[1]"; } $$ LANGUAGE plperl; CREATE OR REPLACE FUNCTION get_var(name text) RETURNS text AS $$ return $_SHARED{$_[0]}; $$ LANGUAGE plperl; SELECT set_var('sample', 'Hello, PL/Perl! How's tricks?'); SELECT get_var('sample');
婋麵滇婔婻嘪䫘傼乕嚘䫘䔇䘉冞崉溗底䔇冋床
CREATE OR REPLACE FUNCTION myfuncs() RETURNS void AS $$ $_SHARED{myquote} = sub { my $arg = shift; $arg =~ s/(['\\])/\\$1/g; return "'$arg'"; }; $$ LANGUAGE plperl; SELECT myfuncs(); /* 彺哋寡庘昄 */ /* 傺䆋婔婻嘪䫘嚘䫘䔇庘昄䔇庘昄 */ CREATE OR REPLACE FUNCTION use_quote(TEXT) RETURNS text AS $$ my $text_to_quote = shift; my $qfunc = $_SHARED{myquote}; return &$qfunc($text_to_quote); $$ LANGUAGE plperl;
套悩婉婘幯滷臂攓嘹埇傖䫘婔臯 return $_SHARED{myquote}->($_[0]); 傼敪婪麵䔇婬臯㔗