EXTRACT Function
This function is used to retrieve or extract specific components from the date. We can extract day of the week from a date and the function returns an integer or numeric value. This numeric value describes the day of the week ( 1 – Sunday,2 – Monday, and so on).
Syntax:
EXTRACT(WEEKDAY FROM date_value)
Example: Retrieving Day of the Week Using EXTRACT Function
DECLARE
my_date DATE:= SYSDATE;
day_of_week NUMBER;
BEGIN
day_of_week := EXTRACT(DAY FROM my_date);
DBMS_OUTPUT.PUT_LINE('Day of the week(numeric): ' || day_of_week);
DBMS_OUTPUT.PUT_LINE('Day of the week(full name): ' || TO_CHAR(my_date, 'DY'));
END;
Output:
Explanation: The code retrieves the day of the week from the current date using the EXTRACT function and assigns it to the variable “day_of_week.” It then prints the numeric representation of the day and its full name using the DBMS_OUTPUT.PUT_LINE function. This provides both numeric and textual representations of the day of the week.
How to Get the Day of the Week for PL/SQL?
PL/SQL is a Procedural language extension for the Structured Query Language. SQL is a standard database language that can be used to manipulate and access relational databases where data is stored in tables. This language can create tables and manipulate the data stored in the tables using queries or statements like insert, delete, update, alter, etc.
The day of the week in PL/SQL can be used for a variety of database operations. In this article, we’ll look at how to retrieve this data in PL/SQL. We will start with the basics, like the TO_CHAR function and EXTRACT function.
With clear explanations and examples, you’ll learn how to use these techniques to improve your PL/SQL projects, improve database management, and make data analysis easier.