Instructor: Craig Duckett Lecture 08: Thursday, October 22 nd, 2015 Patterns, Order of Evaluation, Concatenation, Substrings, Trim, Position 1 BIT275:

Slides:



Advertisements
Similar presentations
Java Programming Strings Chapter 7.
Advertisements

MIS: Chapter 14 Cumulative concepts, features and functions, plus new functions COUNTIFS, SUMIFS, AVERAGEIFS (Separate ppt on REACH.louisville.edu) All.
CSC271 Database Systems Lecture # 11.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
1 Query Languages. 2 Boolean Queries Keywords combined with Boolean operators: –OR: (e 1 OR e 2 ) –AND: (e 1 AND e 2 ) –BUT: (e 1 BUT e 2 ) Satisfy e.
Introduction to Structured Query Language (SQL)
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
JavaScript, Third Edition
UNIX Filters.
Chapter 5 new The Do…Loop Statement
Lesson 3 – Regular Expressions Sandeepa Harshanganie Kannangara MBCS | B.Sc. (special) in MIT.
IFS Intro. to Data Management Chapter 6 Filtering your data.
Chapter 9 Creating Formulas that Manipulate Text Microsoft Office Excel 2003.
Tutorial 14 Working with Forms and Regular Expressions.
Chapter 3 Single-Table Queries
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
ASP.NET Programming with C# and SQL Server First Edition Chapter 5 Manipulating Strings with C#
Strings The Basics. Strings can refer to a string variable as one variable or as many different components (characters) string values are delimited by.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Selecting Data.
Copyright Curt Hill SQL Queries Yet Another Set of Query Features.
Instructor: Craig Duckett Lecture 02: Thursday, October 1 st, 2015 SQL Basics and SELECT, FROM, WHERE 1 BIT275: Database Design (Fall 2015)
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 24 The String Section.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
REGEX. Problems Have big text file, want to extract data – Phone numbers (503)
Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
Chapter 7: Characters, Strings, and the StringBuilder.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Instructor: Craig Duckett Lecture 02: Thursday, April 9, 2015 SQL Basics and SELECT, FROM, WHERE 1.
(Spring 2015) Instructor: Craig Duckett Lecture 08: Tuesday, May 5, 2015 Mere Mortals Chap. 6 Summary, Team Work Time 1.
More Strings CS303E: Elements of Computers and Programming.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Restrictions Objectives of the Lecture : To consider the algebraic Restrict operator; To consider the Restrict operator and its comparators in SQL.
1 CSE 2337 Chapter 7 Organizing Data. 2 Overview Import unstructured data Concatenation Parse Create Excel Lists.
Strings PART I STRINGS, DATES, AND TIMES. FUNDAMENTALS OF CHARATERS AND STRINGS VB represents characters using American National Standards Institute(ANSI)
Gollis University Faculty of Computer Engineering Chapter Five: Retrieval, Functions Instructor: Mukhtar M Ali “Hakaale” BCS.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
Instructor: Craig Duckett Lecture 06: Thursday, October 15 th, 2015 Indexes, Aliases, Distinct, SQL 1 BIT275: Database Design (Fall 2015)
Lesson 4 String Manipulation. Lesson 4 In many applications you will need to do some kind of manipulation or parsing of strings, whether you are Attempting.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Restricting and Sorting Data
Open Source Server Side Scripting MySQL Functions
MySQL: Part II.
Writing Basic SQL SELECT Statements
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Strings Part 1 Taken from notes by Dr. Neil Moore
String and Lists Dr. José M. Reyes Álamo.
Topics Basic String Operations String Slicing
Introduction to Computer Science
Python Strings.
Topics Basic String Operations String Slicing
Exam Prep.
REGEX.
Restricting and Sorting Data
Strings Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Topics Basic String Operations String Slicing
What We Want To Do User enters: Mary Smith
Presentation transcript:

Instructor: Craig Duckett Lecture 08: Thursday, October 22 nd, 2015 Patterns, Order of Evaluation, Concatenation, Substrings, Trim, Position 1 BIT275: Database Design (Fall 2015)

2 Quick Reminder: If you need to me about anything, please do so using my account which I check several times a day. Do not use or reply to the account which I use only for returning files from StudentTracker and only check once or twice a month!  NO CLASS NEXT TUESDAY, October 27 th. It is a non-instructional day. MID-TERM EXAM is LECTURE 10, Tuesday, November 3 rd Assignment 2 is due LECTURE 11, Thursday, November 5 th, in StudentTracker by MIDNIGHT It will cover everything discussed through Thursday’s lecture, Lecture 9, including any chapter reading from The DATABASE DESIGN FOR MERE MORTALS and THE LANGUAGE OF SQL books. You’re allowed to use one large index card for crib notes during the mid-term. I’ll post a Mid-Term Study Guide on the BIT275 website sometime on Friday, May 8.

3 Tuesday (LECTURE 8) Database Design for Mere Mortals: Chapter 6 Thursday (LECTURE 9) The Language of SQL: Chapters 7, 8

4 Patterns Order of Evaluations Concatenation Substring TRIM POSITION

5 Patterns

Matching Patterns with LIKE You can use LIKE to retrieve rows based on partial information. LIKE is useful if you don’t know an exact value (“The author’s last name is Kel-something”) or you want to retrieve rows with similar values (“Which authors live in the San Francisco Bay Area?”). The LIKE condition’s important characteristics are: LIKE works with only character strings, not numbers or datetimes. LIKE uses a pattern that values are matched against. A pattern is a quoted string that contains the literal characters to match and any combination of wildcards. Wildcards are special characters used to match parts of a value. Wildcard Operators

