1 ITN270 Advanced Internet Databases Lecture 02. Operators and Function Reference Topics: – Explain & Demonstrate How You Can Use MySQL Operators – Overview.

Slides:



Advertisements
Similar presentations
CpSc 3220 The Language of SQL Chapters 7-9. The WHERE Clause Determines which rows of table are to be selected.
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
1 Pertemuan 04 Expression Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
More about Numerical Computation CS-2301, B-Term More about Numerical Computation CS-2301, System Programming for Non-Majors (Slides include materials.
JavaScript, Third Edition
Compunet Corporation1 Programming with Visual Basic.NET Arithmetic, Logical & Bitwise Operators Week # 3 Tariq Ibn Aziz.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations System-oriented Programming, B. Hirsbrunner,
Performing Simple Calculations with C# Svetlin Nakov Telerik Corporation
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
IFS Intro. to Data Management Chapter 6 Filtering your data.
Spreadsheets Objective 6.02
2 Explain advanced spreadsheet concepts and functions Advanced Calculations 1 Sabbir Saleh_Lecture_17_Computer Application_BBA.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
Basic Operators. What is an operator? using expression is equal to 9. Here, 4 and 5 are called operands and + is the operator Python language supports.
C++ Basics Tutorial 6 Operators. What are going to see today? Assignment operator(=) Arithmetic operators(+,-,*,/,%) Compound assignment(+=,-=,*=……..)
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
15-Nov-15 All the Operators. operators.ppt 2 Precedence An operator with higher precedence is done earlier (precedes) one with lower precedence A higher.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
1 Operators and Expressions. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples.
Performing Simple Calculations with C# Telerik Corporation
Operators & Expressions
Doing math In java.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
Operators and Expressions
Programming Principles Operators and Expressions.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU Status 6/10/2016 Initial content copied verbatim from ECE 103 material developed.
CSE 220 – C Programming Expressions.
Operators and Expressions
Chap. 2. Types, Operators, and Expressions
University of Central Florida COP 3330 Object Oriented Programming
University of Central Florida COP 3330 Object Oriented Programming
Topics The if Statement The if-else Statement Comparing Strings
Topics The if Statement The if-else Statement Comparing Strings
All the Operators 22-Nov-18.
More about Numerical Computation
Lecture 2 Python Programming & Data Types
All the Operators 4-Dec-18.
Lecture 2 Python Programming & Data Types
Spreadsheets 2 Explain advanced spreadsheet concepts and functions
Expressions.
All the Operators 6-Apr-19.
All the Operators 13-Apr-19.
Spreadsheets Objective 6.02
Spreadsheets Objective 6.02
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Presentation transcript:

1 ITN270 Advanced Internet Databases Lecture 02. Operators and Function Reference Topics: – Explain & Demonstrate How You Can Use MySQL Operators – Overview of MySQL’s Build-in Functions

2 Operators Operators are used to combineterms in expressions to perform arithmetic, compare values, perform bitwise or logical operations and match patterns MySQL comes with more than 25 operators. These operators can be classified, according to their function, into the following four categories: –Arithmetic operators –Comparison operators –Logical operators –Bit operators

3 Operator Precedence Operators have varying levels of precedence. The levels are shown in the fol- lowing list, from highest to lowest. Operators on the same line have the same precedence. Operators at a given precedence level are evaluated left to right. Operators at a higher precedence level are evaluated before operators at a lower precedence level. BINARY COLLATE NOT ! ^ XOR - (unary minus) ) ~ unary bit negation) * / % + - > & | != <> >= > IN IS LIKE REGEXP RLIKE BETWEEN CASE WHEN THEN ELSE AND && OR || :=

4 Grouping Operators Parentheses can be used to group parts of an expression. They override the default operator precedence that determines the order in which terms of an expression are evaluated Parentheses can also be used simply for visual clarity to make an expression more readable. Examples: –1+2*3/42.50 –(((1+2) * 3) / 4)2.25

5 Arithmetic Operators + –Addition –Note: + does not serve as the string concatenation operator - –Subtraction * –Multiplication / –Division (?/0 -> NULL) % –Modulo operator (? % 0 -> NULL)

6 Comparison Operators Comparison operators return –1 if true –0 if False –Null if could not be determinated

7 Comparison Operators Examples: 1. = 1=1-> TRUE(1); 1=2-> FALSE(0) 2. Similar to = except NULL NULL -> TRUE(1) 3. != or <>1 <> 1->FALSE(0) 4. TRUE(1) 5. TRUE(1) 6. >=2>1-> TRUE(1) 7. >2>1-> TRUE(1) 8. exp BETWEEN min AND max ‘def’ BETWEEN ‘abc’ AND ‘ghi’-> TRUE(1) 9. exp NOT BETWEEN min AND max ‘def’ NOT BETWEEN ‘abc’ AND ‘ghi’-> FALSE(0)

