SlideShare uma empresa Scribd logo
1 de 14
Baixar para ler offline
Home Contents




SQLite expressions

In this part of the SQLite tutorial, we will cover SQLite expressions.


An expression in a programming language is a combination of values, variables, operators, and

functions that are interpreted (evaluated) according to the particular rules of precedence and of

association for a particular programming language, which computes and then produces (returns, in a

stateful environment) another value. The expression is said to evaluate to that value. (wikipedia)




Literal values

A literal value is a constant of some kind. Literal values may be integers, floating point numbers,

strings, BLOBs, or NULLs.




  sqlite> SELECT 3, 'Wolf', 34.5;




  3|Wolf|34.5


Here we return three literals. Namely integer, string and floating point constants.




  sqlite> .nullvalue NULL




  sqlite> SELECT NULL;




  NULL


The .nullvalue command tells the SQLite to show NULL values as NULL. SQLite shows empty strings

for NULL values by default. NULL value is a literal too.




  sqlite> SELECT x'345eda2348587aeb';
4^�#HXz


BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X"

character.




Operators

Operators are used to build expressions. SQL operators are very similar to mathematical operators.

There are two kinds of operators. Binary and unary. Binary operators work with two operands, unary

work with one. An operator may have one or two operands. An operand is one of the inputs

(arguments) of an operator.


We have several types of operators:


      •   Arithmetic operators

      •   Boolean operators

      •   Relational operators

      •   Bitwise operators

      •   Other operators


SQLite understand the following binary operators.




  ||




  *        /     %




  +        -




  <<       <>    &     |




  <        <=    >     >=




  =        ==    !=    <>     IS   IN   LIKE   GLOB   BETWEEN
AND




  OR


Operators are arranged according to the precedence. The || operator has the highest order of

precedence, the OR operator the lowest.


These are the unary prefix operators:




  -       +   ~      NOT


The + is a no-op. It does not do anything. The - unary operator changes positive values to negative and

vice versa.




  sqlite> SELECT -(3-44);




  41


The result is 41. The other two operators will be discussed later on.




Arithmetic operators

Arithmetic operators understood by SQLite are: multiplication, division, addition, subtraction and

modulo.




  sqlite> SELECT 3*3/9;




  1


These are multiplication and division operators, that we know from mathematics.




  sqlite> SELECT 3 + 4 - 1 + 5;




  11
Addition and subtraction operators.




  sqlite> SELECT 11 % 3;




  2


The % operator is called the modulo operator. It finds the remainder of division of one number by

another. 11 % 3, 11 modulo 3 is 2, because 3 goes into 11 three times with a remainder of 2.




Boolean operators

With boolean operators we perform logical operations. SQLite has the following boolean operators:

AND, OR and NOT. Boolean operators return true or false. In SQLite, 1 is true, 0 is false.


The AND operator evaluates to true, if both operands are true.




  sqlite> SELECT 0 AND 0, 0 AND 1, 1 AND 0, 1 AND 1;




  0|0|0|1


The first three operations evaluate to false, the last one to true.




  sqlite> SELECT 3=3 AND 4=4;




  1


Both operands are true, so the result is true (1).


The OR operator evaluates to true, if at least one of the operands is true.




  sqlite> SELECT 0 OR 0, 0 OR 1, 1 OR 0, 1 OR 1;




  0|1|1|1
The first operation evaluates to false, other operations evaluate to true.


The NOT operator is negation operator. It makes true false and false true.




    sqlite> SELECT NOT 1, NOT 0;




    0|1




    sqlite> SELECT NOT (3=3);




    0




Relational operators

Relational operators are used to compare values. These operators always result in boolean value.


Symbol            Meaning


<          strictly less than

<=         less than or equal to

>          greater than

>=         greater than or equal to

= or ==    equal to

!= or <>   not equal to



    sqlite> SELECT 3*3 == 9, 9 = 9;




    1|1


Both = and == are equality operators.




    sqlite> SELECT 3 < 4, 3 <> 5, 4 >= 4, 5 != 5;
1|1|1|0


Usage of the relational operators is known from mathematics.




Bitwise operators

Decimal numbers are natural to humans. Binary numbers are native to comptuters. Binary, octal,

