1.

Write a PL/SQL code to count the number of Sundays between the two inputted dates.

Answer»

--declare 2 DATES of type DateDECLARE start_date Date; end_date Date; sundays_count Number:=0; BEGIN -- input 2 dates start_date:='&input_start_date'; end_date:='&input_end_date'; /* Returns the date of the first day after the mentioned date and matching the day specified in second PARAMETER. */ start_date:=NEXT_DAY(start_date-1, 'SUNDAY'); --check the condition of dates by USING while loop. while(start_date<=end_date) LOOP sundays_count:=sundays_count+1; start_date:=start_date+7; END LOOP; -- print the count of sundays dbms_output.put_line('Total number of Sundays between the TWO dates:'||sundays_count); END; /

Input:
start_date = ‘01-SEP-19’
end_date = ‘29-SEP-19’

Output:
Total number of Sundays between the two dates: 5



Discussion

No Comment Found