Chapter Eight Data Manipulation Language (DML) Objectives Oracle DBMS Understanding the DML General format of SQL Capability of SELECT statement Use of.

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Advertisements

1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
SQL Review Sections 1 - SQL and other basic statements.
1 Chapter Seven (part 2) Multiple Row Functions: Objectives: -Multiple row functions -Ordering -Grouping -Concept of JOIN.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following:  List the capabilities of SQL SELECT statements.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Chapter 2 Basic SQL SELECT Statements
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Chapter Four Objectives Introduction to SQL Types of SQL statements Concepts of DDL & DML Creating Tables Restrictions on Tables Data Definition Language(DDL)
Copyright  Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University 1 Basic SQL Statements Oracle/SQL Plus Commands Kroenke, 11 th ed., Chapter Two.
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
After completing this lesson, you should be able to do the following: List the capabilities of MySQL SELECT statements Execute a basic SELECT statement.
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
RELATSIOONILISED ANDMEBAASID(alg) SQLi VÕIMALUSED.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
Chapter Six Objectives Introduction to SQL Types of SQL statements Concepts of DDL & DML Creating Tables Restrictions on Tables Data Definition Language(DDL)
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
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.
Structured Query Language
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
1 Chapter Ten Multiple Row Functions/Join: Objectives: -Multiple row functions -Ordering -Grouping -Concept of JOIN.
Chapter Five Data Manipulation Language (DML) Objectives Oracle DBMS Understanding the DML General format of SQL Capability of SELECT statement Use of.
Chapter Eleven Data Manipulation Language (DML) Nested Queries Dr. Chitsaz Objectives Nested queries Application of nested queries Conditions on nested.
Working with Columns, Characters, and Rows. 2 home back first prev next last What Will I Learn? In this lesson, you will learn to: –Apply the concatenation.
Chapter Twelve Report Writing Objectives: -Writing reports -Page set up -Page layout.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
1-1 Copyright  Oracle Corporation, All rights reserved. Logging In to SQL*Plus From Windows environment:From Windows environment: From command line:From.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Chapter 21: Report writing1 Chapter Twenty One Producing Readable Output Objectives: Writing reports Page set up Page layout Queries with input.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
Writing Basic SQL SELECT Statements Lecture
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Chapter Four Objectives Introduction to SQL Introduction to iSQL*PLUS Types of SQL statements Concepts of DDL & DML Data Manipulation Language (DML)
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Restricting and Sorting Data
RELATSIOONILISED ANDMEBAASID (algus , ORACLE materjalid)
Retrieving Data Using the SQL SELECT Statement
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Basic select statement
Chapter Twenty Producing Readable Output
Writing Basic SQL SELECT Statements
Retrieving Data Using the SQL SELECT Statement
Writing Basic SQL SELECT Statements
Contents Preface I Introduction Lesson Objectives I-2
Writing Basic SQL Statements
Retrieving Data Using the SQL SELECT Statement
Restricting and Sorting Data
Presentation transcript:

Chapter Eight Data Manipulation Language (DML) Objectives Oracle DBMS Understanding the DML General format of SQL Capability of SELECT statement Use of Operators String Processing Concept of NULL Conditional Statement

2 SQL Structured Query Language Developed by IBM Used in most Commercial DBMS Statements are not case sensitive. Statements can be on one or more lines. Reserved words cannot be abbreviated or split over lines. Terminated with a semicolon. Statements are entered at SQL prompt. The subsequent lines are numbered (SQL buffer) Only one statement can be current at any time in the buffer.

3 Example: Student(Name, ID, GPA, Major, B_Date) Course(C_Num, Dept, Title, Cr) Student_Course(ID, C_Num, Dept, Grade) Faculty(ID, Name, Dept, Salary, Area) Faculty_Course(ID, C_Num, Dept, Semester) Department(Name, Num_Faculty) Tables

4 General Format SELECT fieldnames FROM relation [ WHERE condition] [ GROUP BY group_field ] [ HAVING condition] [ ORDER BY fieldname] ;

5 Select Attributes: Example: Show the name and GPA of the students (ALL). SELECT name, GPA FROMstudent;

6 Select Attributes: Example: List all the columns in course SELECT* FROMcourse;

7 General Format Table display: Default justification: -Date and charactersLEFT -NumberRIGHT Default display: -Uppercase

8 General Format NAMEGPA MARY 3.1

9 Duplicated Rows Example: List of the course credits offered at FSU. SELECT Cr FROMCourse;