decimal or hexadecimal symbols are only notations of the same number. Bitwise operators work with

bits of a binary number. We have binary logical operators and shift operators.


The bitwise and operator performs bit-by-bit comparison between two nubmers. The result for a bit

position is 1 only if both corresponding bits in the operands are 1.




      00110

  & 00011

  = 00010


The first number is a binary notation of 6. The second is 3. The result is 2.




  sqlite> SELECT 6 & 3;




  2




  sqlite> SELECT 3 & 6;




  2


The bitwise or operator performs bit-by-bit comparison between two nubmers. The result for a bit

position is 1 if either of the corresponding bits in the operands is 1.




      00110

  |   00011
= 00111


The result is 00110 or decimal 7.




  sqlite> SELECT 6 | 3;




  7


The bitwise shift operators shift bits to the right or left.



number << n : multiply number 2 to the nth power

number >> n : divide number by 2 to the nth power


These operators are also called arithmetic shift.



       00110

  >>    00001

      = 00011


We shift each of the bits of number six to the right. It is equal to dividing the six by 2. The result is

00011 or decimal 3.




  sqlite> SELECT 6 >> 1;




  3



       00110

  << 00001

      = 01100


We shift each of the bits of number six to the left. It is equal to muliplying the number six by 2. The

result is 01100 or decimal 12.




  sqlite> SELECT 6 << 1;
12


The bitwise negation operator changes each 1 to 0 and 0 to 1.




  >>> ~7




  -8




  >>> ~-8




  7


The operator reverts all bits of a number 7. One of the bits also determines, whether the number is

negative or not. If we negate all the bits one more time, we get number 7 again.




Other operators

There are some other operators left. These include ||, IN, LIKE, GLOB, BETWEEN.




  sqlite> SELECT 'wolf' || 'hound';




  wolfhound


The || operator is a string concatenation operator. It simply joins strings.


We can use the IN operator in two cases.




  sqlite> SELECT 'Tom' IN ('Tom', 'Frank', 'Jane');




  1


Here we check, if the string value 'Tom' is in the list of names, following the IN operator. The return

value is a boolean value.
For the following example, let's recap, what we have in the Cars table.




  sqlite> SELECT * FROM Cars;




  Id             Name           Cost




  ----------     ----------     ----------




  1              Audi           52642




  2              Mercedes       57127




  3              Skoda          9000




  4              Volvo          29000




  5              Bentley        350000




  6              Citroen        21000




  7              Hummer         41400




  8              Volkswagen     21600


In the second case, the IN operator allows you to specify multiple values in a WHERE clause.




  sqlite> SELECT * FROM Cars WHERE Name IN ('Audi', 'Hummer');




  Id             Name           Cost
----------     ----------     ----------




  1              Audi           52642




  7              Hummer         41400


From the Cars table, we choose cars, that are listed after the IN operator.


The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.




  sqlite>    SELECT * FROM Cars WHERE Name LIKE 'Vol%';




  Id             Name           Cost




  ----------     ----------     ----------




  4              Volvo          29000




  8              Volkswagen     21600


Here we select cars, whose names begin with 'Vol'.




  sqlite> SELECT * FROM Cars WHERE Name LIKE '____';




  Id             Name           Cost




  ----------     ----------     ----------




  1              Audi           52642


Here we select a car name, that has exactly four characters. There are four underscores.


The GLOB operator is similar to the LIKE, but uses the Unix file globbing syntax for its wildcards. Also,
GLOB is case sensitive, unlike LIKE.




  sqlite> SELECT * FROM Cars WHERE Name GLOB '*en';




  Id            Name           Cost




  ----------    ----------     ----------




  6             Citroen        21000




  8             Volkswagen     21600


Here we have cars, whose names end with 'en' characters.




  sqlite> SELECT * FROM Cars WHERE Name GLOB '????';




  Id            Name           Cost




  ----------    ----------     ----------




  1             Audi           52642


Here we again select a car name, that has exactly four characters.




  sqlite> SELECT * FROM Cars WHERE Name GLOB '*EN';




  sqlite> SELECT * FROM Cars WHERE Name LIKE '%EN';




  Id            Name           Cost




  ----------    ----------     ----------
