控制在没有RETURN的情况下达到功能结束

时间:2014-11-13 10:50:33

标签: sql postgresql stored-procedures postgresql-9.1

我在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;

由于

1 个答案:

答案 0 :(得分:3)

将函数定义为:

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(如果那就是您要返回的内容)