help! i got a request for ansi sql what is it and what do you do with it? presenter: walter guerrero...
TRANSCRIPT
![Page 1: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/1.jpg)
Help! I got a request for ANSI SQL
What is it and what do you do with it?
Presenter: Walter Guerrero
Computer Associates Email: [email protected]
![Page 2: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/2.jpg)
Abstract
As companies deploy more XML and exchange information across many different database types, they will need to implement ISO standards within their business models.
SQL statements must then move away from proprietary format and fit within the ISO/ANSI standards. These ISO/ANSI standards provide a more readable and portable format that can be used by different database engines. Oracle is making the move for Oracle developers to start using ISO/ANSI SQL constructs in the creation of SQL statements to exchange data between XML style sheets. Even after changing the SQL statements into the ISO/ANSI format, developers still need to be concern with the performance needs of the SQL statements running in an Oracle database server.
![Page 3: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/3.jpg)
What is ANSI/ISO SQL
• ANSI and ISO SQL is the standard definition of SQL as agreed by these standards bodies
• ANSI and ISO SQL standards are the same
• If more information is desired, visit • http://www.cssinfo.com/ncitsgate.html
• http://www.iso.ch/
![Page 4: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/4.jpg)
Old Syntax Issues
• Non-standard implementations
• Lack of data modeling
• Lack of data structure processing
• Outer join implementations not standardized
![Page 5: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/5.jpg)
Benefits of ANSI/ISO SQL
• Portability of SQL code across different database engines
• Easier to read SQL statements
• National language support included
![Page 6: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/6.jpg)
Benefits Of ANSI/ISO SQL – Cont’d
• Standardize outer join implementations
• No need to use a UNION to complete an outer join process
![Page 7: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/7.jpg)
Outer Join Advanced Capabilities
• Database navigation
• Access Optimizations
• Data warehouse interaction
• Flexible aggregate operations usage
• Object relational interaction
• View update capability
• Multimedia directory support
![Page 8: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/8.jpg)
Why ANSI/ISO SQL
• Allows the Oracle SQL statements to become more portable and readable
• Information exchange between companies requires portable code
• This is very important for companies using XML, which uses SQLX or XSQL
![Page 9: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/9.jpg)
Oracle Supported ANSI/ISO Datatypes
• Character, char, nchar
• Varchar
• National
• Decimal, dec
• Integer, int
• Float
• Double, precision
• Real
![Page 10: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/10.jpg)
Basic ANSI/ISO SQL Keywords
• Inner
• Using
• Natural
• Left Outer – outer is optional
• Right Outer – outer is optional
• Full Outer – outer is optional
• Case
![Page 11: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/11.jpg)
Advanced ANSI/ISO SQL Keywords
• Siblings• Cross• When/then/else• Extract• Analytic functions• IS OF• Cast• First• Last
![Page 12: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/12.jpg)
Standard Oracle SQL Join Keywords
• =
• =(+)
• (+)=
• Full outer is made up of either =(+) or (+)= and an UNION to an equi-join
![Page 13: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/13.jpg)
Typical Oracle Statement
SELECT *
FROM employees e,
assignments a
WHERE e.emp_seq =
a.emp_seq
This is a typical inner
join using Oracle syntax
![Page 14: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/14.jpg)
Basic ANSI/ISO SQL Statement
SELECT *
FROM employees e JOIN
assignments a
ON e.emp_seq =
a.emp_seq;This is a typical
ANSI SQL inner join
![Page 15: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/15.jpg)
ANSI/ISO SQL “USING” Statement
SELECT *
FROM employees e JOIN
assignments a USING
(emp_seq);
![Page 16: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/16.jpg)
ANSI/ISO SQL “Natural” Statement
SELECT *
FROM employees e
NATURAL JOIN
assignments a;
![Page 17: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/17.jpg)
Oracle Syntax Outer Join
SELECT *
FROM employees e,
assignments a
WHERE e.emp_seq =
a.emp_seq(+)
![Page 18: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/18.jpg)
ANSI Syntax Left Outer Join
SELECT *
FROM employees e LEFT
OUTER JOIN assignments a
ON e.emp_seq = a.emp_seq
![Page 19: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/19.jpg)
ANSI Syntax Right Outer Join
SELECT *
FROM employees e RIGHT
OUTER JOIN assignments a
ON e.emp_seq = a.emp_seq
![Page 20: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/20.jpg)
Oracle Syntax Full Outer Join
SELECT e.emp_seq, p.proj_seq
FROM employees e, assignments a,
projects p
WHERE e.emp_seq = a.emp_seq(+)
AND a.proj_seq = p.proj_seq(+)
UNION ALL
SELECT null, p.proj_seq
FROM projects p, assignments a
WHERE p.proj_seq = a.proj_seq(+)
AND a.proj_seq IS NULL
![Page 21: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/21.jpg)
ANSI/ISO Syntax Full Outer Join
SELECT e.emp_seq, p.proj_seq
FROM (employees e LEFT
JOIN assignments a ON
e.emp_seq = a.emp_seq)
FULL JOIN projects p
ON a.proj_seq = p.proj_seq
![Page 22: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/22.jpg)
Oracle Decode Syntax
SELECT d.dept_seq, d.description,
decode(d.active,
'Y','Active',
'N','Not Active',
'Not Applicable')
FROM departments d
![Page 23: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/23.jpg)
ANSI/ISO CASE Syntax
SELECT d.dept_seq, d.description,
CASE active
WHEN 'Y' THEN 'Active'
WHEN 'N' THEN 'Not Active'
ELSE 'Not applicable' END
FROM departments d
![Page 24: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/24.jpg)
Oracle Inner Syntax Performance Example
SELECT *FROM employees e, assignments aWHERE e.emp_seq = a.emp_seq______________________________________
SELECT STATEMENT Cost = 17 HASH JOIN TABLE ACCESS FULL ASSIGNMENTS TABLE ACCESS FULL EMPLOYEES
![Page 25: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/25.jpg)
ANSI/ISO Inner Syntax Performance Example
SELECT * FROM employees e JOINassignments aON e.emp_seq = a.emp_seq;_________________________
SELECT STATEMENT Cost = 17 HASH JOIN TABLE ACCESS FULL ASSIGNMENTS TABLE ACCESS FULL EMPLOYEES
![Page 26: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/26.jpg)
Oracle Syntax Outer Join Performance Example
SELECT e.emp_seq, p.proj_seqFROM employees e, assignments a,projects pWHERE e.emp_seq = a.emp_seq(+)AND a.proj_seq = p.proj_seq(+)UNION ALLSELECT null, p.proj_seqFROM projects p, assignments aWHERE p.proj_seq = a.proj_seq(+)AND a.proj_seq IS NULL;_________________________________________________________SELECT STATEMENT Cost = 6 UNION-ALL NESTED LOOPS OUTER HASH JOIN OUTER INDEX FULL SCAN PK_EMP INDEX FULL SCAN PK_ASSIGN INDEX UNIQUE SCAN PK_PROJECTS FILTER HASH JOIN OUTER INDEX FULL SCAN PK_PROJECTS INDEX FULL SCAN PK_ASSIGN
![Page 27: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/27.jpg)
ANSI/ISO Syntax Outer Join Performance Example
SELECT e.emp_seq, p.proj_seqFROM (employees e LEFT JOIN assignments a ON e.emp_seq =
a.emp_seq)FULL JOIN projects pON a.proj_seq = p.proj_seq___________________________________________________
SELECT STATEMENT Cost = 4 VIEW UNION-ALL NESTED LOOPS OUTER HASH JOIN OUTER INDEX FULL SCAN PK_EMP INDEX FULL SCAN PK_ASSIGN INDEX UNIQUE SCAN PK_PROJECTS INDEX FULL SCAN PK_PROJECTS FILTER NESTED LOOPS OUTER INDEX FULL SCAN PK_EMP INDEX FULL SCAN PK_ASSIGN
![Page 28: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/28.jpg)
Performance Differences
• There are slight performance differences between Oracle and ANSI SQL syntaxes
• ANSI SQL provides you with improved readability
• ANSI SQL provides you with code portability across different database systems
![Page 29: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/29.jpg)
Summary
• Now that Oracle supports ANSI SQL 92 and parts of ANSI SQL 99, it is important to keep performance targets in mind
• Do performance analysis of your ANSI/ISO SQL during your development phase
• Use the CBO (Cost Based Optimizer) to your advantage
![Page 30: Help! I got a request for ANSI SQL What is it and what do you do with it? Presenter: Walter Guerrero Computer Associates Email: walter.guerrero@ca.comwalter.guerrero@ca.com](https://reader036.vdocument.in/reader036/viewer/2022062715/56649d845503460f94a6b7f6/html5/thumbnails/30.jpg)
Questions?