简体   繁体   English

如何在Pl / SQL中显示输出

[英]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. 我想知道是否有人可以帮助我弄清楚如何编写代码,以便在运行程序时无需使用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;

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. 如果使用的是sqlplus,请尝试使用以下命令打开serveroutput。

set serveroutput on 将serveroutput设置为on

if using another client program, look up the documentation for enabling server output. 如果使用其他客户端程序,请查找文档以启用服务器输出。

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

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