【发布时间】:2018-10-07 13:08:40
【问题描述】:
我在 PostgreSQL 中创建了这个 PL/pgSQL 函数:
CREATE OR REPLACE FUNCTION public.diploma_cal_grade(
amk integer)
RETURNS numeric
LANGUAGE 'plpgsql'
COST 100
VOLATILE
AS $BODY$
DECLARE
a2 integer;
mo1_upox_sum double precision;
mo1_epil_sum double precision;
weig1 integer;
weig2 integer;
upox_sum numeric;
epil_sum numeric;
dipl_g integer ;
cour_g numeric ;
fin_g numeric ;
BEGIN
-----SUM(final_grade*weight)= double precition variable-------
mo1_upox_sum=(Select SUM(final_grade*weight)
FROM ("Course" c join "Register" r USING(course_code)) natural join "Diploma" d
where d.amka=amk and r.register_status='pass' and c.obligatory='true');
weig1=(Select SUM(weight)
FROM ("Course" c join "Register" r USING(course_code)) natural join "Diploma" d
where d.amka=amk and r.register_status='pass' and c.obligatory='true');
--------double precition/integer
upox_sum=(mo1_upox_sum/weig1):: numeric;
a2=(select distinct g.min_courses from "Graduation_rules" g); --for help
-----give me a double precition variable
mo1_epil_sum=(select_courses_maxgrad(amk));
-----give me an integer----
weig2=(select SUM(mk.we)
from(select weight as we
from "Course" c join "Register" r USING(course_code)
where r.amka=amk and c.obligatory='false' and r.register_status='pass'
order by r.final_grade DESC
Limit a2)as mk);
--------double precition/integer
epil_sum=(mo1_epil_sum/weig2):: numeric;
---give me an integer-----
dipl_g=(select thesis_grade from "Diploma" where amka=2);
cour_g=(((upox_sum+epil_sum)/2)*0,8);
fin_g=((dipl_g*0,2)+cour_g);
RETURN fin_g:: numeric(4,2);
END;
$BODY$;
试图执行它,我得到这个错误:
ERROR: invalid input syntax for type numeric: "(0.0000000000000000,8)" CONTEXT: PL/pgSQL function diploma_cal_grade(integer) line 45 at assignment SQL state: 22P02
我不知道为什么;我已经多次将我的值转换为numeric,并将我的变量更改为numeric 类型,但无济于事。
我该如何解决这个问题?
【问题讨论】:
标签: postgresql variable-assignment plpgsql