8 Comparison Operators Examples: 10. CASE expr WHEN expr1 THEN result1 … [ELSE default] END 11. CASE WHEN expr1 THEN result1 … [ELSE default] END CASE 0 WHEN 1 THEN ‘T’ WHEN 0 THEN ‘F’ END --> ‘F’ CASE ‘F’ WHEN T THEN 1 WHEN ‘F’ THEN 0 END --> expr IN (value1, value2,…) 3 IN (1, 2, 3, 4, 5) -> TRUE(1) 13. expr NOT IN (value1, value2,…) 3 NOT IN (1, 2, 3, 4, 5) -> FALSE(0) 14. exp IS NULL:NULL IS NULL --> TRUE(1) 15. exp IS NOT NULL: 0 IS NULL --> FALSE(0)

9 Bit Operators &, |, ^, >, ~ Examples: 1. & - Bitwise AND of the operands 1 & 1-> 1 1 & 2 -> 0 7 & 5 -> 5 2. | - Bitwise OR of the operand 1 | 1-> 1 1 | 2-> 3 3. ^ - Bitwise XOR of the operand 1 ^ 1-> 0 1 ^ 0-> 1 4. << - shifts the leftmost operand left the number of bit position indicated by the right operand: 1 4

10 Bit Operators &, |, ^, >, ~ Examples: 5. >> - shifts the leftmost operand right the number of bit position indicated by the right operand: 16 >> 3--> 2 6. ~ - perform bitwise negation of the following expression: ~0 -> -1 ~(-1) -> 0

11 Logical Operators NOT or ! –NOT 1-> 0 –NOT 0-> 1 –NOT NULL-> NULL AND or && –0 AND 0-> 0 –1 AND 1-> 1 OR or || –0 OR 0->0 –0 OR 1-> 1 –0 or NLL-> NULL –NULL or NULL-> NULL XOR –0 XOR 0-> 0 –0 XOR 1-> 1 –1 XOR 1-> 0

12 Cast Operators Cast operators convert values from one type to another –_charset str _utf8 ‘abc’ –BINARY str Binary causes the following operand to be treated as a binary string so that comparisons are case- sensitive. If the following operand is a number, it is converted to string form. –Str COLLATE charset The COLLATE operator causes the given string str to be compared using the collating order for the character set charset

13 Pattern-Matching Operators str LIKE pat [ESCAPE ‘c’] str NOT LIKE pat [ESCAPE ‘c’] –wildcards ‘%’ - matches any sequence of characters ‘_’ - match any single character ‘ ‘ LIKE ‘%’-> 1 ‘cat’ LIKE ‘cat%’-> 1 –ESCAPE clause: to turn off special meaning of the wildcard characters

14 Pattern-Matching Operators str REGEXP pat –REGEXP performs a regular expression pattern match ‘cats and gogs’ REGEXP ‘dogs’-> 1 str NOT REGEXP pat

15 MySQL Functions These built-in functions can broadly be classified into the following groups : 1. Comparison functions 2. Cast Functions 3. Numerica functions 4. String functions 5. Date and Time functions 6. Summary Functions 7. Security related functions etc.

16 MySQL Functions - Comparison Functions GRATEST(expr1, expr2, …) LEAST(expr1, expr2,…) IF(exp1, exp2, exp3) –if exp1 is true, returns expr2, otherwise return expr3 IFNULL(expr1, expr2) –returns expr2 if expr1 is NULL, otherwise it returns expr1. INTERVAL(n,n1,n2,…) –returns 0 if n<n1, 1 if n<n2, and so on. Or -1 if n is NULL. ISNULL(expr) –RETURN 1 if expr is NULL, otherwise it returns 0 NULLIF(expr1,expr2) –returns expr1 if the two expression values differ, otherwise, returns NULL STRCMP(str1, str2): returns 1, 0, or -1

17 MySQL Functions - Cast Functions CAST (exp AS Type) –CASE(304 AS BINARY)--> ‘304’ CONVERT(expr, type) CONVERT(expr USING charset)

18 MySQL Functions - Numeric Functions

19 MySQL Functions - String Functions There are many string functions, the following table only instroduce some of them:

20 MySQL Functions - String Functions

21 MySQL Functions - Date & Time Functions Given the large number of date and time data type in MySQL, it is obvious that there are large number of functions to manipulate date and time values. The following table lists some of the more important time and date functions.

22 MySQL Functions - Date & Time Functions

23 MySQL Functions - Summary Functions Summary function are also known as aggregate functions. They calculate a single value based on a group of values. The following table lists some of the important aggregate functions.

24 MySQL Functions - Security-Related Functions These functions perform various security-related operations, such as encripting or decrypting strings. The following table lists some of the important security-related functions

25 MySQL Functions - Micellaneous Functions/System Information Functions MySQL also provides specialized functions that can be used to obtain information about the system itself. The following table lists some of the functions: