Upload
vokhanh
View
231
Download
1
Embed Size (px)
Citation preview
About Me …(Speaker Qualifications)
Karen Cannell ~ Principal
Analyzed, designed developed, converted, upgraded, enhanced and otherwise worked on database applications for 22+ years, focused on Oracle since 1994. Currently migrating business processes to web-based systems, leveraging the Oracle10g and 10g suite of tools. Lately APEX, Discoverer.
VOLUNTEER for IOUG, ODTUG, Oracle Magazine. ODTUG Technical Journal EditorVolunteer to author RMOUG, SELECT and ODTUG Journal Articles!!
Using APEX since the HTMLDB beginning
http://www.tunahuntress.com/oracle-application-express-apex/Software Page
Session Objectives
APEX IR from a BI perspective:
filtering, drills, charting, saved reports, downloads and resources required.
Where APEX IR do not measure up to BI Tools
Does it matter for your installation?
Impact of APEX 4.0 IR GROUP BY and Saved Reports
Reinforce APEX Best Practices
The Situation
Fixed # of Prepared Queries / Reports
Little to No Drilldown
Little to No Custom Reports
Reasonable Data Volumes
Expensive, Older-Version Business Objects License
Users Not Leveraging BI Features …
Use Does Not Justify Cost of BI Tool
Existing BI System:
Functional
Set Reports
No Drills
Do Exchange Reports, but not a lot
Costly
Retire License == $$
APEX Interactive Reports
Increase Ease of user, Options
Overall Needs
Simple, Intuitive Operation
Simple Maintenance
Tabular and Crosstab Reports
Specified formats
Linked (Cascading) Selection Parameters
Convert Some Forms & Reports w/Complex Parameter Selection
Save Custom Reports
Download Data – CSV, Print
BI Tools – Common Features
Select Columns
Tabular and Crosstab - Dynamic
Aggregates
Filtering
Grouping
Drills
Highlighting (Stop-lighting)
Multi Data Source
Downloads
Printing
Data Volumes
Plus the “BI Basics”
APEX Interactive Reports Features
Select Columns
Tabular & Crosstab# Formats
Aggregates
Filtering
Grouping #*
Drills #
Highlighting (Stop-lighting)
Single Data Source
Downloads
Printing
# - have to build
* - Help in APEX 4.0
Analysis and Considerations
User Data Needs
How Users Use Their Data
What They Tell You
What They Really Do
Current Query System
Their Feature Checklist
ResourcesManpower
License
Development & Maintenance Time
User Data Needs
Reporting vs. OLAP vs. Data Mining?
Fixed Result Sets vs. Custom Reports?
Fixed Formats?
Tabular ? Crosstab?
Aggregate? Details? Multi-Dimensional?
Analysis?
Drills? Pivots?
Data Volumes?
Downloads?
Analysis & Considerations
How Users Use Their Data
What They Tell You
What They Really Do
Volumes?
Formats?
Post-Report Activity?
Analysis & Considerations
“This is the data I need … “
“I import that into Excel and do … “
Current Query System
Major BI Vendor?
Legacy Tool?
Nothing?
How Much of That Tool is Used?
What is the Real Need?
Is it Free?
Analysis & Considerations
Current Query System – Our Case
Business Objects Web Intelligence
Established Set of Documents
Some Users Build Custom, Most Do Not
Drills Possible, Seldom Used
Mix of Tabular and Crosstab
Data Warehouse, supporting MViews
Download
Print in Tabular Format
Analysis & Considerations
Feature Checklist
Filtering
Parameters
Drills, Analysis, Pivoting
Aggregates, Analytical Functions
Formatting Options
Printing Options
Download Options
Analysis & Considerations
Feature Pros/Cons
Gain: All IR Features:
Select Columns
Filter
Sort
Break Highlight
Chart
Compute
Aggregate
Download
Reset
Help
Save
Feature Pros/Cons
Lose:
Build Own Report (from Scratch)
Auto Drill, Auto aggregates
Out-of-the-Box ROLAP, MOLAP (must build own)
True Dynamic Interactivity
True Analysis Features
Need to Build These In(or Do Without)
Resources Needed
License
Support
Manpower
Training
Enhancement Cost
Required In-House Knowledge
Analysis & Considerations
Requirements Considerations
Base Queries
Tabular
Crosstab
Dynamic Crosstab
Drills and Interactivity
Presentation Options
Charting Options
Download Options
Printing Options
Data Volumes
Data Sources
Analysis & Considerations
Our Project - Requirements
Feature Our Project
Base Queries 30
IR Features All
Drills None !
Presentation Tabular, Crosstab, Dynamic Crosstab
Charting None prepared
Download HTML, CSV
Printing CSV, Generic PDF
Data Volume Small - Moderate
Security Database Account
Development
Basic IR
Parameters (Pre-Filter)
Cascading LOV’s
Parameter NOT NULL Condition on Report
Crosstab QueriesKnown vs. Unknown Columns
Traditional SQL – Kyte – Not directly usable
11g PIVOT – easier queries, 11g Only
AMIS way – Dynamic crosstab
APEX Collections – Result Set to Coll, IR on the Coll
Drills
Performance - Tuning
Basic IR
All Standard APEX IR Features & Practices Apply
Select Features to be On/Off
Add Conditions, Authorizations As Needed for Levels of Privileges (Roles)
Condition on Report Region to Prevent Run before Parameters Selected
Development Considerations
Parameters
Allows for Pre-Filter
Reduce Volume of Result Set
Cascading LOV’s
APEXLib
Kubicek
Home Grown
APEX 4.0 – In There!
Whatever is Needed for Your Parameter Determination
Development Considerations
Crosstabs – Known Columns
Known Columns and Column Names
ex: Length by Month
vs
Unknown Columns and Column Names
ex: Month by Length
Length by Year
Length by Area
Standard APEX IR Needs Column Names
Crosstab Queries
Traditional SQL
MAX ( CASE or DECODE …) )CASE to filter values into columns
MAX to flatten the results
Need Known Columns
11g PIVOT and UNPIVOT
PIVOT
PIVOT … XML http://www.oracle.com/technology/pub/articles/oracle-
database-11g-top-features/11g-pivot.html
Development Considerations - Crosstabs
Crosstab Query Options, cont’d
PIVOT PL/SQL Package - Kyte
In Expert One on One
Dynamic SQL Pivoting - AMIS Solution
TYPE, TYPE BODY
Pipelined Table Function
http://technology.amis.nl/blog/1207/dynamic-sql-pivoting-stealing-antons-thunder
Development Considerations - Crosstabs
Traditional Crosstab Query
SELECT
agency,
area_code,
year,
MAX ( CASE WHEN miy = '01' THEN sum_landed_lbs ELSE NULL END) jan_landed_lbs,
MAX ( CASE WHEN miy = '02' THEN sum_landed_lbs ELSE NULL END) feb_landed_lbs,
MAX ( CASE WHEN miy = '03' THEN sum_landed_lbs ELSE NULL END) mar_landed_lbs,
MAX ( CASE WHEN miy = '04' THEN sum_landed_lbs ELSE NULL END) apr_landed_lbs,
MAX ( CASE WHEN miy = '05' THEN sum_landed_lbs ELSE NULL END) may_landed_lbs,
MAX ( CASE WHEN miy = '06' THEN sum_landed_lbs ELSE NULL END) jun_landed_lbs,
MAX ( CASE WHEN miy = '07' THEN sum_landed_lbs ELSE NULL END) jul_landed_lbs,
MAX ( CASE WHEN miy = '08' THEN sum_landed_lbs ELSE NULL END) aug_landed_lbs,
MAX ( CASE WHEN miy = '09' THEN sum_landed_lbs ELSE NULL END) sep_landed_lbs,
MAX ( CASE WHEN miy = '10' THEN sum_landed_lbs ELSE NULL END) oct_landed_lbs,
MAX ( CASE WHEN miy = '11' THEN sum_landed_lbs ELSE NULL END) nov_landed_lbs,
MAX ( CASE WHEN miy = '12' THEN sum_landed_lbs ELSE NULL END) dec_landed_lbs,
MAX ( CASE WHEN miy = '00' THEN sum_landed_lbs ELSE NULL END)
unk_landed_lbs,
MAX( sum_landed_lbs) yr_landed_lbs
FROM
(SELECT
partner.partner_name agency,
dep_landing.area_code,
time_period.year,
DECODE( time_period.month_in_year,'00','99', time_period.month_in_year) miy,
time_period.month,
SUM( dep_landing.landed_pounds) sum_landed_lbs
FROM
partner,
time_period,
dep_landing
WHERE
dep_landing.version_id = :P10_VERSION_ID
AND dep_landing.period_id = time_period.period_id
AND dep_landing.species_itis = '097314'
AND dep_landing.assessment_id = :P10_ASSESSMENT
AND dep_landing.data_source = PARTNER.partner_id
AND INSTR(':'||:P10_PARTNER||':',':'||PARTNER.partner_id||':') > 0
AND time_period.year BETWEEN :P10_START_YEAR AND :P10_END_YEAR
GROUP BY
ROLLUP( partner.partner_name,
time_period.year,
dep_landing.area_code,
DECODE( time_period.month_in_year,'00','99', time_period.month_in_year),
time_period.month
)
)
WHERE area_code IS NOT NULL AND year IS NOT NULL
GROUP BY agency, area_code, year
ORDER BY agency, area_code, year;
Development - Crosstab Options
SELECT
agency,
area_code,
year,
MAX ( CASE WHEN miy = '01' THEN sum_landed_lbs ELSE NULL END) jan_landed_lbs,
MAX ( CASE WHEN miy = '02' THEN sum_landed_lbs ELSE NULL END) feb_landed_lbs,
MAX ( CASE WHEN miy = '03' THEN sum_landed_lbs ELSE NULL END) mar_landed_lbs,
MAX ( CASE WHEN miy = '04' THEN sum_landed_lbs ELSE NULL END) apr_landed_lbs,
MAX ( CASE WHEN miy = '05' THEN sum_landed_lbs ELSE NULL END) may_landed_lbs,
… …
Known Columns Only
Traditional Crosstab Query
Development - Crosstab Options
PL/SQL PIVOT_PKG
Per Kyte, Expert One on One
Procedure that Returns REFCURSOR
Function that Returns SQL Query
Works for Unknown Columns
BUT
APEX IR is from SQL Query Only –
Does NOT Allow IR Create from Function Returning Query
Development Crosstab Options
PIVOT_Q Function - Returns Query
FUNCTION PIVOT_Q (
p_max_cols IN NUMBER DEFAULT NULL,
p_max_cols_query IN VARCHAR2 DEFAULT NULL,
p_query IN VARCHAR2,
p_anchor IN ARRAY_TT,
p_pivot IN ARRAY_TT) RETURN VARCHAR2 AS
l_max_cols NUMBER;
l_query LONG;
l_cnames ARRAY_T;
BEGIN
/*
per Tom Kyte Expert One on One
*/
-- figure # of columns we need
-- we either know this or have a query to figure it out
IF (p_max_cols IS NOT NULL ) THEN
l_max_cols := p_max_cols;
ELSIF (p_max_cols_query IS NOT NULL) THEN
EXECUTE IMMEDIATE p_max_cols_query INTO l_max_cols;
ELSE
RAISE_APPLICATION_ERROR( -20001, 'PIVOT_PKG ERROR: Cannot determine MAX columns needed.');
END IF;
-- now construct query that can answer querstion for us
-- start with Cq, C2, ... CX coluns
l_query := 'SELECT ';
FOR i IN 1 .. p_anchor.COUNT LOOP
l_query := l_query||p_anchor(i)||', ';
END LOOP;
-- now add columns to be pivoted
-- using format MAX(DECODE( rn, 1, c(x+1), null)) cx+1_1
FOR i IN 1 .. l_max_cols LOOP
FOR j IN 1 .. p_pivot.COUNT LOOP
l_query := l_query ||
'MAX( DECODE( rn, '||i||','||
p_pivot(j)||', NULL)) '||
p_pivot(j)||'_'|| i||', ';
END LOOP;
END LOOP;
-- now add the original query
l_query := RTRIM( l_query,', ')|| ' FROM ('|| p_query||') GROUP BY ';
-- and then the GROUP BY columns
FOR i IN 1 .. p_anchor.COUNT LOOP
l_query := l_query|| p_anchor(i)||',';
END LOOP;
l_query := RTRIM( l_query,',');
RETURN l_query;
END PIVOT_Q;
So …. Plan B for Dynamic Crosstab
Create Collection
SQL Query on the Collection
Condition on the C-C Process, so it doesn’t Recreate
Conditions on the Columns, so Display Only When Data
Column Header Items and Process to Load Header Items
May Not Have Column Names in IR Activity Menu!!
Development - Crosstab Method
Items for Column Headers
Create Item for Each Column
Name Each Column
Apply Display
Condition on Each
Column
Development - Crosstab Method
Process to Load Header Items
Manually Name Column Headers
Manually Apply Display Condition
or
Process to Load Header Items
or
Custom Pl/SQL Procedure to Programmatically Build Items, Names, Conditions ?
Development - Crosstab Method
Dynamic Pivot - Drawbacks
Tedious – C001 – C050
Un-Named Column Headers Don’t Show in Select Cols
Build Crosstabs w/Known or Predictable Column Headers
Development - Crosstab Options
ROLLUP, CUBE, GROUPING SET
All These Valid in SQL Query
Will NOT Have Inherent BI Behavior in an APEX IR
No “Automatic” Drill Levels
No Auto Aggregates
Aim for Known Column Headers, or Dynamic Column Work Necessary
Development Considerations
APEX IR Aggregate Behavior
Original Report Display
Region: West************State County City PopulationCA Orange County Irvine 100CA Orange County Orange 200CA Los Angeles Hollywood 300CA Los Angeles Universal City 400
Sum 1,000
Actual APEX IR ResultRegion: West************State County PopulationCA Orange County 100CA Orange County 200CA Los Angeles 300CA Los Angeles 400
Sum 1,000
Intended ResultRegion: West************State County PopulationCA Orange County 300CA Los Angeles 700
Sum 1,000
Know Your UsersInform Your Users
X
11g PIVOT and UNPIVOT
PIVOTselect * from ( select times_purchased, state_code from customers t )
pivot ( count(state_code) for state_code in ('NY','CT','NJ','FL','MO') ) order by times_purchased /
PIVOT XML … IN ( ANY) … for Unknown Column Values
Not Directly Useable c/o XML Dataselect * from ( select times_purchased as "Purchase Frequency", state_code from
customers t ) pivot xml ( count(state_code) for state_code in (any) ) order by 1
Development - Crosstab Options
11g PIVOT Operator
SELECT *
FROM
(
SELECT stock_name||'('||stock_short_name||')' stock,
sex.sex_description,
time_period.year,
dep_final_number_landed.area_code,
time_period.month_in_year,
---dep_final_number_landed.avg_weight,
SUM( dep_final_number_landed.number_caught) nbr_caught
FROM
sex,
stock_area,
stock_group,
dep_final_number_landed,
time_period
WHERE
--- dep_final_number_landed.version_id = version.version_id
dep_final_number_landed.version_id = 67
AND time_period.period_id = dep_final_number_landed.period_id
AND sex.sex = dep_final_numbeR_landed.sex
AND dep_final_number_landed.assessment_id = 944 ---:P90_ASSESSMENT
AND stock_group.assessment_id = dep_final_number_landed.assessment_id
AND dep_final_number_landed.species_itis = '097314'
AND stock_group.stock_id = stock_area.stock_id
AND stock_Area.stock_id = 2
GROUP BY
ROLLUP ( stock_name||'('||stock_short_name||')',
sex.sex_description,
time_period.year,
dep_final_number_landed.area_code,
time_period.month_in_year)
ORDER BY
stock_name||'('||stock_short_name||')',
sex.sex_description,
dep_final_number_landed.area_code,
time_period.year,
time_period.month_in_year )
PIVOT (
SUM( nbr_caught) FOR month_in_year IN ( '01' AS JAN, '02' AS FEB, '03' AS MAR, '04' AS APR, '05' AS MAY, '06' AS JUN, '07' AS JUL, '08' AS AUG, '09' AS SEP, '10' AS OCT, '11' AS NOV, '12' AS DEC, '00' AS UNK) )
ORDER BY stock,
sex_description,
area_code,
year;
Named Columns
11g PIVOT vs. PIVOT XML
SELECT *
FROM
( …big long query … )
PIVOT (
SUM( nbr_caught) FOR month_in_year
IN ( '01' AS JAN, '02' AS FEB, '03' AS MAR, '04' AS APR, '05' AS MAY, '06' AS JUN, '07' AS JUL, '08' AS AUG, '09' AS SEP, '10' AS OCT, '11' AS NOV, '12' AS DEC, '00' AS UNK) )
ORDER .BY …
SELECT *
FROM
( …big long query … )
PIVOT XML (
SUM( nbr_caught) FOR month_in_year
IN ( SELECT DISTINCT month_in_year FROM time_periods)
)
ORDER .BY …
Un-Named
Columns
Named Columns
11g PIVOT XML … ANY
SELECT *
FROM
( …big long query … )
PIVOT XML (
SUM( nbr_caught) FOR month_in_year
IN ( SELECT DISTINCT month_in_year FROM time_periods)
)
ORDER .BY …
SELECT *
FROM
( …big long query … )
PIVOT XML (
SUM( nbr_caught) FOR month_in_year
IN ( ANY )
)
ORDER .BY …
Un-Named
Columns
Un-Named
Columns
On Using PIVOT XML FOR … (ANY)
Loss of Named
Columns!
MONTH_IN_YEAR_XML_OTHER
Unsupported Data Type in IR
PivotImpl Method
Does Not Require Hard-Code of all Column Values
Object Type and Pipelined Function
http://technology.amis.nl/blog/1207/dynamic-sql-pivoting-stealing-antons-thunder
IR Not Liking It – Will Need Work
Collection workaround May Not required
Column Header workaround MAY be required
Development - Crosstab Options
PivotImpl SQL Query Results
SELECT *
FROM TABLE( PIVOT(' SELECT deptno, job, AVG( sal) sal_avg
FROM emp
GROUP BY deptno, job
')
)
/
DEPTNO ANALYST CLERK MANAGER PRESIDENT SALESMAN WIZARD
-------- ---------- ---------- ---------- ---------- ---------- ----------
30 950 2850 1400
20 3000 950 2975
40 1100
10 1300 2450 5000 1991
Drills
APEX Drill-Down Report
From Summary to Detail
Add Link From Summary to Detail Report
Feature Considerations - Drills
Drills - Considerations
Use IR_COLUMN_NAME for the Link
(Instead of Hidden Page or Region Items)
Allow Manual RESET
or
Automatic Way to Clear Hidden Items
Plan – Plan - Plan
Feature Considerations - Drills
Drills
Build Parent Report
Build Child Report
Build Link in Parent to Child, Passing Parameters
Must Build Each One
Alt: APEX 4.0 GROUP BY – Not Quite It.
Feature Considerations - Drills
Download / Print Options
HTML
Excel
PDFMust Configure PDF Output
(FOP or BI Publisher)
Generic
BI Publisher
XLS
RTF
APEX 4.0:
Email – Allows Sharing Results
Download Options
Generic – Beware Column Widths
BI Publisher
Requires Configuration
XLS
RTF (Word)
Requires Configuration
Email – APEX 4.0
Feature Considerations - Download/Print Options
All Configuration Same As All APEX IR
Charting Options
Out of IR – Full APEX Charting
Supplement the IR
From IR - User-Driven
Simple Charts – NOT Complex Charting
Display Chart OR Report
Chart on Base Data – NOT on GROUP BY Display
APEX 4.0 – More Intuitive
Feature Considerations - Charting
Performance & Tuning
Do It For Every Query
All the Usual Tuning Methods Apply
Tune Query Outside of APEX
Materialized Views
CUBEs, ROLLUP
As Needed to Support Desired Display and Performance
Feature Considerations - Performance
Data Volumes
How Much to “Display” on One Page?
Does one Need “All the Data” On One Screen?
Do They Run the Report, then Download Everything?
Break That Habit
Filter Filter Filter
Feature Considerations - Performance
Training and Documentation
Same as Required for APEX Application
Minimal Compared to Full BI Tool
Feature Considerations - Training
Where APEX Falls Short
Drills – Have to Build Them
Interactive Analysis – No Pivot, Dynamic Analysis
AJAX Performance w/Data Volume (slow cascading LOV)
Dynamic Crosstab
Dynamic Pivot
Analysis Features
NOT a BI Tool!
You Want These,You Build ‘em
APEX 4.0 Improvements
Cascading LOV’s
GROUP BY Option
Public Saved Reports
Alternate Default Reports – Up to 5
Email Download Option – Sharing Result Sets
Notify – Email Report on Set Intervals
IR GROUP BY
GROUP BY Select Columns
Separate Tab for Grouped Data
User Selects Groupings
4.0 Feature
APEX 4.0 IR GROUP BY
Action Menu Option
Up to 3 Columns
Up to 3 Functions (Sum, Avg, Max/Min, Median)
Up to 3 Sorts
Easy User-Driven Grouping Option
Side-by-Side Instead of Drill
APEX 4.0 Saved Reports
Adds Flexibility to Report Strategy
Multiple Views of Same Data
Convenience
Alternate Default Reports
Saved Public Reports
Reports Select List to Access
Overall Results
Resources Setup, Learning Curve
License, Support Costs
In-House Maintenance
Functionality Loss of Built-In Drill
Crosstabs (Must Pre-Build)
Sharing Reports (pre 4.0)
Ease of Use
User Satisfaction
Overall
Not For Everyone!
Multiple Data Sources
Disparate Data Sources
Consolidate first if Possible
Active Analytical Users
Formatted Report Layouts ( w/o BI Publisher)
Side-by-Side Data and Chart
Large Data Volumes
If These are Essential, Shop Elsewhere
What Works
Interactive Reports Flexibility
Menus
Parameter Selection
Generic Printing
No License, Support Cost
Ease of Use
What Doesn’t …
NOT for Unlimited Crosstab
Must Build, Could be Complex
NOT for Unlimited Drills
Must Build Each One
NOT for Advanced BI Functionality
None, UNLESS You Build It
NOT for Fancy Layouts
BI Publisher or XSL-FO for Formatted Reports
NOT Data Mining
Lessons Learned
Know What Your Users Need
Create Core Queries to Suit User Needs
Plan Queries – Plan Layouts
Plan Supporting Structures for Queries
Know Your Data, How to Present It
Plan Download/Printing Approach
Know What Users Really Do With Data
Closing …. Your Call
What Works
Is it enough?
What Doesn’t
Does it Matter?
Lessons Learned
Get clever w/SQL, PL/SQL
Proper Supporting Structures
Good Planning Know Your UsersKnow What Users Really Do
With Data
Resources
Best Source of APEX Help
http://forums.oracle.com/forums/forum.jspa?forumID=137
Cross Tab Query, Tom Kytehttp://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:7086279
412131
Creating a Crosstab Report, Mike Ault
http://www.dba-oracle.com/oracle_tips_crosstab_sql.htm
Pivot and Crosstab Queries, Robert Vollmanhttp://thinkoracle.blogspot.com/search?q=pivot+query
Enhanced Aggregation, Cube, Grouping and Rollup (OLAP Reporting Embedded in SQL) Shouvik Basu
http://www.orafaq.com/node/56
Resources, cont’d
AMIS PivotImpl Series
http://technology.amis.nl/blog/1197/pivot-dynamic-data
http://technology.amis.nl/blog/1207/dynamic-sql-pivoting-stealing-antons-thunder
APEX Tutorial – Drill Down Report
http://download.oracle.com/docs/cd/E14373_01/appdev.32/e13363/rprt_drill.htm#CIHGBADI
Share Your Knowledge!
ODTUG Journal IOUG SELECT Journal
Call for Articles/Reviewers
Editor, ODTUG Technical [email protected]
Migration:
BI to APEX
Karen [email protected]
http://www.integratc.com
Questions ?
Please fill out the evaluations!
Migration: BI to APEX ?
http://www.tunahuntress.com
Software page
Karen Cannell
Thank You ~
Please fill out the evaluations!
Karen Cannell – APEX Papers
http://www.tunahuntress.com
Software Page(http://www.tunahuntress.com/oracle-application-express-apex/)
or
http://www.thtechnology.com