6             Citroen        21000




  8             Volkswagen     21600


These two statements demonstrate, that the LIKE operator is case insensitive, GLOB is case sensitive.


The BETWEEN operator is equivalent to a pair of comparisons. a BETWEEN b AND c is equivalent to

a>=b AND a<=c




  sqlite> SELECT * FROM Cars WHERE Cost BETWEEN 20000 AND 55000;




  Id            Name           Cost




  ----------    ----------     ----------




  1             Audi           52642




  4             Volvo          29000




  6             Citroen        21000




  7             Hummer         41400




  8             Volkswagen     21600


In this SQL statement, we have selected cars, which cost between 20000 and 55000 units.




Precedence

The operator precedence tells us which operators are evaluated first. The precedence level is

necessary to avoid ambiguity in expressions.


What is the outcome of the following expression? 28 or 40?
3 + 5 * 5


Like in mathematics, the multiplication operator has a higher precedence than addition operator. So

the outcome is 28.



(3 + 5) * 5


To change the order of evaluation, we can use square brackets. Expressions inside square brackets are

always evaluated first.




  sqlite> SELECT 3+5*5, (3+5)*5;




  28|40


The first expression evaluates to 28, because the multiplication operator has a higher precedence, than

the addition one. In the second example, we have used square brackets to change the order of

precedence. So the second expressions evaluates to 40.


Here we put again the list of operators in SQLite.




  unary + - ~ NOT




  ||




  *       /    %




  +       -




  <<      <>   &     |




  <       <=   >     >=




  =       ==   !=    <>    IS   IN   LIKE    GLOB    BETWEEN
AND




  OR


The operators on the same row have the same level of precedence. The precedence grows from bottom

to top.




Associativity

Sometimes the precedence is not satisfactory to determine the outcome of an expression. There is

another rule called associativity. The associativity of operators determines the order of evaluation of

operators with the same precedence level.



9 / 3 * 3


What is the outcome of this expression? 9 or 1? The multiplication, deletion and the modulo operator

are left to right associated. So the expression is evaluated this way: (9 / 3) * 3 and the result is 9.




  sqlite> SELECT 9 / 3 * 3;




  9


The associativity rule is left to right.




  sqlite> SELECT 0 AND 0 OR 1;




  1


The associativity rule is again left to right. If it was right to left, the result would be 0.


Arithmetic, boolean, relational and bitwise operators are all left to right associated.


In this part of the SQLite tutorial, we have covered the SQLite expressions.

Mais conteúdo relacionado

Mais procurados

Python Basic Operators
Python Basic OperatorsPython Basic Operators
Python Basic OperatorsSoba Arjun
 
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...Arti Parab Academics
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comclaric130
 
Operators in Python
Operators in PythonOperators in Python
Operators in PythonAnusuya123
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions NotesProf Ansari
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaSierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaPhilip Schwarz
 
Conversion of Boolean Function - R.D.Sivakumar
Conversion of Boolean Function - R.D.SivakumarConversion of Boolean Function - R.D.Sivakumar
Conversion of Boolean Function - R.D.SivakumarSivakumar R D .
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaPhilip Schwarz
 
Programming presentation
Programming presentationProgramming presentation
Programming presentationFiaz Khokhar
 
Cis 115 Effective Communication / snaptutorial.com
Cis 115  Effective Communication / snaptutorial.comCis 115  Effective Communication / snaptutorial.com
Cis 115 Effective Communication / snaptutorial.comBaileyao
 
Chapter 3 : Programming with Java Operators and Strings
Chapter 3 : Programming with Java Operators and  StringsChapter 3 : Programming with Java Operators and  Strings
Chapter 3 : Programming with Java Operators and StringsIt Academy
 
Applicative Functor - Part 3
Applicative Functor - Part 3Applicative Functor - Part 3
Applicative Functor - Part 3Philip Schwarz
 
Cis 115 Education Organization -- snaptutorial.com
Cis 115   Education Organization -- snaptutorial.comCis 115   Education Organization -- snaptutorial.com
Cis 115 Education Organization -- snaptutorial.comDavisMurphyB99
 

