Docsity

Oracle SQL: Commands, Functions, and Queries, Slides of Database Management Systems (DBMS)

Partial preview of the text

Download Oracle SQL: Commands, Functions, and Queries and more Slides Database Management Systems (DBMS) in PDF only on Docsity!

Oracle Structured Query

Language Examples

Basic SQL Commands

• SELECT

  • FROM
  • WHERE

Appendix

Creating a table

  • Create Table Inventory
    • (PackID Varchar2(4),
    • PackName Varchar2(20),
    • PackVer Number(3,2),
    • PackType Varchar2(15),
    • PackCost Number(5,2));
    • Note: Mark there is no comma after the last field/Column description

Appendix Docsity.com

Text Data Defined

  • Note: Oracle defines text data as follows:
  • Packid Varchar2(4)

Appendix

Null Constraints

  • Note: Null constraints can be entered as follows: - Quantity INTEGER NOT NULL - Order_Date DATE NOT NULL

Appendix

Primary Key Definition

Note: The primary key can be defined at table definition end as follows:

  • CONSTRAINT Inventory_PK PRIMARY KEY (PackID)
  • Notes: Inventory_PK is a arbitrary name assigned to the constraint. PackID is the name of the primary key field in the table.
  • Primary key can also be created as:
  • PackID varchar2[10] primary key Appendix

SQL Comparison Operators

  • = Equal to
  • Greater than

  • = Greater than or equal to

  • < Less than
  • <= Less than or equal to
  • <> Not equal to
  • != Not equal to

Appendix

Data Type Samples in SQL

  • Order_Date DATE
  • Last_Name VARCHAR2(18)
  • Quantity INTEGER
  • Amount Number(7,2)

Appendix

Data Query – Wild Card

• SELECT *

  • FROM Inventory;

Appendix

Data Query – Value Condition

  • SELECT EMP_Name
  • FROM Employee
  • WHERE Salary > 50000;

Appendix

Data Query – Text Condition

  • SELECT PackID, PackName
  • FROM Inventory
  • WHERE PackType = ‘Database’;

Appendix

Data Query – Compound Condition

  • SELECT PackName
  • FROM Inventory
  • WHERE PackType = ‘Database’
  • and PackCost > 400;

Appendix

Sorting Records – Single Field

• SELECT *

  • FROM Employee
  • ORDER BY Last_Name;
  • Note: The default order is ascending. Add DESC after the attribute to change the order to descending.

Appendix

Sorting Records – Compound Fields

• SELECT *

  • FROM Employee ORDER BY Last_Name, First_Name; Note: Indicate the major sort field first and then the minor sort field next with a comma between the fields.

Appendix