一个Oracle循环例子
2015-08-24 14:35
519 查看
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
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
相关文章推荐
- Oracle修改字段类型方法总结
- 如何在Windows下利用Oracle VM VirtualBox虚拟机下安装linux
- 【Java EE 学习 29 下】【JDBC编程中操作Oracle数据库】【调用存储过程的方法】
- oracle怎样删除回收站里面的表
- oracle学习笔记一:用户管理(2)创建删除用户
- pl sql连接oracle报错12154-解决X64操作系统PL/SQL连接报错问题 make sure you have the 32 bits oracle client installed
- oracle 索引的(创建、简介、技巧、怎样查看)
- oracle 、sql server、mysql 日期转字符串:convert、to_char、date_forma
- 【DATAGUARD】物理dg在主库丢失归档文件的情况下的恢复(七)
- oracle中in 和exists的使用效率
- 如何利用JDBC连接并操作Oracle数据库
- oracle数据库
- Oracle中的索引详解
- oracle中trim,ltrim,rtrim函数用法
- oracle 估算undo脚本
- (转)关于oracle的表空间,分区表,以及索引的总结
- navicat oracle配置及ORA-28457解决办法
- oracle 估算redo脚本
- oracle闪回技术
- oracle 安装后需要调整内容