Lecture3b - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data Guide to Oracle 10g ITBIS373 Database Development.

Slides:



Advertisements
Similar presentations
© Abdou Illia MIS Spring 2014
Advertisements

Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
A Guide to Oracle9i1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
1 Chapter 3: Using Oracle to Add, View, and Update Data.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Guide to Oracle 10g1 Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
1 Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Microsoft Access 2010 Chapter 7 Using SQL.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Guide to Oracle10G1 Using SQL Queries to Insert, Update, Delete, and View Data Chapter 3.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
Chapter 2 Basic SQL SELECT Statements
Using SQL Queries to Insert, Update, Delete, and View Data Date Retrieval from a single table & Calculations © Abdou Illia MIS Spring 2015.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
Chapter 10 Queries and Updating Part C. SQL Copyright 2005 Radian Publishing Co.
Chapter 3 Single-Table Queries
Lesson 31: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Design.
Microsoft Access 2010 Building and Using Queries.
Chapter 10 Selected Single-Row Functions Oracle 10g: SQL.
ITBIS373 Database Development
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Oracle 11g: SQL Chapter 10 Selected Single-Row Functions.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
ITBIS373 Database Development Lecture 3a - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
1 Creating and Maintaining Database Objects Part 1 Database Systems.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Single-Table Queries 2: Advanced Topics CS 320. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data SELECT field1, field2,
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
Lesson 4: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Set query.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
MySQL Tutorial. Databases A database is a container that groups together a series of tables within a single structure Each database can contain 1 or more.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
1 ORACLE I 3 – SQL 1 Salim Phone: YM: talim_bansal.
Writing Basic SQL SELECT Statements
Contents Preface I Introduction Lesson Objectives I-2
Shelly Cashman: Microsoft Access 2016
Presentation transcript:

Lecture3b - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data Guide to Oracle 10g ITBIS373 Database Development

Guide to Oracle 10g2 Lesson B Objectives After completing this lesson, you should be able to: Write SQL queries to retrieve data from a single database table Create SQL queries that perform calculations on retrieved data Use SQL group functions to summarize retrieved data

Guide to Oracle 10g3 Retrieving Data From a Single Database Table Syntax SELECT columnname1, columnname2, … FROM ownername.tablename [WHERE search_condition]; Retrieve all of columns Use asterisk ( * ) as wildcard character in SELECT clause SELECT * from …

Guide to Oracle 10g4 Suppressing Duplicate Rows SQL DISTINCT qualifier Examines query output before it appears on screen Suppresses duplicate values Syntax SELECT DISTINCT columnname;

Guide to Oracle 10g5

6 Using Search Conditions in SELECT Queries Use search conditions to retrieve rows matching specific criteria Exact search conditions Use equality operator Inexact search conditions Use inequality operators Search for NULL or NOT NULL values WHERE columnname IS NULL WHERE columnname IS NOT NULL

Guide to Oracle 10g7

8 Using Search Conditions in SELECT Queries (continued) IN comparison operator Match data values that are members of a set of search values

Guide to Oracle 10g9

10 LIKE operator Use to match part of character string Syntax WHERE columnname LIKE 'string' Character string should contain wildcard character %, or _, or both. The percent sign (%) wildcard character represents multiple characters. If you place (%) on the left edge of the character string to be matched, the DBMS searches for an exact match on the far-right characters and allows an exact match for the characters represented by(%).

Guide to Oracle 10g11 For example, the search condition WHERE term_desc LIKE ‘%2006’ retrieves all term rows in which the last four characters in TERM_DESC column The DBMS ignores the characters on the left side of the character string up to the substring The search condition WHERE term_desc LIKE ‘Fall%’ retrieves all term rows in which the first four characters are Fall, regardless of the value of the rest of the string. The search condition WHERE course_name LIKE’%Systems%’ retrieves every row in the COURSE table in which the COURSENAME column contains the character string Systems any where in the string.

Guide to Oracle 10g12 The underscore ( _ ) wildcard character represents a single character. For example, the search condition WHERE s_class LIKE ‘_R’ retrieves all values for S_CLASS in which the first character can be any value, but the second character must be the letter R. You can use the underscor ( _ ) and percent sign (%) wildcard characters together in a single search condition. For example, the search condition WHERE c_sec-day LIKE ‘_T%’ retrieves all course sections that meet on Tuesday, provided exactly one character proceeds T in the C_SEC_DAY column. The search condition ignores all of the characters that follow T in the column table value, so the query retrieves values such as MT, MTW, and MTWRF.

