繁体   English   中英

如何在Pl / SQL中显示输出

[英]How to display output in Pl/SQL

我想知道是否有人可以帮助我弄清楚如何编写代码,以便在运行程序时无需使用month_days中的select *命令即可显示输出。

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;

这是你想要的 ??

我还没有测试。 我认为应该可以。

采用:

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;

如果使用的是sqlplus,请尝试使用以下命令打开serveroutput。

将serveroutput设置为on

如果使用其他客户端程序,请查找文档以启用服务器输出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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