Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the INTERVAL DAY TO SECOND data type?

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces what the INTERVAL DAY TO SECOND data type is like, the content is very detailed, interested friends can refer to, hope to be helpful to you.

The INTERVAL DAY TO SECOND type can be used to store time intervals in days and seconds. The following statement creates a table called promotions to store promotion information. The promotions table contains a column of type INTERVAL DAY TO SECOND, duration, which is used to record the time interval during which the promotion is valid:

CREATE TABLE promotions (

Promotion_id INTEGER CONSTRAINT promotions_pk PRIMARY KEY

Name VARCHAR2 (30) NOT NULL

Duration INTERVAL DAY (3) TO SECOND (4)

);

Note that the precision of the day in the duration column is 3 and the precision of the fractional part of the second is 4. This means that you can store 3 digits for the days of the column and up to 4 digits to the right of the decimal point for the seconds of the column.

To provide an INTERVAL DAY TO SECOND literal to the database, you can use the following simplified syntax:

INTERVAL'[+ | -] [d] [h [: M [: s]]'[DAY [(days_precision)]])

[TO HOUR | MINUTE | SECOND [(seconds_precision)]]

● + or-is an optional indicator indicating whether the interval is positive or negative (the default is positive).

● d is the number of days in the interval.

● h is an optional parameter that represents the number of hours between times. If days and hours are specified, TO HOUR must be included in the INTERVAL clause.

● h is an optional parameter that represents the number of minutes of the interval. If days and minutes are specified, TO MINUTES must be included in the INTERVAL clause.

● s is an optional parameter that represents the number of seconds of the interval. If days and seconds are specified, TO SECOND must be included in the INTERVAL clause.

● days_precision is an optional parameter that describes the precision of the number of days (the default is 2).

● seconds_precision is an optional parameter that describes the precision of seconds (the default is 6).

An example of the literal amount of time interval

INTERVAL'3' DAY

The interval is 3 days.

INTERVAL'2' HOUR

The interval is 2 hours.

INTERVAL '25' MINUTE

The interval is 25 minutes.

INTERVAL '45' SECOND

The interval is 45 seconds.

INTERVAL'3 2 'DAY TO HOUR

The interval is 3 days and 2 hours.

INTERVAL'3 2purl 25' DAY TO MINUTE

The interval is 3 days, 2 hours and 25 minutes.

INTERVAL'3 2 purl 25 purl 45 'DAY TO SECOND

The interval is 3 days, 2 hours, 25 minutes and 45 seconds.

INTERVAL '123 2 25 45.12' DAY (3)

TO SECOND (2)

The time interval is 123 days, 2 hours, 25 minutes and 45.12 seconds; the precision of days is 3 digits, and the precision of the decimal part of seconds is 2 digits

INTERVAL'3 2VOG 00UR 45' DAY TO SECOND

The interval is 3 days, 2 hours, 0 minutes and 45 seconds.

INTERVAL'- 3, 2, 2, 25, 15, 45, DAY TO SECOND

The interval is negative, with a value of 3 days, 2 hours, 25 minutes and 45 seconds.

INTERVAL '1234 2 25 15 DAY (3)

TO SECOND

The time interval is not valid because the number of digits in days exceeds the specified precision of 3

INTERVAL '123 2VR 25 DAY 45.123'

TO SECOND (2)

The interval is not valid because the number of decimal places in seconds exceeds the specified precision of 2

The following INSERT statement adds a row of records to the promotions table:

INSERT INTO promotions (promotion_id, name, duration)

VALUES (1,'10% off Z Files', INTERVAL'3 'DAY)

INSERT INTO promotions (promotion_id, name, duration)

VALUES (2,'20% off Pop 3, INTERVAL'2 'HOUR)

INSERT INTO promotions (promotion_id, name, duration)

VALUES (3,'30 off Modern Science', INTERVAL'25 'MINUTE)

INSERT INTO promotions (promotion_id, name, duration)

VALUES (4,'20% off Tank War', INTERVAL'45 'SECOND)

INSERT INTO promotions (promotion_id, name, duration)

VALUES (5,'10% off Chemistry', INTERVAL'3 2 DAY TO MINUTE)

INSERT INTO promotions (promotion_id, name, duration)

VALUES (6,'20% off Creative Yell', INTERVAL'3 2 DAY TO SECOND 25 DAY TO SECOND)

INSERT INTO promotions (promotion_id, name, duration)

VALUES (7,'15% off My Front Line'

INTERVAL '123 2 TO SECOND 25 TO SECOND 45.12' DAY (3))

The following query retrieves the promotions table, noticing the formatting of the duration column values:

SELECT *

FROM promotions

PROMOTION_ID NAME DURATION

1 10% off Z Files + 003 0000VRO 00.0000

2 20% off Pop 3 + 000 0000 02 00.0000

3 30% off Modern Science + 000000 00VOG 25RU 00.0000

4 20% off Tank War + 000000 0000VOV 45.0000

5 10% off Chemistry + 003 02purl 25purl 00.0000

6 20% off Creative Yell + 003 02purl 25purl 45.0000

7 15% off My Front Line + 123 02 25 purl 45.1200

So much for sharing about the INTERVAL DAY TO SECOND data type. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report