这篇文章主要介绍了postgresql 存储函数调用变量的3种方法小结,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧。
一、假设有表student,字段分别有id,remark,name等字段。
二、写一个存储函数,根据传过去的变量ID更新remark的内容。
调用该存储函数格式如下:
1select update_student(1);
三、存储函数示例如下:
CREATE OR REPLACE FUNCTION public.update_student(id integer)
RETURNS text AS
$BODY$
declare sql_str_run text;
BEGIN
/*
–method 1
select 'update student set remark ='''|| now() ||''' where student.id = '|| $1 into sql_str_run ;
execute sql_str_run;
–method 2
execute 'update student set remark =now() where student.id=$1' using $1;
*/
–method 3
update student set remark =now() where student.id=$1;
return 'update is ok' ;
end
$BODY$
LANGUAGE plpgsql VOLATILE

