473,414 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

How to write a calendar with pl/sql?

2
Hi,everybody,I am trying to write a calendar with pl/sql and the program output like this
SUN MON TUE WED THU FRI SAT
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

but I don't konw how to start work,can you give me a useful instance?
Thanks.
Nov 24 '06 #1
5 10824
pragatiswain
96 Expert
Hi,everybody,I am trying to write a calendar with pl/sql and the program output like this
SUN MON TUE WED THU FRI SAT
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

but I don't konw how to start work,can you give me a useful instance?
Thanks.
Hope the following will help you. I have not tested it. please correct the syntax incase of any syntax error.

DECLARE

MYDATE DATETIME;
MYDATEMAX datetime;

I_WEEK_DAY INTEGER; -- VARIES BETWEEN 1 - 7 (SUNDAY - SATURDAY)
C_DATE VARCHAR2;
I_MONTH INTEGER;
I_YEAR INTEGER;
CAL_STR1 VARCHAR2;
CAL_STR2 VARCHAR2;
CAL_STR3 VARCHAR2;
CAL_STR4 VARCHAR2;
CAL_STR5 VARCHAR2;
CAL_STR6 VARCHAR2;
CAL_STR7 VARCHAR2;

CAL_STR1 := 'SUN';
CAL_STR2 := 'MON';
CAL_STR3 := 'TUE';
CAL_STR4 := 'WED';
CAL_STR5 := 'THU';
CAL_STR6 := 'FRI';
CAL_STR7 := 'SAT';

SELECT SYSDATE INTO MYDATE FROM DUAL;

MYDATE := TO_DATE (TO_CHAR(MYDATE,'MM') ||'/01/' || TO_CHAR(MYDATE,'YYYY'), 'MM/DD/YYYY');
MYDATEMAX := TO_DATE (LPAD(TO_CHAR(TO_NUMBER(TO_CHAR(MYDATE,'MM')) + 1),2,'0') ||'01' || TO_CHAR(MYDATE,'/YYYY'), 'MM/DD/YYYY');

WHILE (MYDATE < MYDATEMAX)
LOOP

SELECT TO_NUMBER(TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'D')),
TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'DD'),
TO_NUMBER(TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'MM')),
TO_NUMBER(TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'YYYY'))
INTO I_WEEK_DAY, C_DATE, I_MONTH, I_YEAR FROM DUAL;

IF (I_WEEK_DAY = 1) THEN
CAL_STR1 := CAL_STR1 || ' ' || C_DATE;
ELSE IF (I_WEEK_DAY = 2) THEN
CAL_STR2 := CAL_STR2 || ' ' || C_DATE;
ELSE IF (I_WEEK_DAY = 3) THEN
CAL_STR3 := CAL_STR3 || ' ' || C_DATE;
ELSE IF (I_WEEK_DAY = 4) THEN
CAL_STR4 := CAL_STR4 || ' ' || C_DATE;
ELSE IF (I_WEEK_DAY = 5) THEN
CAL_STR5 := CAL_STR5 || ' ' || C_DATE;
ELSE IF (I_WEEK_DAY = 6) THEN
CAL_STR6 := CAL_STR6 || ' ' || C_DATE;
ELSE
CAL_STR7 := CAL_STR7 || ' ' || C_DATE;
END IF;

MYDATE := MYDATE + 1;

END LOOP;

Set the application font to Arial size 10 for proper alignment
Nov 24 '06 #2
Joe m
2
Thanks for your direction though I have a lot of unstudied question all the same
Nov 28 '06 #3
But while trying to compile it , it is showing error:

CAL_STR1 := 'SUN';
*

ERROR at line 18:
ORA-06550: line 18, column 10:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table LONG_ double ref
char time timestamp interval date binary national character
nchar
The symbol "<an identifier>" was substituted for "=" to continue.
ORA-06550: line 19, column 10:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table LONG_ double ref
char time timestamp interval date binary national chara
ORA-06550: line 20, column 10:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an identifier>
<a double-quoted delimited-identifier> table LONG_ double ref
char time timestamp interval date binary national chara
ORA-06550: line 21, column 10:
PLS-00103: Encountered the symbol "=" when expecting one of the following:
constant exception <an iden




Please reply me

Thanks in advance
Balveer
May 20 '10 #4
debasisdas
8,127 Expert 4TB
try the following sample sql

Expand|Select|Wrap|Line Numbers
  1. with x
  2.       as (
  3.    select *
  4.      from (
  5.    select to_char(trunc(sysdate,'mm')+level-1,'iw') wk,
  6.           to_char(trunc(sysdate,'mm')+level-1,'dd') dm,
  7.           to_number(to_char(trunc(sysdate,'mm')+level-1,'d')) dw,
  8.           to_char(trunc(sysdate,'mm')+level-1,'mm') curr_mth,
  9.           to_char(sysdate,'mm') mth
  10.     from dual
  11.    connect by level <= 31
  12.          )
  13.    where curr_mth = mth
  14.   )
  15.   select max(case dw when 2 then dm end) Mon,
  16.          max(case dw when 3 then dm end) Tue,
  17.          max(case dw when 4 then dm end) Wed,
  18.          max(case dw when 5 then dm end) Thu,
  19.          max(case dw when 6 then dm end) Fri,
  20.          max(case dw when 7 then dm end) Sat,
  21.          max(case dw when 1 then dm end) Sun
  22.     from x
  23.    group by wk
  24.    order by wk
