• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Oracle: Basic SQL
 

Oracle: Basic SQL

on

  • 3,529 views

Oracle: Basic SQL

Oracle: Basic SQL

Statistics

Views

Total Views
3,529
Views on SlideShare
3,491
Embed Views
38

Actions

Likes
1
Downloads
0
Comments
0

3 Embeds 38

http://www.dataminingtools.net 22
http://dataminingtools.net 14
http://www.slideshare.net 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Oracle: Basic SQL Oracle: Basic SQL Presentation Transcript

    • 1
      Using ORACLE®
      Introduction to the ‘ SELECT ‘ clause and writing basic and advanced ‘SELECT ‘ statements using operators and literals
    • 2
      The “SELECT” statement
      In this tutorial we will learn about the ‘SELECT’ clause and how to write basic and advanced ‘SELECT’ statements by using literals and operators. The agenda for the presentation shall consist of:
      Introduction to “SELECT” clause (writing a basic ‘SELECT’ statement).
      Using the concatenation operator ,character string literals and Mathematical operators in SELECT statement.
      NULL values and alias names.
      Restriction and filtering data using comparison operators, logical operators pattern matching and sorting data.
    • 3
      Introduction to ‘SELECT’ statement
      ‘SELECT’ is an SQL keyword used to retrieve data from Oracle tables .SQL commands are not case
      sensitive and can be broken into multiple lines .
      The basic syntax for a ‘SELECT’ statement is: (Here the ‘SELECT’ and ‘FROM’ are keywords)
      SELECT The ‘SELECT’ clause identifies the columns to be retrieved
      */{
      [distinct] avoids duplicate copies of rows to be retrieved
      column_list / expression list of names of columns or expression to be selected
      [alias name]… name to be used to represent the column in display
      }
      FROM table name ; the ‘FROM’ clause identifies the table which contains the columns
      to be retrieved.
      Example:
      SELECT prod_name, prod_ID FROM product_master;
    • The concatenation operator is used to combine string literals and/or columns and displayed in the output. The concatenation operator is ‘ || ‘.
      The ‘AS’ keyword is used to specify the alias name that will represent the column in the output. We can specify the alias name using the ‘AS’ operator or just by entering the alias name after the column name separated by a space while writing the ‘SELECT’ statement.
      (if as ‘ ‘ the string literal contains ‘ character then use q’[ string literal ]’ between || operators)
      EXAMPLE :
      SELECT DISTINCT prod_ID || ‘ is the product ‘ || prod_name AS prod_description
      FROM product_master ;
      4
      The concatenation operator ( || ) and AS keyword.
    • Mathematical Operators
      5
      We can use mathematical operators to create expression in the ‘SELECT’ statement .
      The mathematical operators are :
      EXAMPLE:
      SELECT prod_name, prod_ID, prod_cost, prod_stock - prod_order AS stock_deficit , prod_sales * prod_cost AS sales_amt
      FROM product_master ;
    • Restricting and filtering data
      6
      In the previous ‘SELECT’ commands all the rows of the selected columns are displayed. We can restrict the rows that are displayed by using the ‘WHERE’ clause in combination with comparison operators and logical operators.
      The ‘WHERE’ clause follows the ‘FROM’ clause specifies the conditions a row should satisfy to be displayed in the output. We can use logical and comparison operators to create the expression in ‘WHERE’ clause. The operators are:
      LOGICAL OPERATORS
      COMPARISIN OPERATORS
    • EXAMPLES FOR COMPARISION OPERATORS
      7
      We shall see a few examples using the logical operators:
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_cost > 2000 AND prod_cost < 25000;
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_cost = 30000 ;
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_cost >= 2000 AND prod_cost <= 25000;
    • EXAMPLES FOR LOGICAL OPERATORS
      8
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_cost > 2000 AND prod_cost < 25000;
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_cost > 2000 OR prod_cost < 25000;
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE NOT (prod_cost =2000);
    • EXAMPLES FOR BETWEEN……AND……. CONDITION AND NULL CONDITION
      9
      THE BETWEEN…AND CONDITION:
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_cost BETWEEN 2000 AND 25000;
      lower limit upper limit
      (We use the BETWEEN …AND… condition to find rows containing values in the specified range )
      THE NULL CONDITION:
      SELECT *
      FROM product_master
      WHERE prod_sales IS NULL ;
      We use the IS NULL condition to find the rows containing NULL values for a particular column.
    • EXAMPLES FOR LIKE and IN CONDITION
      10
      THE LIKE CONDITION:
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHERE prod_name LIKE '%sofa' ;
      (We use the like condition when we wish to perform wildcard character pattern matching searches. In the above ‘LIKE’ condition we search for all products containing ‘sofa’ as the terminal characters and use the ‘%’ symbol which is a wildcard for multiple characters .The ‘_’ acts a a wildcard for a single character.)
      THE IN CONDITION:
      SELECT prod_ID,prod_name,prod_cost
      FROM product_master
      WHEREprod_IDIN (‘VF001’ , ’VF004’ , ’VF006’);
      (We use the IN condition when we wish to search for values belonging to a particular list that is specified after the IN keyword.)
    • OPERATOR PRECEDENCE
      11
      Importance of operators decreases
    • ORDER BY clause
      12
      The ‘ ORDER BY’ clause is use to display the rows matching the conditions in a ordered format either in ascending order (by using keyword ‘ASC’) or in the descending order (by using keyword ‘DESC’) with ascending being the default order.
      The rows are ordered according to the values in one or more specified rows.
      THE ORDER BY CLAUSE:
      SELECT *
      FROM product_master
      ORDER BY prod_cost ASC;
      SELECT *
      FROM product_master
      ORDER BY prod_cost DESC;
    • THANK YOU
      13
      THANK YOU FOR VIEWING THIS PRESENTATION
      FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,
      please visit:
      www.dataminingtools.net