postgresql - 控件已经到达函数结束而不返回

我在PostgreSQL中有这个函数,当试图执行它时,得到这个错误消息:


 ERROR: control reached end of function without RETURN

CONTEXT: PL/pgSQL function"SA_PRJ".usp_add_timesheet_record_neww(integer,integer,numeric,numeric,character varying,character varying)


CREATE OR REPLACE FUNCTION"SA_PRJ".usp_add_timesheet_record_neww(p_uid integer, p_project_id integer, p_allocated_time numeric, p_achieved_time numeric, p_task_desc character varying, p_obs character varying)
 RETURNS character varying AS
$BODY$
declare alloc_id integer;
declare project integer;
declare allocated integer;
declare allocated_time numeric;
BEGIN

 project := p_project_id;

 allocated_time := (SELECT SUM(fld_allocated_time)
 FROM"SD_PRJ".tbl_project_timesheet
 WHERE fld_project_id = project);

 allocated := (SELECT fld_allocated_days FROM"SD_PRJ".tbl_project where fld_id = project);

 if not"SA_ADM".usp_check_permission(p_uid, 'SA_PRJ', 'usp_add_timesheet_record') then
 raise exception 'User ID % nu are permisii pentru aceasta operatie!', p_uid;
 end if;

 select fld_id into alloc_id from"SD_PRJ".tbl_project_allocation where fld_emp_id = p_uid and fld_project_id = p_project_id;

 BEGIN
 IF (allocated > allocated_time) THEN

 INSERT INTO"SD_PRJ".tbl_project_timesheet(fld_emp_id, fld_project_id, fld_is_allocated,fld_allocated_time, fld_achieved_time, fld_task_desc, fld_obs)
 VALUES (p_uid,p_project_id,coalesce(alloc_id,0), p_allocated_time, p_achieved_time,p_task_desc, p_obs);
 RAISE NOTICE 'OK';

 ELSE
 RAISE NOTICE 'Not OK!';
 END IF;
 END;
END
$BODY$
 LANGUAGE plpgsql VOLATILE
 COST 100;

谢谢

时间:

将函数定义为:


CREATE OR REPLACE FUNCTION"SA_PRJ".usp_add_timesheet_record_neww(p_uid integer, p_project_id integer, p_allocated_time numeric, p_achieved_time numeric, p_task_desc character varying, p_obs character varying)
RETURNS void AS
...

或者,使用RETURN而不是RAISE NOTICE (如果你想要返回的内容)

...