Built-in Functions. Usage of Wildcards

Slides:



Advertisements
Similar presentations
Databases Lab 5 Further Select Statements. Functions in SQL There are many types of functions provided. The ones that are used most are: –Date and Time.
Advertisements

Sets, Dictionaries SoftUni Team Technical Trainers Software University
Doctrine The PHP ORM SoftUni Team Technical Trainers Software University
Stacks and Queues Processing Sequences of Elements SoftUni Team Technical Trainers Software University
Generics SoftUni Team Technical Trainers Software University
Strings and Text Processing
Auto Mapping Objects SoftUni Team Database Applications
Static Members and Namespaces
Functional Programming
Databases basics Course Introduction SoftUni Team Databases basics
Sets, Hash table, Dictionaries
Interface Segregation / Dependency Inversion
Introduction to MVC SoftUni Team Introduction to MVC
Deploying Web Application
PHP Fundamentals Course Introduction SoftUni Team Technical Trainers
Reflection SoftUni Team Technical Trainers Java OOP Advanced
C# Database Fundamentals with Microsoft SQL Server
/^Hel{2}o\s*World\n$/
Classes, Properties, Constructors, Objects, Namespaces
Mocking tools for easier unit testing
State Management Cookies, Sessions SoftUni Team State Management
EF Code First (Advanced)
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
C# Databases Advanced with Microsoft SQL Server
Processing Sequences of Elements
EF Relations Object Composition
Entity Framework: Code First
Repeating Code Multiple Times
Open Source Server Side Scripting MySQL Functions
Basic Tree Data Structures
Data Definition and Data Types
Databases advanced Course Introduction SoftUni Team Databases advanced
Arrays, Lists, Stacks, Queues
Install and configure theme
Balancing Binary Search Trees, Rotations
Debugging and Troubleshooting Code
Entity Framework: Relations
Fast String Manipulation
Functional Programming
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
Processing Variable-Length Sequences of Elements
Transactions in Entity Framework
Regular Expressions (RegEx)
Numeral Types and Type Conversion
Databases Advanced Course Introduction SoftUni Team Databases Advanced
Combining Data Structures
Best practices and architecture
How to connect natively?
Arrays and Multidimensional Arrays
Data Definition and Data Types
Multidimensional Arrays, Sets, Dictionaries
Extending functionality using Collections
Exporting and Importing Data
Making big SPA applications
Manual Mapping and AutoMapper Library
Functional Programming
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
Exporting and Importing Data
CSS Transitions and Animations
Train the Trainers Course
Iterators and Comparators
Hibernate (JPA) Code First Entity Relations
Spring Data Advanced Querying
Software Quality Assurance
JavaScript Frameworks & AngularJS
Polymorphism, Interfaces, Abstract Classes
Text Processing and Regex API
/^Hel{2}o\s*World\n$/
CSS Transitions and Animations
Multidimensional Arrays
Presentation transcript:

Built-in Functions. Usage of Wildcards Most important built-in functions. How to take advantage of wildcards? Databases Basics SoftUni Team Technical Trainers Software University http://softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Table of Contents String built in functions SQL Server/MySQL Math built in functions SQL Server/MySQL Date built in functions SQL Server/MySQL Other built in functions SQL Server/MySQL Like + Wildcards © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Questions sli.do #8594

String Functions © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

SQL Server MySQL LEN LEN(ColumnName) LENGTH(column_name) * LEN SQL Server MySQL LEN(ColumnName) LENGTH(column_name) CHAR_LENGTH(column_name) Returns the length of the given string. The difference in MySQL is that LENGTH returns the number of bytes used by the characters in the string. The CHAR_LENGTH returns the exact number of characters. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

CONCAT(param1, param2, …, paramN) * CONCAT SQL Server/MySQL CONCAT(param1, param2, …, paramN) Converts the letters of the parameter to lower/upper case. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

LOWER/UPPER(ColumnName) * LOWER / UPPER SQL Server/MySQL LOWER/UPPER(ColumnName) Converts the letters of the parameter to lower/upper case. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

LEFT/RIGHT (ColumnName, TakeQuantity) * LEFT / RIGHT SQL Server/MySQL LEFT/RIGHT (ColumnName, TakeQuantity) Takes a number of letters starting from the left/right side of the string. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

