Tutorial Addendum on SQL - Data Types and Literals
| |
5. Time Breach Literals are acclimated to assemble time intervals with different
time units.
- A time breach accurate is accounting in the anatomy of "INTERVAL n unit", where
unit can be YEAR, MONTH, DAY, HOUR, MINUTE, or SECOND.
Examples of time breach literals:
INTERVAL 3 YEAR
INTERVAL 1 DAY
INTERVAL 4 MONTH
INTERVAL 1 HOUR
INTERVAL 5 MINUTE
INTERVAL 9 SECOND
6. Absent Literal is acclimated to assemble a absent amount for any data type. The syntax
of absent accurate is the chat "null".
Data Accurate Evaluation
Data accurate appraisal is the action converting a data accurate to a accurate
value of a accurate data type. This data blazon haveto bout the blazon of
the announcement area the accurate is located. Expressions will be advised in the next
chapter. Now let s
look at some of the data accurate appraisal rules for anniversary blazon of data literals.
1. Appearance Cord Literals can be evaluated appearance strings, exact
numbers, almost numbers and data and time values. The appraisal rules are:
- A appearance cord accurate will be evaluated to a appearance cord in
a cord expression. The appraisal is beeline forward.
- A appearance cord accurate will be evaluated to an exact amount or
an almost amount in a numeric expression, if the appearance cord literal
is aswell a accurate numeric accurate after the commendation characters. Otherwise,
it will be evaluated to 0. For example, 123 will be evaluated to 123 in numeric
contexts. But ABC will be evaluated to 0.
- A appearance cord accurate will be evaluated to a date and time value
in a date and time expression, if the appearance cord can be akin to the
date and time pattern: "yyyy-mm-dd hh:mm:ss.nnn".
2. Hex Cord Literals can be evaluated to appearance strings and exact
numbers. The appraisal rules are:
- A hex cord accurate will be evaluated to a appearance cord in
a cord expression. The hex cord accurate will be acclimated as an array
of bifold representation of encoded characters, and decoded aback to
a appearance string. For example, x 41424344 will be evaluated to character
string "ABCD".
- A hex cord accurate will be evaluated to an accumulation in a numeric expression.
The hex cord accurate will be acclimated to bout the bifold representation of
an integer. The accurate will be evaluated to the analogous integer.
For example, x ffffffffffffffff will be evaluated to accumulation -1.
3. Numeric Literals can be evaluated to exact numbers and almost
numbers. The appraisal rules are:
- A numeric accurate will be evaluated to an exact amount or an approximate
number in a numeric expression. The appraisal is beeline forward.
Data Accurate Appraisal Examples
Example 1 - CharStringLiterals.sql:
-- CharStringLiterals.sql
-- Absorb (c) 1999 by Dr. Yang
--
SELECT Accost world! AS LINE_1;
SELECT Loews L Enfant Capital AS LINE_2;
SELECT 123 + 0 AS LINE_3;
SELECT 0.123e-1 + 0 AS LINE_4;
SELECT ABC + 1 AS LINE_5;
Output on MySQL server:
LINE_1
Hello world!
LINE_2
Loews L Enfant Plaza
LINE_3
123
LINE_4
0.0123
LINE_5
1
Notes:
- Line 2 shows that " " is evaluated as " " in a cord expression.
- Line 4 confirms that a appearance cord accurate can be evaluated to an approximate
number in a numeric expression.
- Line 5 confirms that a appearance cord accurate will be evaluated to 0, if the
string is an invalid numeric literal.
|
literal, string, evaluated, character, expression, evaluation, numeric, literals, interval, select, rules, integer, example, approximate, numbers, exact, , character string, literal will, string literal, hex string, numeric expression, evaluation rules, data literal, expression the, numeric literal, date and, rules are, data type, literal evaluation, literals can, time interval, string expression, string literal will, character string literal, hex string literal, data literal evaluation, time interval literals, sql data types, |
Also see ...
Example 2 HexStringLiterals.sql: HexStringLiterals.sql Absorb (c) 1999 by Dr. Yang SELECT x 41424344 AS LINE_1;SELECT x 31323334 AS LINE_2;SELECT x 31323334 + 0 AS LIN
This affiliate describes:What are the types and levels of locks?How table akin locks plan in MySQL?How row akin locks plan in MySQL?br
We all understand that assorted locks in assorted sessions could couldcause deadlocks. Let s see if we can make a deadlock in MySQL amid two sessions: mysql Alert ;DROP TABLE IF EXISTS User;
This affiliate describes:What s in MySQL?How to use the SQL applicant apparatus mysql.How to dump data into files.How to amount data from fil
To assassinate the statements in hello.sql, you can use the "source" commandinside mysql: mysqlinmysql host localhost test......mysql antecedent hello.sqlQuery OK, 0 rows affli
This affiliate describes:Expressions.Arithmetic operations.Predicate operations.Date and time operations.Operation examp
Predicate OperationsPredicate operations are operations that can be evaluated to accord a action of true or false:1. "Comparison" Predicates: Compares
Operation ExamplesExample 1 NumericOps.sql NumericOps.sql Absorb (c) 1999 by Dr. Yang SELECT 1 + 2 AS LINE_1;SELECT 2 / 3 AS LINE_2;
This affiliate describes:What is a stored procedure?How to make a stored procedure.How to canyon data through parameters.
Here is a simple analysis on stored action the MySQL applicant tool: mysql USE test; mysql DELIMITER / ;mysql Make Action Msg() BEGIN Baddest CURRENT_TIME() AS Time;br