简体   繁体   中英

How to display output in Pl/SQL

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;

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.

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM