Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question.

Asked: August 31, 2018 - 5:11 pm UTC

Last updated: September 05, 2018 - 4:49 am UTC

Version: ORACLE 12C

Viewed 1000+ times

You Asked

Hi sir,
I have one dought. How to find position of the month in pl/sql and also how to print quarter of the month.

So, please tell me the syntax and explanation.

Input:-
JANUARY

Output:-
JANUARY IS FIRST QUARTER
JANUARY IS 1ST POSITION OF THIS YEAR.

and Connor said...

Something like this ?

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.


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, September 04, 2018 - 12:23 pm UTC

Thank you sir.
Connor McDonald
September 05, 2018 - 4:49 am UTC

Glad to help

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library