Upload
kono
View
226
Download
0
Embed Size (px)
Citation preview
7/24/2019 1113 pl sql banner
1/38
SUNGARD SUMMIT 2007 | sungardsummit.com 1
A Community of Learning
Introduction to SQLPresented by: Jennifer Flagel
George Mason University
March 20, 2007
Course ID 1113
7/24/2019 1113 pl sql banner
2/38
2Course ID 1113
Introduction
SQL = Structured Query Language
Communicate the benefits of learning SQL
Provide a basic understanding of relational databasestructures
Translate Banner application data to its underlying
Oracle
source Introduce basic SQL commands for querying Banner
data
Use the MicrosoftAccess SQL editor to perform
simple queries against sample General Person data
7/24/2019 1113 pl sql banner
3/38
SUNGARD SUMMIT 2007 | sungardsummit.com 3
A Community of Learning
Benefits of SQL
7/24/2019 1113 pl sql banner
4/38
4Course ID 1113
Why Learn SQL?
Improves your abil ity to articulate requirements totechnical staff.
Assists in defining population selection rules in Banner.
Enhances your understanding of how Banner operates.
Provides greater flexibili ty for more complex queries.
7/24/2019 1113 pl sql banner
5/38
SUNGARD SUMMIT 2007 | sungardsummit.com 5
A Community of Learning
Relational Database
Structure
7/24/2019 1113 pl sql banner
6/38
6Course ID 1113
Relational Data Model
Each table consists of columns and rows that describe aset of related items (eg., people).
Each row represents a single entity (eg., a person).
Each column represents an attribute of that entity (eg.,first name, last name, ID number).
Every row in a table must be uniquely identified by the
same attribute or set of attributes, defined as theprimary key (eg, PIDM).
Each table is related to one or more other tables througha shared attribute, defined as the foreign key (eg, PIDM).
7/24/2019 1113 pl sql banner
7/38
7Course ID 1113
Sample Relational Table
Each row contains a combination of attributes
that represents a single entity (person).
Each column represents a specific
attribute of all entit ies (people).
Each row is uniquely
identified by the primary key.
7/24/2019 1113 pl sql banner
8/38
8Course ID 1113
Linking Relational Tables
SPRIDEN
SPRIDEN_PIDM
SPRIDEN_ID
SPRIDEN_LAST_NAME
SPRIDEN_FIRST_NAME
SPRIDEN_CHANGE_IND
SPBPERS
SPBPERS_PIDM
SPBPERS_SSN
SPBPERS_BIRTH_DATE
SPBPERS_SEX
SPRADDR
SPRADDR_PIDM
SPRADDR_STREET_LINE1
SPRADDR_CITY
SPRADDR_STAT_CODE
SPRADDR_ZIP
These tables are related through the shared PIDM attribute.
7/24/2019 1113 pl sql banner
9/38
9Course ID 1113
Related General Person Data
The shared PIDM links identification, biographic, and
demographic data from multiple tables with minimal redundancy.
7/24/2019 1113 pl sql banner
10/38
SUNGARD SUMMIT 2007 | sungardsummit.com 10
A Community of Learning
Translating Between
Banner and Oracle
7/24/2019 1113 pl sql banner
11/38
11Course ID 1113
Banner Schemas
Banner data is grouped by process area, similar to theBanner menu structure
Tables are grouped by owner, or schema
GENERAL owns general tables (G%) SATURN owns student tables (S%)
TAISMGR owns accounts receivable tables (T%)
FAISMGR owns financial aid tables (R%)
FIMSMGR owns finance tables (F%) PAYROLL owns payroll tables (P%)
POSNCTL owns employee tables (N%)
ADISMGR owns alumni/development tables (A%)
BANSECR owns security tables (subset of G%) BANINST1 owns Object:Access views
7/24/2019 1113 pl sql banner
12/38
12Course ID 1113
Same convention as form names
First letter describes Banner system
Second letter describes module within that system
Third letter describes type of table
V = validation table
B = base table
R = repeating table Fourth-Seventh letters describe content
Banner Table Names
7/24/2019 1113 pl sql banner
13/38
13Course ID 1113
Replace third character with V, R, or B STVATYP form = STVATYP table
SPAIDEN form = SPRIDEN table
SPAPERS form = SPBPERS table Multiple form blocks represent multiple tables
SPAIDEN ID = SPRIDEN
SPAIDEN Address = SPRADDR
SPAIDEN Telephone = SPRTELE SPAIDEN Biographical = SPBPERS
Use Help>Dynamic Help Query to view table and columnname
Translating Banner Forms to Tables
7/24/2019 1113 pl sql banner
14/38
14Course ID 1113
Column name prefaced by table name SPRIDEN_PIDM SPRIDEN_LAST_NAME
Validated columns reference validation table and end in_CODE SPRADDR_ATYP_CODE = STVATYP_CODE SPRIDEN_NTYP_CODE = STVNTYP_CODE
Indicator columns end in _IND
SPRIDEN_CHANGE_IND SPBPERS_DEAD_IND
Repeating rows ordered by _SEQNO column SPRADDR_SEQNO
SPRTELE_SEQNO
Other Naming Conventions
7/24/2019 1113 pl sql banner
15/38
SUNGARD SUMMIT 2007 | sungardsummit.com 15
A Community of Learning
Basic SQL Commands
7/24/2019 1113 pl sql banner
16/38
16Course ID 1113
SQL Syntax
ANSI approved standard
Proprietary variations
Must support standard keywords
Oracle uses SQL*Plus
Basic command structure:
SELECT column
FROM table
[WHERE condition]
[ORDER BY column];
Sample query to select name and ID for all entities:
SELECT spriden_last_name, spriden_first_name, spriden_idFROM spriden;
7/24/2019 1113 pl sql banner
17/38
17Course ID 1113
Common Statements
DESC table
Produces list of columns and properties
SELECT *
Selects all columns from specified table
SELECT DISTINCT column
Displays unique rows for selected columns
7/24/2019 1113 pl sql banner
18/38
18Course ID 1113
Conditions and Operators
WHERE clause specifies any number of conditions AND must satisfy all conditions OR must satisfy at least one condition ( ) used to group and prioritize conditions
Operators are used to compare values
Values must conform to data type of column Character and date values enclosed in single quotes
Character values case sensitive Date values format sensitive Default date format set locally (eg: DD-MON-YYYY)
= equal to not equal to < less than
> greater than
BETWEEN includes start and end values IN specifies a list of values LIKE must be used with wildcard
IS NULL absence of any value NOT negates other operators
7/24/2019 1113 pl sql banner
19/38
19Course ID 1113
Describe SPRIDENDESC spriden;
Select all columns from SPRIDEN
SELECT *FROM spriden;
Select ID and name for all rows in SPRIDENSELECT spriden_id, spriden_last_name, spriden_first_name
FROM spriden; Select current ID and name for all persons, ordered by
last name and first name
SELECT spriden_id, spriden_last_name, spriden_first_name
FROM spridenWHERE spriden_change_ind IS NULL
AND spriden_entity_ind = P
ORDER BY spriden_last_name, spriden_first_name;
Practice 1: Basic queries
7/24/2019 1113 pl sql banner
20/38
20Course ID 1113
Joins
Joins are used to select data from mult iple tables.
Each join connects two related tables.
Inner join (also called natural join) selects only those
rows where the shared attribute exists in both tables. Outer join selects all rows from one table regardless of
whether the shared attribute exists in the other.
Left outer join selects all rows from first table regardless of
match in second table. Right outer join selects all rows from second table
regardless of match in first table.
New join syntax for Oracle 9i and higherSELECT column
FROM table1
JOIN table2
ONtable1.column =table2.column;
7/24/2019 1113 pl sql banner
21/38
21Course ID 1113
Practice 2: Inner Join
Select current name, ID, and birth date for all persons
SELECT spriden_last_name, spriden_first_name,
spriden_id, spbpers_birth_date
FROM spriden
JOIN spbpers
ON spriden_pidm = spbpers_pidm
WHERE spriden_change_ind IS NULL
AND spriden_entity_ind = P;
7/24/2019 1113 pl sql banner
22/38
22Course ID 1113
Practice 2: Left Join
Select current name, ID, and birth date for all persons
SELECT spriden_last_name, spriden_first_name,
spriden_id, spbpers_birth_date
FROM spridenLEFT JOIN spbpers
ON spriden_pidm = spbpers_pidm
WHERE spriden_entity_ind = P
AND spriden_change_ind IS NULL;
7/24/2019 1113 pl sql banner
23/38
23Course ID 1113
Practice 2: Right Join
Select current name, ID, and birth date for all persons
SELECT spriden_last_name, spriden_first_name,
spriden_id, spbpers_birth_date
FROM spridenRIGHT JOIN spbpers
ON spriden_pidm = spbpers_pidm
WHERE spriden_entity_ind = P
AND spriden_change_ind IS NULL;
7/24/2019 1113 pl sql banner
24/38
24Course ID 1113
Practice 2: Multiple Joins
Select current name and gender for all persons withmailing address in Virginia
SELECT spriden_last_name, spriden_first_name, spbpers_sex
FROM spridenLEFT JOIN spbpers
ON spriden_pidm = spbpers_pidm
JOIN spraddr
ON spriden_pidm = spraddr_pidm
WHERE spriden_change_ind IS NULL
AND spraddr_atyp_code = MA
AND spraddr_stat_code = VA;
7/24/2019 1113 pl sql banner
25/38
25Course ID 1113
Subqueries
Produce subset of data for reference in another query
Can be used as table in FROMSELECT column
FROM(SELECT column
FROM table)
WHERE condition;
Can be used as a condition in WHERESELECT column
FROM table
WHERE column operator
(SELECT columnFROM table);
7/24/2019 1113 pl sql banner
26/38
26Course ID 1113
Practice 3: Subquery in FROM
Select current name and ID for all persons withoutconfidential indicator
SELECT spriden_last_name, spriden_first_name, spriden_id
FROM spridenLEFT JOIN
(SELECT spbpers_pidm
FROM spbpers
WHERE spbpers_confid_ind = Y)
ON spriden_pidm = spbpers_pidm
WHERE spriden_change_ind IS NULL
AND spbpers_pidm IS NULL;
7/24/2019 1113 pl sql banner
27/38
27Course ID 1113
Practice 3: Subquery in WHERE
Select current name and ID for all persons withoutmailing address
SELECT spriden_last_name, spriden_first_name,
spriden_idFROM spriden
WHERE spriden_change_ind IS NULL
AND spriden_pidm NOT IN
(SELECT spraddr_pidmFROM spraddr
WHERE spraddr_atyp_code = MA);
7/24/2019 1113 pl sql banner
28/38
28Course ID 1113
Aggregate Functions
Perform mathematical summaries over a group of rows
MIN
MAX
COUNT AVG
SUM
Results in an aggregate total for each uniquecombination of selected columns
Must specify non-aggregate columns in GROUP BY
SELECT column1, column2, SUM(column3)
FROM tableWHERE condition
GROUP BY column1, column2;
7/24/2019 1113 pl sql banner
29/38
29Course ID 1113
Select count of persons by ethnicity and gender
SELECT spbpers_ethn_code, spbpers_sex,
COUNT(spriden_pidm)
FROM spridenLEFT JOIN spbpers
ON spriden_pidm = spbpers_pidm
WHERE spriden_entity_ind = P
AND spriden_change_ind IS NULL
GROUP BY spbpers_ethn_code, spbpers_sex;
Practice 4: Aggregation
7/24/2019 1113 pl sql banner
30/38
30Course ID 1113
Advanced Options
Aliases
Concatenation
Literals
Substitution Variables
Calculations
Set Operators
UNION INTERSECT
MINUS
Character Strings
Substring Instring
Data Type Conversions TO_DATE
TO_NUMBER
TO_CHAR Formats
UPPER
LOWER
NVL CASE
DECODE
ROUND
TRUNC
7/24/2019 1113 pl sql banner
31/38
31Course ID 1113
Practice 5: Aliases and Substitution Variables
Select most recent mailing address for a student.
SELECT s.spriden_id ID, a.*
FROM spriden s
JOIN spraddr aON s.spriden_pidm = a.spraddr_pidm
JOIN (select spraddr_pidm, spraddr_atyp_code,
MAX(spraddr_seqno) maxseq
FROM spraddrGROUP BY spraddr_pidm, spraddr_atyp_code) b
ON a.spraddr_pidm = b.spraddr_pidm
AND a.spraddr_atyp_code = b.spraddr_atyp_code
AND a.spraddr_seqno = b.maxseqWHERE spraddr_atyp_code = MA
AND spriden_id = :ID
AND spriden_change_ind IS NULL;
7/24/2019 1113 pl sql banner
32/38
32Course ID 1113
Practice 5: Concatenation and Literals
Select full name for all persons
SELECT spriden_first_name|| ||spriden_mi
|| ||spriden_last_name name
FROM spriden
WHERE spriden_id = :ID
AND spriden_change_ind IS NULL;
7/24/2019 1113 pl sql banner
33/38
33Course ID 1113
Practice 5: Format Using CASE
Select count of persons by gender description (Male,Female, or Unknown).
SELECT CASE WHEN spbpers_sex = F
THEN FemaleWHEN spbpers_sex = M
THEN Male
ELSE Unknown
END gender,
COUNT(spbpers_pidm) total
FROM spbpers
GROUP BY spbpers_sex;
7/24/2019 1113 pl sql banner
34/38
34Course ID 1113
Practice 5: Format Using NVL
Select all active addresses.
SELECT *
FROM spraddr
WHERE NVL(spraddr_status_ind, A) = A;
7/24/2019 1113 pl sql banner
35/38
35Course ID 1113
Exercises
Use Microsoft Access SQL editor to practice writingqueries against the sample tables
7/24/2019 1113 pl sql banner
36/38
36Course ID 1113
Learning More
Training
SQL*Plus user manuals
Online resources
View generated SQL
7/24/2019 1113 pl sql banner
37/38
37Course ID 1113
Questions and Answers
7/24/2019 1113 pl sql banner
38/38
38Course ID 1113
Thank You!
Jennifer Flagel
Please complete the online class evaluation form
Course ID 1113
SunGard, the SunGard logo, Banner, Campus Pipeline, Lumin is, PowerCAMPUS, Matrix , and Plus are trademarks or registeredtrademarks of SunGard Data Systems Inc. or its subsidiaries in the U.S. and other countries. Third-party names and marksreferenced herein are trademarks or registered trademarks of their respective owners.
2006 SunGard. All rights reserved.