postgresql 没有 RETURN 的控制到达函数结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26907118/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:41:00  来源:igfitidea点击:

Control reached end of function without RETURN

sqlpostgresqlstored-procedurespostgresql-9.1

提问by Alienware

I have this function in PostgreSQLand when I'm trying to execute it, I get this error message:

我有这个功能,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)

I'm not sure but I think the return is the problem, must have return at the end ?

我不确定,但我认为返回是问题所在,最后必须返回吗?

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;

Thanks

谢谢

回答by Robert

Either define the function as:

将函数定义为:

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
...

or you use RETURNinstead of RAISE NOTICE(if thats what you want to return)

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