rockvault
asked on
A pl/sql program to display date variable and assigns sysdate to it?
I need to write a pl/sql program that declares a date variable named 'today' and assigns sysdate to it. Output should hopefully look like the following:
(day 1-10) "It is the <day number> of <month name>. It is early in the month,"
Here is what I have so far...
>declare
todaysdate date;
positionofday binary_integer;
today varchar2(9);
begin
todaysdate := sysdate;
positionofday := instr(today, 'day');
today :=to_char(sysdate, 'day');
dbms output.put_line(today is '|| today || to_char(todaysdate));
if positionofday = '1' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '2' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '3' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '4' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '5' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '6' then
dbms_output.put_line('it is early in the month');
else
dbms_output.put_line('erro r displaying day information');
end if;
end;
/
THanks for any and all help.
-rockvault
(day 1-10) "It is the <day number> of <month name>. It is early in the month,"
Here is what I have so far...
>declare
todaysdate date;
positionofday binary_integer;
today varchar2(9);
begin
todaysdate := sysdate;
positionofday := instr(today, 'day');
today :=to_char(sysdate, 'day');
dbms output.put_line(today is '|| today || to_char(todaysdate));
if positionofday = '1' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '2' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '3' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '4' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '5' then
dbms_output.put_line('it is early in the month');
elsif positionofday = '6' then
dbms_output.put_line('it is early in the month');
else
dbms_output.put_line('erro
end if;
end;
/
THanks for any and all help.
-rockvault
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi all, would you settle for a basic SQL statement?
select 'It is the ' || to_char(sysdate, 'DD') ||
' of the month. It is ' ||
case when to_char(sysdate, 'DD') < 10
then ' early '
else ' late ' end
|| ' in the month.' "Today's Date"
from dual;
Today's Date
-------------------------- ---------- ---------- --------
It is the 25 of the month. It is late in the month.
BTW, I hope you've got 8i...
select 'It is the ' || to_char(sysdate, 'DD') ||
' of the month. It is ' ||
case when to_char(sysdate, 'DD') < 10
then ' early '
else ' late ' end
|| ' in the month.' "Today's Date"
from dual;
Today's Date
--------------------------
It is the 25 of the month. It is late in the month.
BTW, I hope you've got 8i...
ASKER
mozartny,
thanks a lot, just what i needed.
-rockvault
thanks a lot, just what i needed.
-rockvault
declare
v_today_str VARCHAR2(60);
v_day NUMBER;
begin
v_today_str := 'It is day '||to_char(sysdate, 'DD')||' of '||to_char(sysdate, 'MONTH')||'. ';
v_day := to_number(to_char(sysdate,
IF ((v_day/10) <= 1)
THEN
v_today_str := v_today_str || 'It is early in the month.';
ELSIF ((v_day/20) <= 1)
THEN
v_today_str := v_today_str || 'It is the middle of the month.';
ELSE
v_today_str := v_today_str || 'It is late in the month.';
END IF;
dbms_output.put_line(v_tod
end;