Print calendar with PLSQL

Source: Internet
Author: User

Recently, after reading the concept, I suddenly felt empty. Not much gossip.

I used PLSQL to write a calendar printing function.

Create or replace package display_date is
Procedure display_spec_mon (year number, month number );
End;

 

Create or replace package body display_date is
Type t_conv_mon is table of varchar2 (10 );
Conv_mon t_conv_mon: = t_conv_mon ();
Procedure display_title (year number, month number)
Is
Begin
Dbms_output.put_line (year | '.' | conv_mon (month ));
Dbms_output.put_line (lpad ('', 21 ,'-'));
Dbms_output.put_line ('su Mo Tu We Th Fr Sa ');
End;
Procedure display_spec_mon (year number, month number)
Is
Current_mon date;
Current_line varchar2 (21 );
Begin
-- Dbms_output.put_line (year | lpad (month | '', 2, '0') | '01 ');
Display_title (year, month );
Current_mon: = to_date (year | lpad (month | '', 2, '0') | '01', 'yyyymmdd ');
For I in 1 .. (add_months (current_mon, 1)-current_mon) loop
If I = 1 then
Current_line: = current_line | (lpad ('', (to_char (current_mon + I-1, 'd)-1) * 3 ,'--'));
End if;
Current_line: = current_line | rpad (I | '', 3 ,'');
If length (current_line)> = 21 then
Dbms_output.put_line (current_line );
Current_line: = '';
End if;
End loop;
Dbms_output.put_line (current_line );
End;


Begin
Conv_mon.extend (12 );
Conv_mon (1): = 'january ';
Conv_mon (2): = 'february ';

Conv_mon (3): = 'marcy ';
Conv_mon (4): = 'cmdl ';

Conv_mon (5): = 'may ';
Conv_mon (6): = 'june ';

Conv_mon (7): = 'july ';
Conv_mon (8): = 'August ';

Conv_mon (9): = 'September ';
Conv_mon (10): = 'October ';

Conv_mon (11): = 'November ';
Conv_mon (12): = 'decimal ';
End;

 

Execution result:

_ Sys @ DAVID> exec display_date.display_spec_mon (maid );
2013. October
--------------------
Su Mo Tu We Th Fr Sa
-- 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.

_ Sys @ DAVID> exec display_date.display_spec_mon (hz12 );
2012. December
--------------------
Su Mo Tu We Th Fr Sa
-- 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.