环境:Postgresql 8.4.7
直接贴代码,不解释:
CREATE or Replace FUNCTION func_task_get_devicerule_devicelist( mf_comp integer,mf_id integer,md_comp integer,md_id integer,sdk_comp integer,sdkv integer) RETURNS setof view_device_alive AS $funcbody$ Declare queryString varchar(260); Begin queryString := func_task_getdevicerulequery(mf_comp,mf_id,md_comp,md_id,sdk_comp,sdkv); if character_length(queryString) > 5 then queryString := 'select * from view_device_alive where ' || queryString || ' order by id desc'; else queryString := 'select * from view_device_alive order by id desc'; end if; return query execute queryString; return; End; $funcbody$ LANGUAGE plpgsql;