SQLite learning Manual (expression)

Source: Internet
Author: User

I. common expressions:

Like most relational databases, SQLite can well support expressions provided in the SQL standard, and its functions are consistent with the SQL standard, such:
|
*/%
+-
<> & |
<=> =
===! = <> Is not in like
And
Or
~ Not
In the above expression, the only thing to note is "|". This expression is mainly used for the connection between two strings. Its return value is the connected string, even if the operands on both sides of the operator are non-string type, they must be converted to the string type before the expression is executed, and then connected.

Ii. conditional expressions:

the syntax of this expression is as follows:
1 ). case x when W1 then R1 when W2 then R2 else R3 end
2 ). case when X = W1 then R1 when X = W2 then R2 else R3 end
In the first case, condition expression X only needs to be calculated once, and then compare it with the condition after the when keyword one by one until equal conditions are found, the comparison rule is equivalent to an equal sign (=) expression. If a matching condition is found, the value pointed to by the subsequent then keyword is returned. If no matching is found, the value after the else keyword is returned. If no else branch exists, null is returned. In the second case, the only difference from the first case is that expression X may be executed multiple times. For example, if the first when condition does not match, the following when condition is calculated, other rules are identical to the first rule. It should be noted that the above two forms of case expressions follow the short circuit principle, that is, once the conditions of the first expression match, all the subsequent when expressions will not be executed or compared.

Iii. Conversion expression:

The syntax of this expression is as follows:
Cast(ExprAsTarget_type)
This expression converts the expr parameter to the target_type type. For specific conversion rules, see the following list:

Target type Conversion Rule Description
Text If you want to convert an integer or real value to the text type, you can directly convert it, just like the work completed by the C/C ++ interface function sqlite3_snprintf.
Real If the value of the text type is converted to the real type, the text that can be converted to the real number is converted to the corresponding real number at the beginning of the text, and the rest is ignored. The leading zeros of the text value are also ignored. If the text value does not contain any character, it can be converted to a real number. The cast expression is converted to 0.0.
Integer If you convert the text value to the integer type, the text that can be converted to an integer is converted to the corresponding integer at the beginning of the text, and the rest is ignored. The leading zeros of the text value are also ignored. If the text value does not contain any characters, it can be converted to an integer. The cast expression is converted to 0.
If a real value is converted to the integer type, the fractional part of the real number is truncated. If the real number is too large, the maximum negative integer-9223372036854775808 is returned.
Numeric If the text value is converted to the numeric type, the value is first forcibly converted to the real type. Only when the real type is converted to an integer will not cause data loss or completely reversible data, SQLite will be further converted to the integer type.

Note that if expr is null, the conversion result is also null.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.