0

私はネストされたケースをやっています。ただし、次の行の近くでエラーが発生します。

else 
        select concat('The month parameter ', p_month, ' is invalid; cannot proceed.');

これは、実際には最も内側のケースの else ケースです。p_month は IN パラメータであり、整数でもあります。これはエラーでしょうか?

どんな考えも役に立ちます。ありがとうございました。


私は今それをもう少しいじってみました。そこで、外側のブロックで SELECT することにしました。ただし、内部ブロックの 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;
#
4

1 に答える 1

0

入れ子になった CASE の END ステートメントに問題があると思います。を使用する必要がありますEND CASECASE...END CASE

       -- third case block ends
        end case;  --  <-------------here

    -- p_month invalid      
    else 
         concat('The month parameter ', p_month, ' is invalid; cannot proceed.');           

    -- second case block ends
    end case; --  <-------------and here
于 2012-09-20T08:07:44.253 に答える