10 Use of Distinct: Example: Type of the course credits offered at FSU. SELECT DISTinct Cr FROMCourse;

11 Use of Aliases: Example: List of the faculty ’ s name and their salary per month. SELECT name, salary / 12 FROM faculty;

12 Use of Aliases: Rename column heading Example: List of the faculty salary for next year with 5% increase. SELECT name, salary Pay, salary+salary*0.05 AS New_Salary FROM faculty;

13 Use of Arithmetic Operations: () -, *, / +, - Operation of some priority is evaluated from left to right 5* (2+1)

14 Use of Arithmetic Operations: Example: List the course numbers and credits in a quarter system SELECTC_Num, Cr * 0.75 FROMCourse;

15 Use of Concatenation: Example: List of faculty and department as a unit SELECTname || dept “ Name: ” FROM faculty; Name: CHITSAZCOSC

16 Use of Literal: Example: List of faculty and department SELECTname || ‘ ‘ || ‘ is in ’ || dept “ Department Name: ” FROM faculty; Department Name: CHITSAZ is in COSC

17 Condition statements: SELECTname, GPA FROMstudent WHEREGPA > 2;

18 Condition Operators: =, >, >=, != ^= IN BETWEEN..... AND..... LIKE IS NULL AND, OR, NOT

19 String & Date Comparison Example: List the students who born on March 2, 99 SELECTname FROMstudent WHEREB_Date = ’ 02-MAR-99 ’ ; Date Format ‘ DD-MON-YY ’

20 Use of Boolean Operations: Example: List of Student names that have a GPA > 3 and majoring in COSC SELECTname FROMstudent WHEREGPA > 3 AND major = 'COSC'; Character string is case sensitive & should be in a single quotation mark

21 Precedence Rule: >, >=, <>, <=, =, NOT AND OR

22 Null vs. No Value Null value is: Unavailable Unassigned Unknown Inapplicable Examples: Null is not the same as zero or blank

23 Null vs. No Value SELECTname, Major FROMStudent; SELECTname, Num_Faculty FROMDepartment;

24 Null Values in Expressions Result of an arithmetic expression with a null value is null. SELECTname, GPA*0.75 FROMStudent;

25 Null vs. No Value List of students with no major SELECTname FROMStudent WHEREmajor IS NULL; SELECTname FROMStudent WHEREmajor IS NOT NULL;

26 Null vs. No Value NVL Null Value substitution: We can substitute a value for a NULL value record by using NVL. List of students and their major: SELECTname, NVL(major, ‘unknown’) FROMStudent; SELECT name, NVL(GPA, 0.0) FROM Student; *COALESCE

27 Null vs. No Value List of students and their GPA base 20 points: SELECT name, NVL(GPA, 0.0)*5 FROM Student; NVL2 (Exp1, Exp2, Exp3)

28 Use of Between BETWEEN: Test against a list of values: (Check the data in a range) List description of courses with the course number between 200 AND 299 SELECTTitle FROMCourse WHEREC_Num BETWEEN 200 AND 299;

29 Use of Between SELECTTitle FROMCourse WHERE C_Num NOT (BETWEEN 200 AND 299); SELECTTitle FROMCourse WHERE (C_Num >= 200) AND (C_Num <= 299);

30 Use of Between List of Faculty’s name from D to E SELECTname FROMfaculty WHERE name BETWEEN ‘D’ AND ‘E’;

31 Use of IN IN: Tests against a list of values: (Set of values used for comparison) List of students with ID = 1111, ID = 2111 or ID = 3111 SELECTname FROMStudent WHERE ID IN (1111, 2111, 3111);

32 Use of IN SELECTname FROMStudent WHERE major IN (‘COSC’, ‘MATH’); SELECT name FROM Student WHERE major NOT IN (‘COSC’, ‘MATH’);

33 Example of IN page IN (2, 3,4, 5, 6) page NOT IN (2, 3,4, 5, 6) page BETWEEN 2 AND 6 section IN (‘A’, ‘B’, ‘C’, ‘D’, ‘E’) section NOT IN (‘A’, ‘B’, ‘C’, ‘D’, ‘E’) section BETWEEN ‘A’ AND ‘E’

34 Use of LIKE LIKE: Determines the presence of a sub string (_) a single unknown character (%) any number of unknown characters

35 Use of LIKE List all the student’s records so that the student’s name starts with a ‘K’ SELECT* FROMStudent WHERE name LIKE ‘K%’;

36 Use of LIKE List of students records with the second character to be ‘K’ SELECT* FROMStudent WHERE name LIKE ‘_K’;