oracle 两个循环,一个Oracle循环例子

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值