Presentation is loading. Please wait.

Presentation is loading. Please wait.

Built-in Functions. Usage of Wildcards

Similar presentations


Presentation on theme: "Built-in Functions. Usage of Wildcards"— Presentation transcript:

1 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 © Software University Foundation – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

2 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 – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

3 Questions sli.do #8594

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

5 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

6 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

7 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

8 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

9 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

10 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

11 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

12 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

13 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

14 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

15 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

16 Math Functions

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

18 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

19 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

20 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

21 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

22 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

23 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

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

25 Date Functions

26 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

27 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

28 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

29 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

30 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

31 Other Functions

32 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

33 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

34 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 - All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.*

35 Wildcards

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

37 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)

38 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.

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

40 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 – This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license.

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


Download ppt "Built-in Functions. Usage of Wildcards"

Similar presentations


Ads by Google