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:
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?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/plsql-exercises/control-statement/plsql-control-statement-exercise-5.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics