w3resource

PL/SQL Control Statement Exercises: Check whether a date falls on weekend i.e. SATURDAY or SUNDAY

PL/SQL Control Statement: Exercise-5 with Solution

Write a PL/SQL program to check whether a date falls on weekend i.e. SATURDAY or SUNDAY.

Sample Solution:

PL/SQL Code:

DECLARE
dt1 DATE := TO_DATE('&new_dt', 'DD-MON-YYYY');
get_day VARCHAR2(15);
BEGIN
get_day := RTRIM(TO_CHAR(dt1, 'DAY'));
IF get_day IN ('SATURDAY', 'SUNDAY') THEN
dbms_output.new_line;
DBMS_OUTPUT.PUT_LINE 
('The day of the given date is '||get_day||' and it falls on weekend');
ELSE
dbms_output.new_line;
DBMS_OUTPUT.PUT_LINE ('The day of the given date is '||get_day||' and it does not fall on the weekend');
END IF;
DBMS_OUTPUT.PUT_LINE ('Execution  done successfully.');
END;
/

Sample Output:

Enter value for new_dt: 5-MAY-2018
old   2: dt1 DATE := TO_DATE('&new_dt', 'DD-MON-YYYY');
new   2: dt1 DATE := TO_DATE('5-MAY-2018', 'DD-MON-YYYY');

The day of the given date is SATURDAY and it falls on weekend
Execution  done successfully.

PL/SQL procedure successfully completed.

Flowchart:

Flowchart: PL/SQL Control Statement Exercises: Check whether a date falls on weekend i.e. SATURDAY or SUNDAY.

Improve this sample solution and post your code through Disqus

Previous: Write a PL/SQL procedure to calculate the incentive on a specific target otherwise a general incentive to be paid using IF-THEN-ELSE.
Next: Write a PL/SQL procedure to calculate incentive achieved according to the specific sale limit.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.