May 24 '10 #5
DECLARE
MYDATE DATE;
MYDATEMAX date;
I_WEEK_DAY number(15); -- VARIES BETWEEN 1 - 7 (SUNDAY - SATURDAY)
C_DATE VARCHAR2(50);
I_MONTH number(15);
I_YEAR number(15);
CAL_STR1 VARCHAR2(50);
CAL_STR2 VARCHAR2(50);
CAL_STR3 VARCHAR2(50);
CAL_STR4 VARCHAR2(50);
CAL_STR5 VARCHAR2(50);
CAL_STR6 VARCHAR2(50);
CAL_STR7 VARCHAR2(50);
begin
CAL_STR1 := 'SUN';
CAL_STR2 := 'MON';
CAL_STR3 := 'TUE';
CAL_STR4 := 'WED';
CAL_STR5 := 'THU';
CAL_STR6 := 'FRI';
CAL_STR7 := 'SAT';
SELECT SYSDATE INTO MYDATE FROM DUAL;
MYDATE := TO_DATE (TO_CHAR(MYDATE,'MM') ||'/01/' || TO_CHAR(MYDATE,'YYYY'), 'MM/DD/YYYY');
MYDATEMAX := TO_DATE (LPAD(TO_CHAR(TO_NUMBER(TO_CHAR(MYDATE,'MM')) + 1),2,'0') ||'01' || TO_CHAR(MYDATE,'/YYYY'), 'MM/DD/YYYY');
WHILE (MYDATE < MYDATEMAX)
LOOP
SELECT TO_NUMBER(TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'D')),
TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'DD'),
TO_NUMBER(TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'MM')),
TO_NUMBER(TO_CHAR(TO_DATE(MYDATE,'MM/DD/YYYY'),'YYYY'))
INTO I_WEEK_DAY, C_DATE, I_MONTH, I_YEAR FROM DUAL;
IF (I_WEEK_DAY = 1) THEN
CAL_STR1 := CAL_STR1 || ' ' || C_DATE;
ELSIF (I_WEEK_DAY = 2) THEN
CAL_STR2 := CAL_STR2 || ' ' || C_DATE;
ELSIF (I_WEEK_DAY = 3) THEN
CAL_STR3 := CAL_STR3 || ' ' || C_DATE;
ELSIF (I_WEEK_DAY = 4) THEN
CAL_STR4 := CAL_STR4 || ' ' || C_DATE;
ELSIF (I_WEEK_DAY = 5) THEN
CAL_STR5 := CAL_STR5 || ' ' || C_DATE;
ELSIF (I_WEEK_DAY = 6) THEN
CAL_STR6 := CAL_STR6 || ' ' || C_DATE;
ELSE
CAL_STR7 := CAL_STR7 || ' ' || C_DATE;
END IF;
MYDATE := MYDATE + 1;
dbms_output.put_line(mydate);
END LOOP;
end;
Mar 15 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hitit | last post by:
I found the script below in internet and I want it to create a page with links for each date changing according to date. For example: For August 10, the link in calendar page should point to:...
2
by: Chuck Hartman | last post by:
I've been trying to add an ImageButton object to a Calendar table cell, but so far I am unable to handle the Command event from that button in my form's code behind. Below is an example of what I...
1
by: malgorzata | last post by:
i have this script that i found on internet, but i nedd to compare the dates in calendar with the ones i pick up from database oracle using jsp. and i have a proble with it, can someone help me? ...
2
by: Kajsa Anka | last post by:
Before I re-invent something I would like to ask if there exists some code that can be used for create the HTML code for a calendar which I then can include on a web page. The module in the...
7
by: pankajit09 | last post by:
Hello, I have developed a calendar program in Javascript which opens a calendar as a popup window and when a user clicks on a date the date is copied into the parent windows textbox. The code...
4
by: gubbachchi | last post by:
Hi all, Please anybody help me solve this problem. I am stuck up with this from past 2 weeks. I am developing an application where, when the user selects date from javascript datepicker and enters...
1
by: abhishekbrave | last post by:
The code below is opening a calendar on mouse over in the same window. I need the calendar to be opened in new window. Have to fulfill this requirement urgentely so posting the whole code here. I...
7
by: William (Tamarside) | last post by:
Please, if you have the time and knowledge to help me I'd truly appreciate it! I need to build a calendar page that displays available/unavailable info from a DB and colour a cell according to...
8
by: Arhaus | last post by:
I was wondering if someone could help me out. I am new to jscript and I need to modify a calendar onclick event. We have a calendar which displays the dates either in green or red based upon data...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.