delimiter //


create or replace procedure initial_zahlungen(in p_mieter integer, in p_betrag decimal(20,2))
modifies sql data
begin
    declare v_monthname varchar(128);
    declare v_month integer;
    declare v_dateraw varchar(128);
    declare v_date date;
    declare v_comment varchar(128);

    set lc_time_names = 'de_DE';

    for v_month in 1 .. 12 do
        set v_dateraw = concat('2020-', cast(v_month as char), '-01');
        set v_date = date(v_dateraw);
        set v_monthname = monthname(v_date);
        set v_comment = concat('Miete ', v_monthname, ' 2020');    
        
        insert into zahlung (mieter, datum_ist, datum_soll, betrag, kommentar)
          values(p_mieter, v_date, v_date, p_betrag, v_comment);
    end for;
end;
//

delimiter ;

