Question
  1. Create a function that will accept a date as input and will return if this date happens in fall, spring, winter or summer. Before you start writing this function experiment with queries below.

Current date

select sysdate from dual;

Yesterday

select sysdate - 1 from dual;

Tomorrow

select sysdate + 1 from dual;

The date format element D returns the number of the day of the week (1-7).

select to_char(sysdate,'D') from dual;

MM returns two-digit numeric abbreviation of month (01-12; JAN = 01)

select to_char(sysdate,'MM') from dual;

SYSDATE 21-MAY-19 SYSDATE-1 20-MAY-19 SYSDATE+1 22-MAY-19 TO 05 LnWorksheet Query Builder SELECT season (29-JAN-19) FROM DUAL SE LECT season (11-APR-19) FROM DUAL; Query Result Script Out

Let us for simplicity use winter December-February, spring March – May, summer June-August, and fall September – November

SYSDATE 21-MAY-19 SYSDATE-1 20-MAY-19 SYSDATE+1 22-MAY-19 TO 05 Ln
Worksheet Query Builder SELECT season ('29-JAN-19') FROM DUAL SE LECT season ('11-APR-19') FROM DUAL; Query Result Script Output x Task completed in 0.047 seconds SEASON ('29-JAN-19') 29-JAN-19 is winter SEASON ('11-APR-19') 11-APR-19 is spring
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the script that wil create a function names SEASON as per the requirement. It is well explained inside the script using comments.

-- Creates or replaces function SEASON
-- It expects
date as input
CREATE OR REPLACE FUNCTION SEASON(
inputDate DATE)
   RETURN VARCHAR2
   IS
    mm INT; -- declare
varible to store month
   BEGIN
    -- extract month from the given date
    SELECT CAST(TO_CHAR(
inputDate,'MM')AS INT) INTO mm FROM DUAL;
  
    -- find season using month, and return the message with season
    IF mm BETWEEN 3 AND 5
    THEN
        RETURN TO_CHAR(inputDate, 'DD-MON-YY') ||' is spring';
    ELSIF mm BETWEEN 6 AND 8
    THEN
        RETURN TO_CHAR(inputDate, 'DD-MON-YY') ||' is summer';
    ELSIF mm BETWEEN 9 AND 11
    THEN
        RETURN TO_CHAR(inputDate, 'DD-MON-YY') ||' is fall';
    ELSE
        RETURN TO_CHAR(inputDate, 'DD-MON-YY') ||' is winter';
    END IF;
    
    END SEASON;
/

Below screenshot displays that it ran successfully:

Creates or replaces function SEASON It expects date as input ECREATE OR REPLACE FUNCTION SEASON (inputDate DATE) RETURN VARCH

Below are the sample outputs of function run:

SELECT SEASON (29-JAN-19) FROM DUAL; Query Result x All Rows Fetched: 1 in 0.004 seconds E sQL SEASON(29-JAN-19) 1 29-JAN-1

SELECT SEASON 11-APR-19) FROM DUAL; Query Result sQL | All Rows Fetched: 1 in 0.006 seconds * 2 h SEASON(11-APR-19) 1 11-AP

SELECT SEASON (10-AUG-19) FROM DUAL; Query Resultx SQL| All Rows Fetched: 1 in 0.01 seconds SEASON(10-AUG-19) 1 10-AUG-19 i

This completes the requirement. Let me know if you have any queries.

Thanks!