Mais procurados (15)

Python Basic Operators
Python Basic OperatorsPython Basic Operators
Python Basic Operators
 
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
FYBSC IT Digital Electronics Unit II Chapter II Minterm, Maxterm and Karnaugh...
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
CIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.comCIS 115 Become Exceptional--cis115.com
CIS 115 Become Exceptional--cis115.com
 
Operators in Python
Operators in PythonOperators in Python
Operators in Python
 
C++ Expressions Notes
C++ Expressions NotesC++ Expressions Notes
C++ Expressions Notes
 
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and ScalaSierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
Sierpinski Triangle - Polyglot FP for Fun and Profit - Haskell and Scala
 
Conversion of Boolean Function - R.D.Sivakumar
Conversion of Boolean Function - R.D.SivakumarConversion of Boolean Function - R.D.Sivakumar
Conversion of Boolean Function - R.D.Sivakumar
 
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and ScalaFunctional Core and Imperative Shell - Game of Life Example - Haskell and Scala
Functional Core and Imperative Shell - Game of Life Example - Haskell and Scala
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
Cis 115 Effective Communication / snaptutorial.com
Cis 115  Effective Communication / snaptutorial.comCis 115  Effective Communication / snaptutorial.com
Cis 115 Effective Communication / snaptutorial.com
 
Computer programming 2 Lesson 7
Computer programming 2  Lesson 7Computer programming 2  Lesson 7
Computer programming 2 Lesson 7
 
Chapter 3 : Programming with Java Operators and Strings
Chapter 3 : Programming with Java Operators and  StringsChapter 3 : Programming with Java Operators and  Strings
Chapter 3 : Programming with Java Operators and Strings
 
Applicative Functor - Part 3
Applicative Functor - Part 3Applicative Functor - Part 3
Applicative Functor - Part 3
 
Cis 115 Education Organization -- snaptutorial.com
Cis 115   Education Organization -- snaptutorial.comCis 115   Education Organization -- snaptutorial.com
Cis 115 Education Organization -- snaptutorial.com
 

Destaque

Sq lite functions
Sq lite functionsSq lite functions
Sq lite functionspunu_82
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line toolpunu_82
 
Creating, altering and dropping tables
Creating, altering and dropping tablesCreating, altering and dropping tables
Creating, altering and dropping tablespunu_82
 
Java one 2010
Java one 2010Java one 2010
Java one 2010scdn
 
第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5scdn
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq litepunu_82
 
SCDN 1
SCDN 1SCDN 1
SCDN 1scdn
 

Destaque (9)

Sq lite functions
Sq lite functionsSq lite functions
Sq lite functions
 
The sqlite3 commnad line tool
The sqlite3 commnad line toolThe sqlite3 commnad line tool
The sqlite3 commnad line tool
 
Creating, altering and dropping tables
Creating, altering and dropping tablesCreating, altering and dropping tables
Creating, altering and dropping tables
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 
мясной дом Бородина.
мясной дом Бородина.мясной дом Бородина.
мясной дом Бородина.
 
第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5第5回SCDN - Things that become possible with HTML5
第5回SCDN - Things that become possible with HTML5
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq lite
 
SCDN 1
SCDN 1SCDN 1
SCDN 1
 
Werkkapitaal en logistiek
Werkkapitaal en logistiekWerkkapitaal en logistiek
Werkkapitaal en logistiek
 

Semelhante a Sq lite expressions

Operators in C++.pptx
Operators in C++.pptxOperators in C++.pptx
Operators in C++.pptxssuser41748c
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressionsStoian Kirov
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statementsIntro C# Book
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01Abdul Samee
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql featuresConnor McDonald
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++sunny khan
 
The select statement
The select statementThe select statement
The select statementpunu_82
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Himanshu Kaushik
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statementsCtOlaf
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++Praveen M Jigajinni
 
Chapter 3:Programming with Java Operators and Strings
Chapter 3:Programming with Java Operators and  StringsChapter 3:Programming with Java Operators and  Strings
Chapter 3:Programming with Java Operators and StringsIt Academy
 
