暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle PL/SQL日期处理

askTom 2018-08-31
429

问题描述

嗨,先生,
我有一个杜德。如何在pl/sql中找到月份的位置,以及如何打印月份的季度。

所以,请告诉我语法和解释。

输入:-
一月

输出:-
一月 IS FIRST QUARTER
一月 IS 1ST POSITION OF THIS YEAR.

专家解答

像这样的东西?

SQL> create or replace
  2  procedure show_month(p_input varchar2) is
  3    l_mth_num int;
  4    l_mth_qtr int;
  5  begin
  6    l_mth_num := to_number(to_char(to_date(p_input,'MONTH'),'MM'));
  7    l_mth_qtr := to_number(to_char(to_date(p_input,'MONTH'),'Q'));
  8
  9    dbms_output.put_line(p_input||' is month '||l_mth_num);
 10    dbms_output.put_line(p_input||' is quarter '||l_mth_qtr);
 11  end;
 12  /

Procedure created.

SQL>
SQL>
SQL> exec show_month('JANUARY');
JANUARY is month 1
JANUARY is quarter 1

PL/SQL procedure successfully completed.

SQL> exec show_month('MARCH');
MARCH is month 3
MARCH is quarter 1

PL/SQL procedure successfully completed.

SQL> exec show_month('AUGUST');
AUGUST is month 8
AUGUST is quarter 3

PL/SQL procedure successfully completed.


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论