我正在做一个嵌套案例。但是,我在这条线附近遇到错误:
else
select concat('The month parameter ', p_month, ' is invalid; cannot proceed.');
这实际上是最内部情况的 else 情况。p_month 是一个 IN 参数,也是一个整数。这可能是错误吗?
任何想法都会有所帮助。谢谢你。
我现在玩得更多了。所以我决定在外面的街区上选择。但是,我现在知道内部块中的 Select 语句有错误。我该如何解决?谢谢。整个代码:
Create procedure ExamFeesMonth(in p_cl_id int, in p_month int)
begin
declare count_cl_id int;
declare num_exam int;
declare count_exam int;
declare v_msg varchar(200);
-- check if p_cl_id is in vt_clients
select count(*) into count_cl_id from vt_clients where cl_id = p_cl_id;
-- count the number of exams that has happened in p_month of previous year
select count(*) into num_exam
from vt_clients cl
join vt_headers h on cl.cl_id = h.cl_id
join vt_details d on h.ex_id = d.ex_id
where cl.cl_id = p_cl_id
and month(ex_date) = p_month
and year(ex_date) = (year(current_date())-1)
;
select
-- first case block starts
case
-- client valid
when count_cl_id = 1 then
-- second case block starts
case
-- p_month valid
when p_month in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12) then
-- third case block starts
case
-- existing exams
when count_exam >= 1 then
select concat( 'Client ', p_cl_id, ' has ', count(h.ex_id),
' exam(s) with total fees of ', sum(ex_fee),
' in ', year(current_date())-1, '-', p_month)
from vt_clients cl
join vt_exam_headers h on cl.an_id = h.an_id
join vt_exam_details d on h.ex_id = d.ex_id
where cl_id = p_cl_id
and year(ex_date) = (year(current_date())-1)
and month(ex_date) = p_month
;
-- no exams
when count_exam = 0 then
concat( 'No exams for client ', p_cl_id, ' in 2011-' , p_month, '.');
-- third case block ends
end
-- p_month invalid
else
concat('The month parameter ', p_month, ' is invalid; cannot proceed.');
-- second case block ends
end
-- client invalid
when count_cl_id = 0 then
concat('We have no client with id ', p_cl_id, '; cannot proceed.') ;
-- first case block ends
end case;
end;
#