String comparisons are case insensitive or case sensitive, depending on your DBMS. You can negate a LIKE condition with NOT LIKE. You can combine LIKE conditions and other conditions with AND and OR.

Escape and Unescaped Patterns

[ ] and [ ^ ] Patterns

BETWEEN Use BETWEEN to determine whether a given value falls within a specified range. The BETWEEN condition’s important characteristics are: BETWEEN works with character strings, numbers, and datetimes. The BETWEEN range contains a low value and a high value, separated by AND. The low value must be less than or equal to the high value. BETWEEN is a convenient, shorthand clause that you can replicate by using AND. BETWEEN is equivalent to: WHERE (test_column >= low_value) AND (test_column <= high_value) BETWEEN specifies an inclusive range, in which the high value and low value are included in the search. To specify an exclusive range, which excludes endpoints, use > and comparisons instead of BETWEEN: WHERE (test_column > low_value) AND (test_column < high_value) String comparisons are case insensitive or case sensitive. You can negate a BETWEEN condition with NOT BETWEEN. You can combine BETWEEN conditions and other conditions with AND and OR.

BETWEEN

IN Use IN to determine whether a given value matches any value in a specified list. The IN condition’s important characteristics are: IN works with character strings, numbers, and datetimes. The IN list is a parenthesized listing of one or more comma-separated values. The list items needn’t be in any particular order. IN is a convenient, shorthand clause that you can replicate by using OR. is equivalent to:

14 Order of Evaluations Operator Precedence

Operators and Order of Evaluation * * * 3 – 2 = ? 1 + (2 * 3) + (4 * 2) + (4 * 3) – 2 = 1 + ( ) – 2 = (1 + 26) – 2 = 27 – 2 = 5

16 Concatenation

Use the operator || to combine, or concatenate, strings. The operator’s important characteristics are: The operator || is two consecutive vertical-bar, or pipe, characters Concatenation doesn’t add a space between strings. || combines two strings into a single string: 'formal' || 'dehyde' is 'formaldehyde‘ You can chain concatenations to combine multiple strings into a single string: 'a' || 'b' || 'c' || 'd' is 'abcd‘ Concatenation with an empty string ('') leaves a string unchanged: 'a' || ' ' || 'b' is 'ab‘ The result of any concatenation operation that involves a null is null: 'a' || NULL || 'b' is NULL To concatenate a string and a nonstring (such as a numeric or datetime value), you must convert the nonstring to a string if your DBMS doesn’t convert it implicitly (CAST). NOTE : MySQL uses the CONCAT() function for concatenation (CONCAT_WS) Concatenation with separator

Concatenation

19 Substring

SUBSTRING Use the function SUBSTRING() to extract part of a string. The function’s important characteristics are: A substring is any sequence of contiguous characters from the source string, including an empty string or the entire source string itself. SUBSTRING() extracts part of a string starting at a specified position and continuing for specified number of characters. A substring of an empty string is an empty string. If any argument is null, SUBSTRING() returns null. SUBSTRING(string FROM start [FOR length]) string is the source string from which to extract the substring. string is a string expression such as a column that contains character strings, a string literal, or the result of an operation or function that returns a string. start is an integer that specifies where the substring begins. length is an integer that specifies the length of the substring (the number of characters to return). If FOR length is omitted, SUBSTRING() returns all the characters from start to the end of string

SUBSTRING

Changing String Case Use the function UPPER() to return a string with lowercase letters converted to uppercase, and use the function LOWER() to return a string with uppercase letters converted to lowercase. The functions’ important characteristics are: A cased character is a letter that can be lowercase (a) or uppercase (A). Case changes affect only letters. Digits, punctuation, and whitespace are left unchanged. Case changes have no effect on empty strings (''). If its argument is null, UPPER() and LOWER() return null.

Changing String Case EXAMPLE OF WILDCARD WITH STRING CASE: List the titles that contain the characters MO, regardless of case. All the letters in the LIKE pattern must be uppercase for this query to work.

24 TRIM Function

TRIM Use the function TRIM() to remove unwanted characters from the ends of a string. The function’s important characteristics are: You can trim leading characters, trailing characters, or both. (You can not use TRIM() to remove characters from within a string.) By default, TRIM() trims spaces, but you can strip off any unwanted characters, such a leading and trailing zeros or asterisks. TRIM() typically is used to format results and make comparisons in a WHERE clause. TRIM() is useful for trimming trailing spaces from CHAR values. Trimming has no effect on empty strings (''). If any argument is null, TRIM() returns null. To trim spaces from a string: TRIM([ [LEADING | TRAILING | BOTH] FROM] string) string is a string expression such as a column that contains character strings, a string literal, or the result of an operation or function that returns a string. Specify LEADING to remove leading spaces, TRAILING to remove trailing spaces, or BOTH to remove leading and trailing spaces. If this specifier is omitted, BOTH is assumed.

TRIM

27 POSITION Function

POSITION Use the function POSITION() to locate a particular substring within a given string. The function’s important characteristics are: POSITION() returns an integer (=0) that indicates the starting position of a substring’s first occurrence within a string. If the string doesn’t contain the substring, POSITION() returns zero. String comparisons are case insensitive or case sensitive, depending on your DBMS The position of any substring within an empty string ('') is zero. If any argument is null, POSITION() returns null. POSITION (substring IN string)

POSITION

30 BIT 275 ICE 8