Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Testing for holidays, part 2

I saw your previous solution for counting the number of work days. How can I modify it to not count dates in my holiday table?

```CREATE TABLE  holiday
(
id         NUMBER (10)    PRIMARY KEY,
start_dt   DATE           NOT NULL,
end_dt     DATE           NOT NULL,
cmnt       VARCHAR2 (100)
);
```

I've attached some sample data for the table.

The following is continued from part 1.

### Code for holiday_num Function

When comparing dates in Oracle, always remember that they contain a time component. When you ask "Is SYSDATE + 21 a holiday?", you may think you're asking "Is October 13 a holiday?", but actually you're asking "Is October 13, 1:08 p.m., a holiday?". Is the difference significant? It is if you inserted '13-Oct-2003' as the end of the holiday, because Oracle interprets that as being 12 midnight at the beginning of October 13, which is before 1:08 in the afternoon of the same day. Use the TRUNC function if you want to ignore the time of day.

```--  holiday_num returns a positive number if in_dt is
--  a holiday according to the holiday table (that is,
--  if in_dt falls between start_dt and end_dt (inclusive)
--  for some row in holiday.
--    The number returned is the id for that row (or for
--  an arbitrary one of the rows, if there are several.)
--    If in_dt is not a holiday, 0 is returned.  (Therefore,
--  don't use 0 as an id.)

CREATE OR REPLACE FUNCTION holiday_num
(
in_dt  DATE
)
RETURN  NUMBER
IS
first_id  holiday.id%TYPE;
BEGIN
SELECT  id
INTO   first_id
FROM   holiday
WHERE  TRUNC (in_dt) BETWEEN TRUNC (start_dt)
AND (end_dt)
AND  ROWNUM = 1;

RETURN  first_id;    -- It is a holiday
EXCEPTION
WHEN  NO_DATA_FOUND
THEN  RETURN 0;  -- Not a holiday
WHEN  OTHERS
THEN  RETURN NULL;
END  holiday_num;
```

### Sample Data

```INSERT INTO  holiday
(
id,
start_dt,
end_dt,
cmnt
)
VALUES
(
holiday_id_seq.NEXTVAL,
'13-Oct-2003',
'13-Oct-2003',
'Columbus Day'
);

INSERT INTO  holiday
(
id,
start_dt,
end_dt,
cmnt
)
VALUES
(
holiday_id_seq.NEXTVAL,
'27-Nov-2003',
'28-Nov-2003',
'Thanksgiving (Thursday); business closed Friday, too'
);
```

#### Start the conversation

Send me notifications when other members comment.

## SearchDataManagement

• ### PlanetScale extends multi-cloud database as a service

Open source-based PlanetScaleDB adds support for Microsoft Azure, enabling a multi-cloud database as a service platform that ...

• ### Oracle NoSQL database comes to the cloud

Another Oracle database is coming to the cloud with the general availability of Oracle NoSQL Database Cloud Service as the demand...

• ### MariaDB SkySQL enables cloud-native database as a service

MariaDB brings back an old name for its cloud-native database-as-a-service platform. MariaDB CEO Michael Howard details how he's ...

• ### Importance of analytics clear amid COVID-19 crisis

With health organizations and business leaders alike trying to minimize the effects of COVID-19, analytics is playing a critical ...

• ### AI tools in analytics software key in fighting COVID-19

With data skewed by incomplete testing, augmented intelligence and machine learning tools are helping data scientists create ...

• ### Should your company hire a freelance data scientist?

Enterprises need to make the right hiring choices when it comes to supporting their data projects. Here are some reasons your ...

## SearchSAP

• ### SAP S/4HANA deployment options: Legacy ERP vs. cloud

Take this tour of the on-premises S/4HANA and its two cloud siblings and get expert advice on major differences in cost and ...

• ### Floating the possibilities of SAP S/4HANA Cloud migration

When weighing the advantages of abandoning legacy ERP systems for SAP S/4HANA Cloud, factors include implementation and support ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Eclipse launches Theia 1.0 as alternative to VS Code

The Eclipse Foundation's Theia framework for building desktop and cloud IDEs has the potential to be as big as the initial ...

• ### Developing a COVID-19 application? Design it the right way

Application developers with skills and an idea could design an app to combat the virus. Follow these insights to effectively ...

• ### How developers can volunteer during the COVID-19 pandemic

What resources can developers offer to go against COVID-19? Explore some promising developer volunteer and open source project ...

## SearchDataCenter

• ### Build a migration plan for enterprise edge infrastructure

Micro data centers are essential to edge computing use cases. Build an effective migration plan through site selection, ...

• ### Tech giants aim supercomputers, clouds at finding a COVID-19 cure

The new COVID-19 HPC consortium comprised of tech giants, national labs and academia are using supercomputers and clouds to speed...

• ### Top vendor SDDC certification programs for admins

If you decide to grow your knowledge of software-defined data center technologies, VMware, Nuage Networks and Microsoft offer ...

## SearchContentManagement

• ### Creating digital experiences key to driving exceptional CX

The way in which businesses build digital experiences is ever-evolving. It's a race to create easier-to-use customer interfaces ...

• ### Vendors offer free remote work technology for telecommuting

It's more than a marketing ploy: Cloud technology vendors, seeing their own issues enabling remote work, extend paid products to ...

• ### How businesses should deal with enterprise search issues

Enterprise search issues frequently complicate user experience with ECM systems. While users may face many problems, they also ...

## SearchHRSoftware

• ### How to create an employee journey map

This handy guide shows you how to build your own employee journey map, which is more important than ever as the coronavirus ...

• ### Remote team tech Sneek keeps co-workers in view

Sneek, a remote team platform, uses frequently updated photographs of remote workers to connect co-workers together.

• ### Best-case, worst-case pandemic scenarios for India service providers

India's IT and business support services will be tested during that country's pandemic lockdown. Many workers are now operating ...

Close