|
Data Types and Literals
Part:
1
2
3
4
(Continued from previous part...)
With the double precision standard, the mantissa precision can go up to 52 binary
digits, about 15 decimal digits.
For more details, see section "Binary Representation of 'float' and 'double' Values"
of my other book "Herong's Notes on C#".
5. Data and Time - A date and time value is usually stored in memory as an exact
integer number with 8 bytes representing an instance by measuring the time period
between this instance and a reference time point in millisecond precision,
second fraction precision of 3. How MySQL is store date and time values? We will
try to find out later.
Data Literals
Now we know the types of data, and how they are stored in memory. Next we need know
how data can get in to the computer. One way is to enter it through the program
source code as a data literal.
Data Literal: An program source element that represents a data value.
Data literals can be divided into multiple groups depending the type of the data
it is representing and how it is representing.
1. Character String Literals are used to construct character strings, exact
numbers, approximate numbers and data and time values. The syntax rules
of character string literals are pretty simple:
- A character string literal is a sequence of characters enclosed by quote characters.
- The quote character is the single quote character "'".
- If "'" is part of the sequence, it needs to be doubled it as "''".
Examples of character string literals:
'Hello world!'
'Loews L''Enfant Plaza'
'123'
'0.123e-1'
'1999-01-01'
2. Hex String Literals are used to construct character strings and exact numbers.
The syntax rules for hex string literals are also very simple:
- A hex string literal is a sequence of hex digits enclosed by quote characters and
prefixed with "x".
- The quote character is the single quote character "'".
Examples of hex string literals:
x'41424344'
x'31323334'
x'31323334'
x'01'
x'0001'
x'ff'
x'ffffffff'
x'ffffffffffffffff'
3. Numeric Literals are used to construct exact numbers and approximate numbers.
Syntax rules of numeric literals are:
- A numeric literal can be written in signed integer form, signed real numbers
without exponents, or real numbers with exponents.
Examples of numeric literals:
1
-22
33.3
-44.44
55.555e5
-666.666e-6
4. Date and Time Literals are used to construct date and time values.
The syntax of date and time literals are:
- A date literal is written in the form of "DATE 'yyyy-mm-dd'".
- A time literal is written in the form of "TIMESTAMP 'yyyy-mm-dd hh:mm:ss'".
Examples of data and time literals:
DATE '1999-01-01'
TIMESTAMP '1999-01-01 01:02:03'
(Continued on next part...)
Part:
1
2
3
4
|