Datasheet

Writing Simple Queries
23
1.5f
34.567D
4d
4.0E+0
Datetime Literals
You can specify a date value as a string literal using the datetime literals. The most common
methods to represent the datetime values are to use the conversion function
TO_DATE or
TO_TIMESTAMP with the appropriate format mask. For completeness of literals, I will discuss
the datetime literals briefly.
The
DATE literal uses the keyword DATE followed by the date value in single quotes, and
the value must be specified in
YYYY-MM-DD format with no time component. The time com-
ponent will be defaulted to midnight (00:00:00). The following are examples of the
DATE
literal:
DATE ‘2008-03-24’
DATE ‘1999-12-31’
Similar to the TIMESTAMP datatype, the TIMESTAMP literal can be used to specify
the year, month, date, hour, minute, second, and fractional second. You can also include time-
zone data along with the TIMESTAMP literal. The time zone information can be specified
using the UTC offset or using the time zone region name. The literal must be in the format
YYYY-MM-DD HH24:MI:SS TZ. Here are some examples of the TIMESTAMP literal:
TIMESTAMP ‘2008-03-24 03:25:34.123’
TIMESTAMP ‘2008-03-24 03:25:34.123 -7:00’
TIMESTAMP ‘2008-03-24 03:25:34.123 US/Central’
TIMESTAMP ‘2008-03-24 03:25:34.123 US/Central CDT’
Interval Literals
Interval literals specify a period of time in terms of years and months or in terms of days
and seconds. These literals correspond to the Oracle datatypes INTERVAL YEAR TO
MONTH and INTERVAL DAY TO SECOND. I’ll discuss these datatypes in more detail
in Chapter 6.
Writing Simple Queries
A query is a request for information from the database tables. Queries do not modify data;
they read data from database tables and views. Simple queries are those that retrieve data
from a single table or view. A table is used to store data and is stored in rows and columns.
The basis of a query is the
SELECT statement. The SELECT statement can be used to get data
95127c01.indd 23 2/18/09 6:37:09 AM