Add a comment
Know the answer?
Add Answer to:
Create a function that will accept a date as input and will return if this date happens in fall, spring, winter or summ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The administrator of a hospital is interested in predicting the amount of gross patient revenue that the organization expects to earn during the winter, spring, summer, and fall of the next year. the...

    The administrator of a hospital is interested in predicting the amount of gross patient revenue that the organization expects to earn during the winter, spring, summer, and fall of the next year. the following data represent the gross patient revenue earned in the past 6 years. Season Time Gross Revenue Moving average Winter 1 36 Spring 2 27 Summer 3 15.1 Fall 4 37.8 = Winter 5 47.6 Spring 6 41.4 Summer 7 26.9 Fall 8 51.7 Winter 9 53.3...

  • I need the answer to #2 listed above. This is the code I have come up...

    I need the answer to #2 listed above. This is the code I have come up with, and it is wrong. I am new to this and need help. group by sust.cida Q2 (7 Points) Show customer id (CID) for customers who have spent 30,000 or more with the company in 2019. Money is considered "spent" when the entire work order is completed as recorded in workorder.completionDate. (Correct query will find customer 2). Use ONE SQL statement. select workarder.id from...

  • Create a procedure to update the sales history table following the requirements below. A table creation...

    Create a procedure to update the sales history table following the requirements below. A table creation script is provided below. a) Call the procedure: UPDATE_SALES_HISTORY (The procedure name is important for our scripts to test and grade your code; please do not rename it (otherwise our scripts will not run and your score will be 0). b) The procedure takes 2 parameters: (4-digit-year, 2-digit-month). Both parameters will be numeric, e.g., (2019, 11) will denote 2019 (year) and November (month). The...

  • Code with Java using arrays and Scanner only ( input should end with 0 to terminate...

    Code with Java using arrays and Scanner only ( input should end with 0 to terminate the program) Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social interaction among co-workers, foster friendship among classmates or even strengthen bond between families. Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, candles with names, or it can be in the form of simple bar chart to indicate the birthday...

  • Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing...

    Java code BIRTHDAY GRAPH5 4B Input Standard input Output Standard output Topic Array & Array Processing Birthday Graph Problem Description Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social E interaction among co-workers, foster friendship among classmates or even strengthen bond between E BOBO Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, UU candles with names, or it can be in the form of simple bar...

  • Mountain Ski Sports, a chain of ski-equipment shops in Colorado, purchases skis from a manufacturer each...

    Mountain Ski Sports, a chain of ski-equipment shops in Colorado, purchases skis from a manufacturer each summer for the coming winter season. The most popular intermediate model costs $150 and sells for $275. Any skis left over at the end of the winter are sold at the store's spring sale (for $100). Sales over the years are quite stable. Gathering data from all its stores, Mountain Ski Sports developed the following probability distribution for demand: Demand Probability 150 0.05 175...

  • Partial Question 10 1/2 pts Give the SQL statement to list the trip name and state...

    Partial Question 10 1/2 pts Give the SQL statement to list the trip name and state for each trip that occurs during one of the Fall seasons that is Early Fall, Spring and Late Fall. Sort by State. Use the wildcard for the season. SELECT TripName, State FROM Trip WHERE Season LIKE '%Fall' OR SEA ORDER BY State: Answer 1: LIKE '%Fall' OR SEASON LIKE 'Spring' Answer 2: ORDER BY Partial Question 11 1/2 pts Give the SQL statement to...

  • USE colonial; CREATE TABLE CUSTOMER (CUSTOMER_NUM CHAR(4) PRIMARY KEY, LAST_NAME CHAR(30) NOT NULL, FIRST_NAME CHAR (30),...

    USE colonial; CREATE TABLE CUSTOMER (CUSTOMER_NUM CHAR(4) PRIMARY KEY, LAST_NAME CHAR(30) NOT NULL, FIRST_NAME CHAR (30), ADDRESS CHAR(35), CITY CHAR(35), STATE CHAR(2), POSTAL_CODE CHAR(5), PHONE CHAR(12) ); CREATE TABLE RESERVATION (RESERVATION_ID CHAR(7) PRIMARY KEY, TRIP_ID DECIMAL(3,0), TRIP_DATE DATE, NUM_PERSONS DECIMAL(3,0), TRIP_PRICE DECIMAL(6,2), OTHER_FEES DECIMAL(6,2), CUSTOMER_NUM CHAR(4) ); CREATE TABLE TRIP (TRIP_ID DECIMAL(3,0) PRIMARY KEY, TRIP_NAME CHAR(75), START_LOCATION CHAR(50), STATE CHAR(2), DISTANCE DECIMAL(4,0), MAX_GRP_SIZE DECIMAL(4,0), TYPE CHAR(20), SEASON CHAR(20) ); CREATE TABLE TRIP_GUIDES (TRIP_ID DECIMAL(3,0), GUIDE_NUM CHAR(4), PRIMARY KEY (TRIP_ID, GUIDE_NUM)...

  • Mountain Ski Sports, a chain of ski-equipment shops in Colorado, purchases skis from a manufacturer each...

    Mountain Ski Sports, a chain of ski-equipment shops in Colorado, purchases skis from a manufacturer each summer for the coming winter season. The most popular intermediate model costs $150 and sells for $275. Any skis left over at the end of the winter are sold at the store's spring sale (for $100). Sales over the years are quite stable. Gathering data from all its stores, Mountain Ski Sports developed the following probability distribution for demand: Demand Probability 150 0.05 175...

  • A guide to SQL 9th edition Colonial Adventure Tours chapter 3 page 90-92 Odd numbered exercises...

    A guide to SQL 9th edition Colonial Adventure Tours chapter 3 page 90-92 Odd numbered exercises only figure 3-39(Guide, trip, customer, reservation and Trip_Guides) figure 1-5 chapter 1: 7. Review me on TUI UTILIVUDIJ types used to create the ITEM table in Figure 3-34. Suggest alternate data types for the DESCRIPTION, ON HAND. and STOREHOUSE fields and explain your recommendation Colonial Adventure Tours Use SQL to complete the following exercises 1. Create a table named ADVENTURE TRIP. The table has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT