Interval Literal (SQL)

Introduction

The SQL Interval Literal defines a constant elapsed time.

Syntax

primary-literal-interval ::=
  INTERVAL [ sign ] interval-string interval-qualifier

interval-string ::=
  ' unquoted-interval-string '

interval-qualifier ::=
  start-interval-type [ TO end-interval-type ]

start-interval-type ::=
  interval-type

end-interval-type ::=
  interval-type

interval-type ::=
  SECOND | MINUTE | HOUR | DAY

Remarks

The INTERVAL keyword introduces an interval literal. The format of the unquoted-interval-string depends on which start and end interval types are used. The following combinations are supported:

Start Format End Format String Format Example
DAY 'd' INTERVAL '1' DAY
DAY HOUR 'd h' INTERVAL - '2 12' DAY TO HOUR
DAY MINUTE 'd h:m' INTERVAL + '2 5:30' DAY TO MINUTE
DAY SECOND 'd h:m:s' INTERVAL '0 12:34:56.789' DAY TO SECOND
HOUR 'h' INTERVAL '50' HOUR
HOUR MINUTE 'h:m' INTERVAL '5:30' HOUR TO MINUTE
HOUR SECOND 'h:m:s' INTERVAL '12:34:56.789' HOUR TO SECOND
MINUTE 'm' INTERVAL '75' MINUTE
MINUTE SECOND 'm:s' INTERVAL '34:56.789' MINUTE TO SECOND
SECOND 's' INTERVAL '300' SECOND

Further Information

Value Expressions (SQL)

To learn more about SQL scalar value expressions.

Fernhill SCADA Structured Query Language (SQL)

To learn more about the SQL features in Fernhill SCADA.

Glossary

For definitions of the terms used in Fernhill SCADA.