Guide to Oracle 10g13

Guide to Oracle 10g14 Sorting Query Output ORDER BY clause Sort query output Syntax for select with ordered results SELECT columnname1, columnname2, … FROM ownername.tablename WHERE search_condition ORDER BY sort_key_column; Sort can be ascending or descending Can specify multiple sort keys

Guide to Oracle 10g15

Guide to Oracle 10g16

Guide to Oracle 10g17 Using Calculations in SQL Queries Perform many calculations directly within SQL queries Very efficient way to perform calculations Create SQL queries Perform basic arithmetic calculations Use variety of built-in functions

Guide to Oracle 10g18  Arithmetic operations on retrieved data  Addition (+)  Subtraction (-)  Multiplication (*)  Division (/)  Example: SELECT inv_id, qoh*price FROM inventory;

Guide to Oracle 10g19

Guide to Oracle 10g20 Performing Arithmetic Calculations Perform arithmetic calculations on columns that have data types NUMBER DATE INTERVAL SYSDATE pseudocolumn Retrieves current system date Use + and – to calculate differences between dates

Guide to Oracle 10g21

Guide to Oracle 10g22

Guide to Oracle 10g23 Interval Calculation The oracle 10g DBMS can perform calculations using interval values that store elapsed time value.

Guide to Oracle 10g24 Ex: suppose you need to update the TIME_ENROLLED column every month by adding one month to the interval value. SELECT s_id, time_enrolled + TO_YMINTERVAL(‘0- 1’) FROM student; Similarity, you use the following query to add an interval of 10 minutes to the c_SEC_DURATION column in the COURSE_SECTION table. SELECT c-sec_id, c_sec_duration + TO_DSINTERVAL (‘0 00:10:00’) FROM course_section;

Guide to Oracle 10g25 Oracle 10g SQL Functions Built-in functions perform calculations and manipulate retrieved data values Called single-row functions Return single result for each row of data retrieved To use: List function name in SELECT clause followed by required parameter in parentheses

Guide to Oracle 10g26

Guide to Oracle 10g27

Guide to Oracle 10g28 Single-row Character Functions

Guide to Oracle 10g29

Guide to Oracle 10g30

Guide to Oracle 10g31 Single-row Data Functions

Guide to Oracle 10g32

Guide to Oracle 10g33 Oracle 10g SQL Group Functions Group function Performs operation on group of queried rows Returns single result such as column sum To use: List function name followed by column name in parentheses

Guide to Oracle 10g34

Guide to Oracle 10g35

Guide to Oracle 10g36 Using the COUNT Group Function The COUNT group function returns an integer that represents the number of rows that a query returns. The COUNT(*) version of this function calculates the total number of rows in a table that satisfy a given search condition. The COUNT(*) function is the only group function in Table3-10 that include NULL values. The other functions ignore NULL values.

Guide to Oracle 10g37

Guide to Oracle 10g38 Using the GROUP BY Clause to Group Data GROUP BY clause Group output by column with duplicate values Apply group functions to grouped data Syntax GROUP BY group_columnname; Follows FROM clause All columns listed in SELECT clause must be included in GROUP BY clause

Guide to Oracle 10g39

Guide to Oracle 10g40

Guide to Oracle 10g41

Guide to Oracle 10g42 Using the HAVING Clause to Filter Grouped Data HAVING clause Place search condition on results of queries that display group function calculations Syntax HAVING group_function comparison_operator value Example HAVING sum(capacity) >= 100

Guide to Oracle 10g43

Guide to Oracle 10g44 Creating Alternate Column Headings Column headings for retrieved columns are names of database table columns Specify alternate output heading text SELECT columnname1 "heading1_text ", columnname2 "heading2_text", …

Guide to Oracle 10g45 Creating Alternate Column Headings (continued) Alias Alternate name for query column Syntax SELECT columnname1 AS alias_name1…

Guide to Oracle 10g46 Formatting Data Using Format Models TO_CHAR function Convert column to character string Apply desired format model to value Syntax TO_CHAR(column_name, 'format_model') Use for data types DATE INTERVAL NUMBER

Guide to Oracle 10g47