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