Академический Документы
Профессиональный Документы
Культура Документы
Jonathan Miller
Learning SQL Series
Items To be Covered
Functions
Group
String
Date
Number
WHERE condition(s)
ORDER BY column(s)
Optional Elements
3
PARAMETERS
MO_ID
SI_SI_ID
PA_PARAMETER_CODE
POC
Parameter_Code
Parameter_Desc
44201
44201
Ozone
42101
42101
81102
42101
CO
42401
SO2
44201
81102
PM10
42401
1
4
MONITORS
PARAMETERS
MO_ID
SI_SI_ID
PA_PARAMETER_CODE
POC
Parameter_Code
Parameter_Desc
44201
44201
Ozone
42101
42101
81102
42101
CO
42401
SO2
44201
81102
PM10
42401
61
Aliases
SITES
MONITORS
QUALIFIER_
DETAILS
RAW_DATA
MONITOR_
PROTOCOLS
Join Types
Simple Join:
Inner Join
Outer Join
jm1
Outer Joins
12
Self Joins
Parent Record
Parent Record
Parent Record
Parent Record
13
What is It
14
15
B
C
16
QUESTION:
1. A UNION B
2
4
C
7
ANSWER:
1, 2, 3, 4, 5, 6
2. A MINUS B
1, 4
3. A INTERSECT (B MINUS C)
4. C UNION (B INTERSECT A)
2, 4, 5, 6,187
20
21
Subqueries
22
Subquery Examples
23
24
26
Functions
27
What is a Function?
28
Function Notation
FUNCTION(parameter {datatype},
[optional parameters])
Datatypes
VARCHAR2 (Apple, Sample Text *, 1234)
NUMBER (1, 1.03, -15)
DATE Well talk about this one later
29
Types of Functions
String Functions
Mathematical Functions
Single-Value Functions
Group-Value Functions
List Functions
SELECT Statement
SELECT INITCAP(agency_desc)
FROM agencies
WHERE Statement
SELECT *
FROM sites
WHERE SUBSTR(lut_land_use_type, 1) = MOBILE
31
DUAL Table
SELECT A
FROM DUAL
Result: A
32
||
INITCAP(String)
INSTR(String, set [, start [, occurrence] ])
LENGTH(String)
LOWER(String) / UPPER(String)
Concatenate (||)
SELECT Go || WOLFPACK
FROM DUAL
Results: Go WOLFPACK
34
In String - INSTR
36
LENGTH
37
LPAD / RPAD
SELECT LPAD(Carrot,10)
FROM dual
Result:
Carrot
SELECT RPAD(Carrot,10, x)
FROM dual
Result: Carrotxxxx
38
LTRIM / RTRIM
Trims off a Set of Characters from Either the Left (LTRIM) or Right
(RTRIM) of a String
39
Substring - SUBSTR
May Tell it How Many Characters to Clip (Default is to clip to end of the
string)
40
Mathematic Functions
GREATEST (List)
LEAST (List)
Group Functions
41
Group Functions
By Size
11
4
1
Total Count
By Color
1
32
42
Transformation Functions
44
Oracle Dates
46
Date Comparisons
TO_DATE(20041116, YYYYMMDD) =
sysdate is not a true statement.
47
Date Functions
TO_DATE(2004-NOV-02, YYYY-MON-DD)
TO_CHAR(sysdate, YYYYMMDD)
49
Date Arithmetic
50
Summary
Summary (Continued)
54
Any Questions?
55