簡體   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