Data Warehouse , Data Cube Computation
Data Warehouse   , Data Cube ComputationData Warehouse   , Data Cube Computation
Data Warehouse , Data Cube Computationsit20ad004
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview QuestionsBest SEO Tampa
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questionsnagesh Rao
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
 

Semelhante a Sq lite expressions (20)

C++ chapter 2
C++ chapter 2C++ chapter 2
C++ chapter 2
 
Operators in C++.pptx
Operators in C++.pptxOperators in C++.pptx
Operators in C++.pptx
 
03. operators and-expressions
03. operators and-expressions03. operators and-expressions
03. operators and-expressions
 
03. Operators Expressions and statements
03. Operators Expressions and statements03. Operators Expressions and statements
03. Operators Expressions and statements
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
3 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp013 operators-expressions-and-statements-120712073351-phpapp01
3 operators-expressions-and-statements-120712073351-phpapp01
 
Assignment#06
Assignment#06Assignment#06
Assignment#06
 
Latin America Tour 2019 - 10 great sql features
Latin America Tour 2019  - 10 great sql featuresLatin America Tour 2019  - 10 great sql features
Latin America Tour 2019 - 10 great sql features
 
Few Operator used in c++
Few Operator used in c++Few Operator used in c++
Few Operator used in c++
 
The select statement
The select statementThe select statement
The select statement
 
Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++Lecture 2 C++ | Variable Scope, Operators in c++
Lecture 2 C++ | Variable Scope, Operators in c++
 
Operators expressions-and-statements
Operators expressions-and-statementsOperators expressions-and-statements
Operators expressions-and-statements
 
Operators and Expressions in C++
Operators and Expressions in C++Operators and Expressions in C++
Operators and Expressions in C++
 
Cluto presentation
Cluto presentationCluto presentation
Cluto presentation
 
Chapter 3:Programming with Java Operators and Strings
Chapter 3:Programming with Java Operators and  StringsChapter 3:Programming with Java Operators and  Strings
Chapter 3:Programming with Java Operators and Strings
 
Data Warehouse , Data Cube Computation
Data Warehouse   , Data Cube ComputationData Warehouse   , Data Cube Computation
Data Warehouse , Data Cube Computation
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Sql interview questions
Sql interview questionsSql interview questions
Sql interview questions
 
chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)chap 2 : Operators and Assignments (scjp/ocjp)
chap 2 : Operators and Assignments (scjp/ocjp)
 

Último

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 

