0

I was wondering if someone can help me figure out how to code so that it will display the output without me having to use the command select * from month_days when I run the program.

set serveroutput on

--- Drop Table
DROP TABLE MONTH_DAYS;
--- Create Table 
CREATE TABLE MONTH_DAYS(cnt number(2), Month_ Varchar(9),Days_ Number(2));

Declare
mons varchar2(10);
dats varchar2(10);
i Binary_integer := 0;

Begin
loop
i:= i+1;
if i = 13 then
exit;
end if;
insert into month_days(cnt, month_, days_)`enter code here`
values
(i, to_char(add_months(to_date('20200112', 'YYYYDDMM'), i), 'Month'),
to_char(last_day(add_months(to_date('20200112', 'YYYYDDMM'), i)), 'DD'));
end loop;
DBMS_Output.Put_Line('The Month and Days for the year 2020'||Month_|| ''||Days_);
end;
3
  • 1
    What is your question? What is your problem? Commented Nov 21, 2013 at 22:03
  • My question is that how do I change my code so that it display the output of the months and days also because it only display what I have in quote when I run the program. Commented Nov 21, 2013 at 22:15
  • If you want to just see the output you have already done it. IF you want to see the output in tabular format. What you do is change this to a function say "insert_date" . then call it like select insert_date(12,1986) from dual; Commented Nov 22, 2013 at 1:55

3 Answers 3

2

Create or Replace function insert_date (mons varchar2, dats varchar2)
return varchar2
as
i Binary_integer := 0;
Begin
loop
i:= i+1;
if i = 13 then
exit;
end if;
insert into month_days(cnt, month_, days_)
//enter code here Didn't understood what you are trying to do here
values
(i, to_char(add_months(to_date('20200112', 'YYYYDDMM'), i), 'Month'), to_char(last_day(add_months(to_date('20200112', 'YYYYDDMM'), i)), 'DD'));
end loop;
return 'The Month and Days for the year 2020'||Month_|| ''||Days_;
end;
select insert_date(12,2) from dual;

Is this what you are looking for ??

I haven't tested this. I think it should work.

Sign up to request clarification or add additional context in comments.

Comments

1

Use:

select
  rownum cnt,
  to_char(add_months(date '2020-12-01', rownum), 'Month') month_,
  to_char(last_day(add_months(date '2020-12-01', rownum)), 'DD')) days_
from
  dual
connect by
  level <= 12;

Comments

0

If you're using sqlplus, try turning serveroutput on by using the following command.

set serveroutput on

if using another client program, look up the documentation for enabling server output.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.