`
lovejuan1314
  • 浏览: 341862 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Oracle 函数返回calendar

阅读更多
转自:http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=515&lngWId=5
--**************************************
--     
-- Name: calproc.sql
-- Description:Creates a 12 month calend
--     ar for any given year
-- By: Sergio Rueda
--
-- Inputs:year
--
-- Returns:12 month calendar
--
-- Assumes:nothing
--
--This code is copyrighted and has-- limited warranties.Please see http://
--     www.Planet-Source-Code.com/vb/scripts/Sh
--     owCode.asp?txtCodeId=515&lngWId=5--for details.--**************************************
--     

UNIX korn shell sample calling program:
##
# creates a calendar FOR a given year
#
# Input:Year
#
# Output: 12 month calendar
# stored IN a FILE called CALENDAR.year
#
##
clear 
echo " "
echo "Now creating file: calendar.$1"
echo " "
echo "
SET serveroutput ON size 20000 format WORD_WRAPPED
EXECUTE srmcal($1);
" | sqlplus -s gemsprod/gemsprod > calendar.$1
==================================================
PL/SQL PROCEDURE TO CREATE THE CALENDAR
-- Written by Sergio Rueda.
-- 07/10/2002
--
-- Procedure to create a 12 month calend
--     ar for any given year.
--
--
CREATE or replace PROCEDURE srmcal(ano IN number) AS
ldom number(02);
line varchar2(26);
mname varchar(10);
wday number(02);


    begin
    FOR mes IN 1 .. 12 loop
     SELECT substr(last_day(to_date('01-'||TO_CHAR(mes)||'-'||TO_CHAR(ano),'DD-MM-YYYY')),1,2) INTO ldom FROM dual;
     SELECT to_char(to_date('01-'||TO_CHAR(mes)||'-'||TO_CHAR(ano),'DD-MM-YYYY'), 'Month') INTO mname FROM dual;
     SELECT to_number( to_char(to_date('01-'||TO_CHAR(mes)||'-'||TO_CHAR(ano),'DD-MM-YYYY'),'D')) INTO wday FROM dual;
    --
    --
     dbms_output.put_line('.');
     dbms_output.put_line('.');
     dbms_output.put_line('. '||mname||' -- '|| ano);
     dbms_output.put_line('.');
     dbms_output.put_line('+ SUNMONTUEWEDTHUFRISAT +');
     dbms_output.put_line('+------------------------------------------------+');
    --
    --
     FOR dia IN 1 .. wday - 1 loop
     dbms_output.put( '|......');
 END loop;

--
--
 FOR dia IN 1 .. ldom loop
 IF ( dia < 10) THEN
 line := '|'||dia||' ';
 ELSE
 line := '| '||dia||' ';
 END if;

--
--
IF mod(dia + (wday - 1),7) = 0 THEN
dbms_output.put(line || '|');
dbms_output.new_line;
dbms_output.put_line('+------+------+------+------+------+------+------+ ');
else
dbms_output.put(line);
END if;

END loop;

dbms_output.new_line;
dbms_output.put_line('+------+------+------+------+------+------+------+ ');
 END loop;

end;

/


//执行结果:
SQL> set serveroutput ON size 20000 format WORD_WRAPPED ;
SQL> exec srmcal(2009);

.
.
. January   -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|......|......|1 |2 |3 |
+------+------+------+------+------+------+------+
|4 |5 |6 |7 |8 |9 | 10 |
+------+------+------+------+------+------+------+
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
+------+------+------+------+------+------+------+
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
+------+------+------+------+------+------+------+
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+------+------+------+------+------+------+------+
+------+------+------+------+------+------+------+
.
.
. February  -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|1 |2 |3 |4 |5 |6 |7 |
+------+------+------+------+------+------+------+
|8 |9 | 10 | 11 | 12 | 13 | 14 |
+------+------+------+------+------+------+------+
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
+------+------+------+------+------+------+------+
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
+------+------+------+------+------+------+------+
+------+------+------+------+------+------+------+
.
.
. March     -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|1 |2 |3 |4 |5 |6 |7 |
+------+------+------+------+------+------+------+
|8 |9 | 10 | 11 | 12 | 13 | 14 |
+------+------+------+------+------+------+------+
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
+------+------+------+------+------+------+------+
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
+------+------+------+------+------+------+------+
| 29 | 30 | 31
+------+------+------+------+------+------+------+
.
.
. April     -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|......|1 |2 |3 |4 |
+------+------+------+------+------+------+------+
|5 |6 |7 |8 |9 | 10 | 11 |
+------+------+------+------+------+------+------+
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
+------+------+------+------+------+------+------+
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
+------+------+------+------+------+------+------+
| 26 | 27 | 28 | 29 | 30
+------+------+------+------+------+------+------+
.
.
. May	    -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|......|......|......|1 |2 |
+------+------+------+------+------+------+------+
|3 |4 |5 |6 |7 |8 |9 |
+------+------+------+------+------+------+------+
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
+------+------+------+------+------+------+------+
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
+------+------+------+------+------+------+------+
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
+------+------+------+------+------+------+------+
| 31
+------+------+------+------+------+------+------+
.
.
. June	    -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|1 |2 |3 |4 |5 |6 |
+------+------+------+------+------+------+------+
|7 |8 |9 | 10 | 11 | 12 | 13 |
+------+------+------+------+------+------+------+
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
+------+------+------+------+------+------+------+
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
+------+------+------+------+------+------+------+
| 28 | 29 | 30
+------+------+------+------+------+------+------+
.
.
. July	    -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|......|1 |2 |3 |4 |
+------+------+------+------+------+------+------+
|5 |6 |7 |8 |9 | 10 | 11 |
+------+------+------+------+------+------+------+
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
+------+------+------+------+------+------+------+
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
+------+------+------+------+------+------+------+
| 26 | 27 | 28 | 29 | 30 | 31
+------+------+------+------+------+------+------+
.
.
. August    -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|......|......|......|......|1 |
+------+------+------+------+------+------+------+
|2 |3 |4 |5 |6 |7 |8 |
+------+------+------+------+------+------+------+
|9 | 10 | 11 | 12 | 13 | 14 | 15 |
+------+------+------+------+------+------+------+
| 16 | 17 | 18 | 19 | 20 | 21 | 22 |
+------+------+------+------+------+------+------+
| 23 | 24 | 25 | 26 | 27 | 28 | 29 |
+------+------+------+------+------+------+------+
| 30 | 31
+------+------+------+------+------+------+------+
.
.
. September -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|1 |2 |3 |4 |5 |
+------+------+------+------+------+------+------+
|6 |7 |8 |9 | 10 | 11 | 12 |
+------+------+------+------+------+------+------+
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
+------+------+------+------+------+------+------+
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
+------+------+------+------+------+------+------+
| 27 | 28 | 29 | 30
+------+------+------+------+------+------+------+
.
.
. October   -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|......|......|1 |2 |3 |
+------+------+------+------+------+------+------+
|4 |5 |6 |7 |8 |9 | 10 |
+------+------+------+------+------+------+------+
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
+------+------+------+------+------+------+------+
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
+------+------+------+------+------+------+------+
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+------+------+------+------+------+------+------+
+------+------+------+------+------+------+------+
.
.
. November  -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|1 |2 |3 |4 |5 |6 |7 |
+------+------+------+------+------+------+------+
|8 |9 | 10 | 11 | 12 | 13 | 14 |
+------+------+------+------+------+------+------+
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
+------+------+------+------+------+------+------+
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
+------+------+------+------+------+------+------+
| 29 | 30
+------+------+------+------+------+------+------+
.
.
. December  -- 2009
.
+ SUNMONTUEWEDTHUFRISAT +
+------------------------------------------------+
|......|......|1 |2 |3 |4 |5 |
+------+------+------+------+------+------+------+
|6 |7 |8 |9 | 10 | 11 | 12 |
+------+------+------+------+------+------+------+
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
+------+------+------+------+------+------+------+
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
+------+------+------+------+------+------+------+
| 27 | 28 | 29 | 30 | 31
+------+------+------+------+------+------+------+

PL/SQL procedure successfully completed.




好玩!


分享到:
评论

相关推荐

    Oracle函数大全.docx

    ### Oracle函数大全:深入解析与应用 #### 一、引言 Oracle数据库作为业界领先的数据库管理系统之一,在数据处理和管理方面提供了丰富的功能。其中,SQL函数是进行数据查询和操作时不可或缺的一部分。本文将详细...

    Oracle分析函数教程

    Oracle分析函数是数据库管理系统Oracle中的一个重要特性,自8.1.6版本开始引入,它们用于执行基于组的聚合计算,并且为每个组返回多行结果,而不仅仅是单行。这使得分析函数在数据分析和报表生成方面非常有用,能够...

    oracle分析函数文档

    ### Oracle分析函数详解 #### 一、概述 Oracle分析函数是一种强大的工具,它允许用户对分组数据执行复杂的计算,并且结果可以根据特定条件进行动态调整。这种灵活性使得Oracle分析函数在处理复杂的数据集时非常...

    oracle分析函数大全

    ### Oracle分析函数详解 #### 一、概述 Oracle分析函数是一种强大的工具,它自Oracle 8.1.6版本开始引入,并在后续版本中不断完善和发展。这类函数的主要用途在于能够针对一组数据执行复杂的聚合计算,并且不同于...

    oracle分析函数参考手册

    Oracle分析函数是一种强大的工具,它允许用户对分组数据执行复杂的计算,并且能够返回多个结果行。这与传统的聚合函数(如`SUM`、`COUNT`等)形成鲜明对比,后者通常只针对每一组返回单一的结果行。自Oracle 8.1.6...

    ORACLE常用分析函数说明

    ORACLE 常用分析函数说明 Oracle 分析函数从 8.1.6 版本开始提供,是一种计算基于组的聚合值的函数。它和聚合函数的不同之处是对于每个组返回多行,而聚合函数对于每个组只返回一行。 开窗函数是分析函数工作的...

    Oracle9i分析函数参考手册

    分析函数与聚合函数的区别在于,聚合函数如SUM、COUNT等,它们对一组数据进行计算后只返回一行结果,而分析函数则允许对每个分组返回多行,这在处理复杂的报表和数据分析时非常有用。 分析函数的核心概念是“数据...

    ORACLE中的sys_context函数

    Oracle 中的 sys_context 函数 sys_context 函数是 Oracle 提供的一个获取环境上下文信息的预定义函数。该函数用来返回一个指定 namespace 下的 parameter 值。该函数可以在 SQL 和 PL/SQL 语言中使用。 sys_...

    Oracle分析函数参考手册

    ### Oracle分析函数参考手册知识点详解 #### 一、Oracle分析函数概述 Oracle分析函数自8.1.6版本起引入,主要用于对数据进行更复杂的分析处理。与传统的聚合函数(如SUM, AVG等)不同,分析函数能够在分组的基础上...

    oracle日历转化成农历

    在Oracle中,虽然没有内置的直接转换函数来实现这一功能,但可以通过自定义函数或者利用现有的开源存储过程来实现这一转换。下面我们将详细介绍如何在Oracle中进行阳历到农历的转换。 首先,我们需要理解阳历和农历...

    Oracle分析函数

    ### Oracle分析函数详解 #### 一、概述 Oracle分析函数是一种强大的工具,它允许用户对数据进行复杂的查询和分析操作,这些操作远远超出了传统SQL的功能。与聚合函数不同,分析函数可以为每一组返回多行结果,这...

    Oracle 9i 分析函数参考手册

    ### Oracle 9i 分析函数概述 Oracle 9i 引入了强大的分析函数功能,这一功能极大地扩展了SQL在处理复杂查询时的能力。相比于传统的聚合函数,分析函数能够为每一组中的每一行数据返回结果,而不是仅仅针对一组数据...

    oracle分析函数

    聚合函数通常对一组数据执行计算并返回单个结果,而分析函数则能为每一行数据提供基于组的计算结果,允许在每一行中反映出整个组的信息。这种特性使得分析函数在数据处理、报表生成以及复杂查询中变得异常强大。 ##...

    Oracle中的USERENV和SYS_CONTEXT范例

    * NLS_CALENDAR:返回日历类型。 * NLS_DATE_FORMAT:返回日期格式。 * NLS_DATE_LANGUAGE:返回日期语言名称。 * NLS_SORT:返回排序规则。 * CURRENT_USER:返回当前用户名称。 * CURRENT_USERID:返回当前用户...

    PHP函数参考手册大全

    Calendar 日历函数 X. CCVS API Functions [deprecated] XI. Character Type Functions XII. Classes/Objects 类/对象函数 XIII. Classkit Functions XIV. ClibPDF Functions XV. COM 和 .Net(Windows)函数 XVI....

    oracle-j2sdk1.8-1.8.0+update181-1.x86-64.rpm

    - **日期与时间API**: java.time包取代了旧的java.util.Date和Calendar,提供了更易用、更强大的日期和时间处理功能。 - **默认方法**: 接口中可以定义有实现的方法,增强了接口的功能。 - **类型接口**: 针对...

Global site tag (gtag.js) - Google Analytics