Week 7 March 8

advertisement
1
Week 7
March 8
• SQL: Chronological Sort, SUBSTRing, ROUND
• Dynamic SQL: Host and Lexical Reference
Variables
• Overview: Drill-down, Roll-up Reports
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
2
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Chronological sort
Month sequence in the calendar
3
Order by the
month’s sequence
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Without Chronological Order
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
4
Length
Beginning position
SUBSTR captures only parts of a string
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
5
Without SUBSTR
Wasted space
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
6
ROUND rounds a number to a
specified number of decimal places
7
Number of
decimal places
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Without ROUND
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
8
Order by Quarter
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
9
Dynamic SQL
10
• As opposed to static SQL, dynamic SQL allows the user to
specify parts of the query (i.e., column names, table
names, conditions, etc.) during runtime
• For example (static SQL):
SQL>
2
3
4
5
6
select manufacturer_code, to_char(sales_month_97,'q'),
sum(sales_revenue_97), sum(sales_revenue_98)
from sales_97_98
where lower(manufacturer_code) = 'son'
group by manufacturer_code, to_char(sales_month_97,'q')
order by to_char(sales_month_97,'q');
The same columns, table and condition are used
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Dynamic SQL
11
• With dynamic SQL, parts of the query can be substituted
by variable names
Lexical reference variable name
Host variable
Lexical reference variable designator
select manufacturer_code, &P_Time_interval,
sum(sales_revenue_97), sum(sales_revenue_98)
from sales_97_98
where lower(manufacturer_code) = :P_manufacturer_code
group by manufacturer_code, to_char(sales_month_97,'q')
order by &P_Time_interval;
Host variable designator
• During run time, the user will specify a value for
P_time_interval
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Creating a Lexical Reference Variable
• Create a lexical reference
variable under User
Parameters of the Data
Model (in the Object
Navigator)
Select

Create
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
12
Create a User Parameter
Default name
Select the new parameter, right-mouse
click and select Property Palette
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
13
Change the Properties
Change the name
Change the data type to character
Assign an initial value (optional)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
14
Insert the Lexical Reference Variables
(User Parameters)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
15
During Runtime...
Host variable
Lexical reference variables
(default values)
Host variable
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
16
Drill-Down, Roll-up Reports
• A drill-down report is actually two or more
reports working together
• The top-level report is like a master record
– Launches a report that provides more details
about the data in its current record
• Generally, the detail report displays information
related to the master
– Provides details for a single record, a group
of records, or the report as a whole
– Master report "links" to the detail report by
passing parameters that control the
execution of the detail
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
17
Master
Detail
Drill-Down Reports
Master Report
(Annual)
18
Data Model 1
Parameter-list1
Drill-down Report
(Quarters)
Data Model 2
Parameter-list2
Drill-down Report
(Months)
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
Data Model 2
19
+
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
+
=
Annual
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
20
Quarters
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
21
Months within a Quarter
R. Ching, Ph.D. • MIS Area • California State University, Sacramento
22
Download