LTRIM/RTRIM(ColumnName) * LTRIM / RTRIM SQL Server/MySQL LTRIM/RTRIM(ColumnName) Trims from white spaces from the left/right. MySQL has TRIM function! (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SUBSTRING(ColumnName, StartIndex, Length) * SUBSTRING SQL Server/MySQL SUBSTRING(ColumnName, StartIndex, Length) Returns a substring of the string (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL CHARINDEX LOCATE(substr, CHARINDEX(substr, str, str, * CHARINDEX SQL Server MySQL CHARINDEX(substr, str, [position]) LOCATE(substr, str, position) Returns the start index of the substring in the big string. Returns 0 if no index is found. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

REPLACE(StringExpression, StringPattern, StringReplacement) * REPLACE SQL Server/MySQL REPLACE(StringExpression, StringPattern, StringReplacement) Replaces the given string pattern with the replacement string. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL REPLICATE REPLICATE(ColumnName, NumberOfTimes) * REPLICATE SQL Server MySQL REPLICATE(ColumnName, NumberOfTimes) REPEAT(column_name, number_of_times) Repeats the given string, given number of times. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL REVERSE REVERSE(ColumnName) Reverses the given string * REVERSE SQL Server/MySQL REVERSE(ColumnName) Reverses the given string (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL STUFF / INSERT STUFF(ColumnName, StartIndex, Length, * STUFF / INSERT SQL Server MySQL STUFF(ColumnName, StartIndex, Length, InsertStr) INSERT(column_name, start_index, length, insert_str) Deletes length number of symbols starting from the given start index and then inserts the given insert string at the start index. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Math Functions

SQL Server/MySQL PI PI() Returns the value of PI * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL ABS ABS(Number) * ABS SQL Server/MySQL ABS(Number) Returns the absolute value of a given number. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL FLOOR / CEILING FLOOR/CEILING(number) * FLOOR / CEILING SQL Server/MySQL FLOOR/CEILING(number) Return the lower/higher integer number to the given number. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL POWER POWER(NumberToRaise, Power) * POWER SQL Server MySQL POWER(NumberToRaise, Power) POW(number_to_raise, power) Returns the given number raised to the given power (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL Random RAND() RAND(Seed) * Random SQL Server/MySQL RAND() RAND(Seed) Returns a random number between 0 and 1. If the seed is the same, the generated random number is also the same. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL ROUND ROUND(Number, Precision) * ROUND SQL Server/MySQL ROUND(Number, Precision) Rounds the numbers after the floating point of a given float number. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL SIGN SIGN(Number) * SIGN SQL Server/MySQL SIGN(Number) Returns (-1, 0, 1) depending on the sign of the number. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server/MySQL Square Root SQRT(Number) * (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Date Functions

SQL Server MySQL Date Addition DATEADD( DatePart, Quantity, * Date Addition SQL Server MySQL DATEADD( DatePart, Quantity, ColumnName) DATE_ADD( column_name, INTERVAL quantity date_part) Add a number of “intervals” to the date. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL Date Difference DATEDIFF( DatePart, FirstDate, * Date Difference SQL Server MySQL DATEDIFF( DatePart, FirstDate, SecondDate) DATEDIFF( first_date, second_date) In SQL Server, returns the difference of the given date part. In MySQL, returns the difference in days. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL Date Name DATENAME( DAYNAME(date) DatePart, Date) * Date Name SQL Server MySQL DATENAME( DatePart, Date) DAYNAME(date) In MySQL returns the name of the day of the week. In SQL Server, returns what the desired date part is. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL Day / Month / Year DAY / MONTH / YEAR(Date) DAY / * Day / Month / Year SQL Server MySQL DAY / MONTH / YEAR(Date) DAY / DAYOFMONTH / DAYOFYEAR(date) (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL GETDATE() NOW() Current Time * Current Time SQL Server MySQL GETDATE() NOW() Returns the current date and time. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Other Functions

SQL Server/MySQL Cast CAST (expression AS type) * Cast SQL Server/MySQL CAST (expression AS type) Casts an expression to a give type. (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL Conversion CONVERT(type, expr) CONVERT(expr, type) * Conversion SQL Server MySQL CONVERT(type, expr) CONVERT(expr, type) Converts from one type to another (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

SQL Server MySQL Null Check ISNULL( CheckExpression, ReplacementValue) * Null Check SQL Server MySQL ISNULL( CheckExpression, ReplacementValue) IFNULL( check_expression, replacement_value) Converts from one type to another (c) 2007 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

Wildcards

Using LIKE syntax SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;

Wildcards % - A substitute for zero or more characters _ - A substitute for a single character [charlist] – Sets and ranges of characters to match [^charlist] or [!charlist] – Matches only a character not in the brackets (Not working in MYSQL)

Summary There are a lot of built in functions that can help us make some programmable logic inside the database. There are some differences between the SQL Server and the MySQL functions, but almost all of them have their equivalent in one way or another.

Built-in Functions https://softuni.bg/courses/ © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

License This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International" license Attribution: this work may contain portions from "Databases" course by Telerik Academy under CC-BY-NC-SA license © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

Free Trainings @ Software University Software University Foundation – softuni.org Software University – High-Quality Education, Profession and Job for Software Developers softuni.bg Software University @ Facebook facebook.com/SoftwareUniversity Software University @ YouTube youtube.com/SoftwareUniversity Software University Forums – forum.softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.