Último (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Sq lite expressions

  • 1. Home Contents SQLite expressions In this part of the SQLite tutorial, we will cover SQLite expressions. An expression in a programming language is a combination of values, variables, operators, and functions that are interpreted (evaluated) according to the particular rules of precedence and of association for a particular programming language, which computes and then produces (returns, in a stateful environment) another value. The expression is said to evaluate to that value. (wikipedia) Literal values A literal value is a constant of some kind. Literal values may be integers, floating point numbers, strings, BLOBs, or NULLs. sqlite> SELECT 3, 'Wolf', 34.5; 3|Wolf|34.5 Here we return three literals. Namely integer, string and floating point constants. sqlite> .nullvalue NULL sqlite> SELECT NULL; NULL The .nullvalue command tells the SQLite to show NULL values as NULL. SQLite shows empty strings for NULL values by default. NULL value is a literal too. sqlite> SELECT x'345eda2348587aeb';
  • 2. 4^�#HXz BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. Operators Operators are used to build expressions. SQL operators are very similar to mathematical operators. There are two kinds of operators. Binary and unary. Binary operators work with two operands, unary work with one. An operator may have one or two operands. An operand is one of the inputs (arguments) of an operator. We have several types of operators: • Arithmetic operators • Boolean operators • Relational operators • Bitwise operators • Other operators SQLite understand the following binary operators. || * / % + - << <> & | < <= > >= = == != <> IS IN LIKE GLOB BETWEEN
  • 3. AND OR Operators are arranged according to the precedence. The || operator has the highest order of precedence, the OR operator the lowest. These are the unary prefix operators: - + ~ NOT The + is a no-op. It does not do anything. The - unary operator changes positive values to negative and vice versa. sqlite> SELECT -(3-44); 41 The result is 41. The other two operators will be discussed later on. Arithmetic operators Arithmetic operators understood by SQLite are: multiplication, division, addition, subtraction and modulo. sqlite> SELECT 3*3/9; 1 These are multiplication and division operators, that we know from mathematics. sqlite> SELECT 3 + 4 - 1 + 5; 11
  • 4. Addition and subtraction operators. sqlite> SELECT 11 % 3; 2 The % operator is called the modulo operator. It finds the remainder of division of one number by another. 11 % 3, 11 modulo 3 is 2, because 3 goes into 11 three times with a remainder of 2. Boolean operators With boolean operators we perform logical operations. SQLite has the following boolean operators: AND, OR and NOT. Boolean operators return true or false. In SQLite, 1 is true, 0 is false. The AND operator evaluates to true, if both operands are true. sqlite> SELECT 0 AND 0, 0 AND 1, 1 AND 0, 1 AND 1; 0|0|0|1 The first three operations evaluate to false, the last one to true. sqlite> SELECT 3=3 AND 4=4; 1 Both operands are true, so the result is true (1). The OR operator evaluates to true, if at least one of the operands is true. sqlite> SELECT 0 OR 0, 0 OR 1, 1 OR 0, 1 OR 1; 0|1|1|1
  • 5. The first operation evaluates to false, other operations evaluate to true. The NOT operator is negation operator. It makes true false and false true. sqlite> SELECT NOT 1, NOT 0; 0|1 sqlite> SELECT NOT (3=3); 0 Relational operators Relational operators are used to compare values. These operators always result in boolean value. Symbol Meaning < strictly less than <= less than or equal to > greater than >= greater than or equal to = or == equal to != or <> not equal to sqlite> SELECT 3*3 == 9, 9 = 9; 1|1 Both = and == are equality operators. sqlite> SELECT 3 < 4, 3 <> 5, 4 >= 4, 5 != 5;
  • 6. 1|1|1|0 Usage of the relational operators is known from mathematics. Bitwise operators Decimal numbers are natural to humans. Binary numbers are native to comptuters. Binary, octal, decimal or hexadecimal symbols are only notations of the same number. Bitwise operators work with bits of a binary number. We have binary logical operators and shift operators. The bitwise and operator performs bit-by-bit comparison between two nubmers. The result for a bit position is 1 only if both corresponding bits in the operands are 1. 00110 & 00011 = 00010 The first number is a binary notation of 6. The second is 3. The result is 2. sqlite> SELECT 6 & 3; 2 sqlite> SELECT 3 & 6; 2 The bitwise or operator performs bit-by-bit comparison between two nubmers. The result for a bit position is 1 if either of the corresponding bits in the operands is 1. 00110 | 00011
  • 7. = 00111 The result is 00110 or decimal 7. sqlite> SELECT 6 | 3; 7 The bitwise shift operators shift bits to the right or left. number << n : multiply number 2 to the nth power number >> n : divide number by 2 to the nth power These operators are also called arithmetic shift. 00110 >> 00001 = 00011 We shift each of the bits of number six to the right. It is equal to dividing the six by 2. The result is 00011 or decimal 3. sqlite> SELECT 6 >> 1; 3 00110 << 00001 = 01100 We shift each of the bits of number six to the left. It is equal to muliplying the number six by 2. The result is 01100 or decimal 12. sqlite> SELECT 6 << 1;
  • 8. 12 The bitwise negation operator changes each 1 to 0 and 0 to 1. >>> ~7 -8 >>> ~-8 7 The operator reverts all bits of a number 7. One of the bits also determines, whether the number is negative or not. If we negate all the bits one more time, we get number 7 again. Other operators There are some other operators left. These include ||, IN, LIKE, GLOB, BETWEEN. sqlite> SELECT 'wolf' || 'hound'; wolfhound The || operator is a string concatenation operator. It simply joins strings. We can use the IN operator in two cases. sqlite> SELECT 'Tom' IN ('Tom', 'Frank', 'Jane'); 1 Here we check, if the string value 'Tom' is in the list of names, following the IN operator. The return value is a boolean value.
  • 9. For the following example, let's recap, what we have in the Cars table. sqlite> SELECT * FROM Cars; Id Name Cost ---------- ---------- ---------- 1 Audi 52642 2 Mercedes 57127 3 Skoda 9000 4 Volvo 29000 5 Bentley 350000 6 Citroen 21000 7 Hummer 41400 8 Volkswagen 21600 In the second case, the IN operator allows you to specify multiple values in a WHERE clause. sqlite> SELECT * FROM Cars WHERE Name IN ('Audi', 'Hummer'); Id Name Cost
  • 10. ---------- ---------- ---------- 1 Audi 52642 7 Hummer 41400 From the Cars table, we choose cars, that are listed after the IN operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. sqlite> SELECT * FROM Cars WHERE Name LIKE 'Vol%'; Id Name Cost ---------- ---------- ---------- 4 Volvo 29000 8 Volkswagen 21600 Here we select cars, whose names begin with 'Vol'. sqlite> SELECT * FROM Cars WHERE Name LIKE '____'; Id Name Cost ---------- ---------- ---------- 1 Audi 52642 Here we select a car name, that has exactly four characters. There are four underscores. The GLOB operator is similar to the LIKE, but uses the Unix file globbing syntax for its wildcards. Also,
  • 11. GLOB is case sensitive, unlike LIKE. sqlite> SELECT * FROM Cars WHERE Name GLOB '*en'; Id Name Cost ---------- ---------- ---------- 6 Citroen 21000 8 Volkswagen 21600 Here we have cars, whose names end with 'en' characters. sqlite> SELECT * FROM Cars WHERE Name GLOB '????'; Id Name Cost ---------- ---------- ---------- 1 Audi 52642 Here we again select a car name, that has exactly four characters. sqlite> SELECT * FROM Cars WHERE Name GLOB '*EN'; sqlite> SELECT * FROM Cars WHERE Name LIKE '%EN'; Id Name Cost ---------- ---------- ----------
  • 12. 6 Citroen 21000 8 Volkswagen 21600 These two statements demonstrate, that the LIKE operator is case insensitive, GLOB is case sensitive. The BETWEEN operator is equivalent to a pair of comparisons. a BETWEEN b AND c is equivalent to a>=b AND a<=c sqlite> SELECT * FROM Cars WHERE Cost BETWEEN 20000 AND 55000; Id Name Cost ---------- ---------- ---------- 1 Audi 52642 4 Volvo 29000 6 Citroen 21000 7 Hummer 41400 8 Volkswagen 21600 In this SQL statement, we have selected cars, which cost between 20000 and 55000 units. Precedence The operator precedence tells us which operators are evaluated first. The precedence level is necessary to avoid ambiguity in expressions. What is the outcome of the following expression? 28 or 40?
  • 13. 3 + 5 * 5 Like in mathematics, the multiplication operator has a higher precedence than addition operator. So the outcome is 28. (3 + 5) * 5 To change the order of evaluation, we can use square brackets. Expressions inside square brackets are always evaluated first. sqlite> SELECT 3+5*5, (3+5)*5; 28|40 The first expression evaluates to 28, because the multiplication operator has a higher precedence, than the addition one. In the second example, we have used square brackets to change the order of precedence. So the second expressions evaluates to 40. Here we put again the list of operators in SQLite. unary + - ~ NOT || * / % + - << <> & | < <= > >= = == != <> IS IN LIKE GLOB BETWEEN
  • 14. AND OR The operators on the same row have the same level of precedence. The precedence grows from bottom to top. Associativity Sometimes the precedence is not satisfactory to determine the outcome of an expression. There is another rule called associativity. The associativity of operators determines the order of evaluation of operators with the same precedence level. 9 / 3 * 3 What is the outcome of this expression? 9 or 1? The multiplication, deletion and the modulo operator are left to right associated. So the expression is evaluated this way: (9 / 3) * 3 and the result is 9. sqlite> SELECT 9 / 3 * 3; 9 The associativity rule is left to right. sqlite> SELECT 0 AND 0 OR 1; 1 The associativity rule is again left to right. If it was right to left, the result would be 0. Arithmetic, boolean, relational and bitwise operators are all left to right associated. In this part of the SQLite tutorial, we have covered the SQLite expressions.