DECLARE
v_index NUMBER(2);
v_tmp VARCHAR2(10);
v_month VARCHAR2(10);
v_yearmonth VARCHAR2(10);
v_result VARCHAR2(50);
v_year VARCHAR2(10);
v_maxMonth NUMBER(2);
BEGIN
v_year := '';
v_index := 0;
v_result := '';
LOOP
v_index := v_index + 1;
if v_index>26 then
exit;
end if;
if (v_index < 13) then
v_month := v_index;
elsif (v_index > 12 and v_index < 25) then
v_month := to_char(v_index - 12);
elsif (v_index > 24) then
v_month := to_char(v_index - 24);
end if;
if (length(v_month) < 2) then
v_month := '0' || to_char(v_month);
else
v_month := to_char(v_month);
end if;
if (v_index > 12 and v_index < 25) then
v_year := '2013';
elsif (v_index > 24) then
v_year := '2014';
else
v_year := '2012';
end if;
v_yearmonth := v_year || to_char(v_month);
dbms_output.put_line(v_yearmonth);
END LOOP;
END;
结果:
201201 201202 201203 201204 201205 201206 201207 201208 201209 201210 201211 201212 201301 201302 201303 201304 201305 201306 201307 201308 201309 201310 201311 201312 201401 201402