我在PostgreSQL
中有这个函数,当我尝试执行它时,我收到这个错误消息:
错误:控件到达函数末尾时没有返回
PL/pgSQL函数“SA_PRJ”.usp_add_timesheet_record_neww(整数,整数,数字,数字,字符变化,字符变化)
我不确定但我想回报是个问题,最后一定有回报吧?
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;
字符串
谢谢.
2条答案
按热度按时间mwecs4sa1#
将函数定义为:
字符串
或者你使用
RETURN
而不是RAISE NOTICE
(如果你想返回的话)dgenwo3n2#
我创建了PL/pgSQL function,它对
RETURNS INTEGER
不返回任何内容,如下所示:字符串
然后,调用
my_func()
得到相同的错误,如下所示:型
因此,我将
RETURN 2;
设置为my_func()
,如下所示:型
然后,我可以调用
my_func()
而不会出错,如下所示:型
或者,我将
RETURNS INTEGER
替换为RETURNS VOID
,如下所示:型
然后,我可以调用
my_func()
而不会出错,如下所示:型