1 / 17

CS422 Principles of Database Systems Oracle SQL

CS422 Principles of Database Systems Oracle SQL. Chengyu Sun California State University, Los Angeles. Structured Query Language (SQL). Data Definition Language ( DDL ) CREATE , DROP , ALTER Data Manipulation Language ( DML ) SELECT , INSERT , DELETE , UPDATE

roakley
Télécharger la présentation

CS422 Principles of Database Systems Oracle SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS422 Principles of Database SystemsOracle SQL Chengyu Sun California State University, Los Angeles

  2. Structured Query Language (SQL) • Data Definition Language (DDL) • CREATE, DROP, ALTER • Data Manipulation Language (DML) • SELECT, INSERT, DELETE, UPDATE • Data Control Language (DCL) • GRANT, REVOKE • COMMIT, ROLLBACK, SAVEPOINT

  3. Sample Schema Products( product_id, category, description, price ) Customers( customer_id, first_name, last_name, address ) Order( order_id, customer_id, date_ordered, date_shipped ) Order_Details( order_id, product_id, quantity )

  4. Constraints • Column and table constraints • Constraints w/o names • Use ALTER statement to add or remove constraints

  5. Sequence, Index, and View • Sequence • MINVALUE, MAXVALUE • nextval, currval • Index • UNIQUE • Function-based index • View • CREATE OR REPLACE VIEW

  6. SELECT LIKE, REGEXP_LIKE BETWEEN IN IS NULL DISTINCT ORDER BY dual Joins INNER JOIN OUTER JOIN LEFT RIGHT FULL (+) Simple Selections

  7. Query Results • Column alias • w/o AS • Use double quotes to preserve case and white spaces • Concatenate columns with || • SQL*Plus • COLUMNcolumn_nameFORMAT • column description format a16 • column price format 9999.9

  8. Date and Time • Default date format: DD-MMM-YYYY • TO_DATE( x [, format] ) • TO_CHAR( x [, format] ) • EXTRACT • INTERVAL

  9. Aggregation functions COUNT, SUM, MAX, MIN AVG, MEDIAN VARIANCE, STDDEV GROUP BY HAVING Aggregation Queries

  10. Set Operations • UNION, UNION ALL • INTERSECT • MINUS

  11. Subqueries • Subquery that returns • Scalar • Relation • Correlated subquery

  12. CASE: switch style SELECT product_id, CASE category WHEN ‘MB’ THEN ‘Motherboard’ WHEN ‘CPU’ THEN ‘Processor’ ELSE ‘ERROR!’ END FROM products;

  13. CASE: if-else style SELECT product_id, CASE WHEN Price > 200 THEN ‘Expensive’ ELSE ‘Cheap’ END FROM products;

  14. Transactions • COMMIT • ROLLBACK • SAVEPOINT and ROLLBACK TO SAVEPOINT

  15. Start and End of A Transaction • Start • First DML statement after connection or the end of last transaction • End • First DDL or DCL statement (except SAVEPOINT) after a transaction starts • Failed DML statements are automatically rolled back • Disconnect

  16. Advanced Topics • Transaction Isolation Level • Recursive queries • Stored procedures and triggers • Objects and collections • Analytic functions • LOB and full text search • XML data

  17. Exercises • Read about the Human Resources (HR) sample schema in Oracle Documentation at http://sun.calstatela.edu/~cysun/documentation/oracle/server.101/b10771/toc.htm. You’ll use this schema for Lab 1.

More Related