Download presentation
Presentation is loading. Please wait.
Published bySimon Lester Modified over 9 years ago
1
Chapter Five 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
2 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
3
3 General Format SELECT fieldnames FROM relation [ WHERE condition] [ GROUP BY group_field ] [ HAVING condition] [ ORDER BY fieldname] ;
4
4 Select Attributes: Example: Show the name and GPA of the students (ALL). SELECT name, GPA FROMstudent;
5
5 Select Attributes: Example: List all the columns in course SELECT* FROMcourse;
6
6 General Format Table display: Default justification: -Date and charactersLEFT -NumberRIGHT Default display: -Uppercase
7
7 General Format NAMEGPA ------------ ---------- MARY 3.1
8
8 Practice: List all columns in customer table
9
9 Duplicated Rows Example: List of the course credits offered at FSU. SELECT Cr FROMCourse;
10
10 Use of Distinct: Example: Type of the course credits offered at FSU. SELECT DISTINCT Cr FROMCourse;
11
11 Practice: List of cities in customer table. (Unique city name)
12
12 Use of Aliases: Example: List of the faculty’s name and their salary per month. SELECT name, salary / 12 FROM faculty;
13
13 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;
14
14 Use of Aliases: NAMEPAY NEW_SALARY -------- ------ -----------------
15
15 Practice: Produce the following list: Customer_City Customer_State Customer_Zip_Code ----------------- ------------------ ------------------------
16
16 Use of Arithmetic Operations: () -, *, / +, - Operation of some priority is evaluated from left to right 5* (2+1)
17
17 Use of Arithmetic Operations: Example: List the course numbers and credits in a quarter system SELECTC_Num, Cr * 0.75 FROMCourse;
18
18 Use of Concatenation: Example: List of faculty and department as a unit SELECTname || dept “Name:” FROM faculty; Name: ----------------------------- CHITSAZCOSC
19
19 Use of Literal: Example: List of faculty and department SELECTname || ‘ ‘ || ‘is in ’ || dept “Department Name:” FROM faculty; Department Name: ------------------------- CHITSAZ is in COSC
20
20 Condition statements: SELECTname, GPA FROMstudent WHEREGPA > 2;
21
21 Condition Operators: =, >, >=, != ^= IN BETWEEN..... AND..... LIKE IS NULL AND, OR, NOT
22
22 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’
23
23 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
24
24 Question What kind of information you get if you use this condition: SELECTname FROMstudent WHEREGPA > 3 OR major = 'COSC';
25
25 Question What kind of information you get if you use this condition: SELECTname FROMstudent WHERE(GPA > 3 AND major = 'COSC') OR(GPA>2.5 AND major=‘ART ’);
26
26 Practice: List of Last name, First name of customers with a balance > 2000 and their birth date is before March, 01, 1985.
27
27 Precedence Rule: >, >=, <>, <=, =, NOT AND OR
28
28 Practice: List Last name of customer which have a balance >100 or credit limit <2000 and live in MD from the customer table.
29
29 Null vs. No Value Null value is: Unavailable Unassigned Unknown Inapplicable Examples: Null is not the same as zero or blank
30
30 Null vs. No Value SELECTname, Major FROMStudent; SELECTname, Num_Faculty FROMDepartment;
31
31 Null Values in Expressions Result of an arithmetic expression with a null value is null. SELECTname, GPA*0.75 FROMStudent;
32
32 Null vs. No Value List of students with no major SELECTname FROMStudent WHEREmajor IS NULL; SELECTname FROMStudent WHEREmajor IS NOT NULL;
33
33 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;
34
34 Practice: List of customer first and last names which have not been assigned a sales rep. number.
35
35 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;
36
36 Use of Between SELECTTitle FROMCourse WHERE C_Num NOT BETWEEN 200 AND 299; SELECTTitle FROMCourse WHERE (C_Num >= 200) AND (C_Num <= 299);
37
37 Use of Between List of Faculty’s name from D to E SELECTname FROMfaculty WHERE name BETWEEN ‘D’ AND ‘E’;
38
38 Question List of names starting with D only!
39
39 Practice: List the order numbers of items with a order quoted price between $100 and $1000
40
40 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);
41
41 Use of IN SELECTname FROMStudent WHERE major IN (‘COSC’, ‘MATH’); SELECT name FROM Student WHERE major NOT IN (‘COSC’, ‘MATH’);
42
42 Practice: List customer number, first and last name of customers with Zip code of 11011 or 12011 or 10012 or 11001
43
43 Use of LIKE LIKE: Determines the presence of a sub string (_) a single unknown character (%) any number of unknown characters
44
44 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%’;
45
45 Use of LIKE List of students records with the second character to be ‘K’ SELECT* FROMStudent WHERE name LIKE ‘_K’;
46
46 Practice: List of customers with the last name ending with “SON” like Jackson, Nelson, Larson.
47
47 Practice: List of customer Last names who live in a street name which has a character string ‘upper’ like ‘South upper Potomac’, ‘upper Dakota’, ‘Magnolia upper’
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.