SlideShare uma empresa Scribd logo
1 de 33
1
 Writing Basic
SQL Statements
Objectives

After completing this lesson, you should
be able to do the following:
  • List the capabilities of SQL SELECT
    statements
  • Execute a basic SELECT statement
  • Differentiate between SQL statements
    and SQL*Plus commands



1-2
Capabilities of SQL SELECT
              Statements
      Selection          Projection




      Table 1            Table 1
                  Join




      Table 1            Table 2
1-3
Basic SELECT Statement

 SELECT     [DISTINCT] {*, column [alias],...}
 FROM       table;




      • SELECT identifies what columns.
      • FROM identifies which table.




1-4
Writing SQL Statements

  • SQL statements are not case sensitive.
  • SQL statements can be on one or
    more lines.
  • Keywords cannot be abbreviated or split
    across lines.
  • Clauses are usually placed on separate
    lines.
  • Tabs and indents are used to enhance
    readability.
1-5
Selecting All Columns

 SQL> SELECT *
   2 FROM    dept;


    DEPTNO   DNAME            LOC
 ---------   --------------   -------------
        10   ACCOUNTING       NEW YORK
        20   RESEARCH         DALLAS
        30   SALES            CHICAGO
        40   OPERATIONS       BOSTON




1-6
Selecting Specific Columns

 SQL> SELECT deptno, loc
   2 FROM    dept;


    DEPTNO   LOC
 ---------   -------------
        10   NEW YORK
        20   DALLAS
        30   CHICAGO
        40   BOSTON




1-7
Column Heading Defaults

  • Default justification
      – Left: Date and character data
      – Right: Numeric data
  • Default display: Uppercase




1-8
Arithmetic Expressions

Create expressions on NUMBER and DATE
data by using arithmetic operators.

      Operator   Description

         +       Add

          -      Subtract

          *      Multiply

         /       Divide




1-9
Using Arithmetic Operators

 SQL> SELECT ename, sal, sal+300
   2 FROM    emp;


ENAME            SAL   SAL+300
---------- --------- ---------
KING            5000      5300
BLAKE           2850      3150
CLARK           2450      2750
JONES           2975      3275
MARTIN          1250      1550
ALLEN           1600      1900
...
14 rows selected.



1-10
Operator Precedence

                    / +      _
               *
  • Multiplication and division take priority
    over addition and subtraction.
  • Operators of the same priority are
    evaluated from left to right.
  • Parentheses are used to force
    prioritized evaluation and to clarify
    statements.

1-11
Operator Precedence

 SQL> SELECT ename, sal, 12*sal+100
   2 FROM    emp;


 ENAME            SAL 12*SAL+100
 ---------- --------- ----------
 KING            5000      60100
 BLAKE           2850      34300
 CLARK           2450      29500
 JONES           2975      35800
 MARTIN          1250      15100
 ALLEN           1600      19300
 ...
 14 rows selected.



1-12
Using Parentheses

SQL> SELECT ename, sal, 12*(sal+100)
  2 FROM    emp;


ENAME            SAL 12*(SAL+100)
---------- --------- -----------
KING            5000       61200
BLAKE           2850       35400
CLARK           2450       30600
JONES           2975       36900
MARTIN          1250       16200
...
14 rows selected.




1-13
Defining a Null Value
  • A null is a value that is unavailable,
    unassigned, unknown, or inapplicable.
  • A null is not the same as zero or a blank
    space.
 SQL> SELECT   ename, job, comm
   2 FROM      emp;

 ENAME      JOB            COMM
 ---------- --------- ---------
 KING       PRESIDENT
 BLAKE      MANAGER
 ...
 TURNER     SALESMAN          0
 ...
 14 rows selected.
1-14
Null Values
       in Arithmetic Expressions
  Arithmetic expressions containing a null
  value evaluate to null.

SQL> select ename, 12*sal+comm
  2 from    emp
  3 WHERE ename='KING';



ENAME      12*SAL+COMM
---------- -----------
KING



1-15
Defining a Column Alias

  • Renames a column heading
  • Is useful with calculations
  • Immediately follows column name;
    optional AS keyword between column
    name and alias
  • Requires double quotation marks if it
    contains spaces or special characters
    or is case sensitive

1-16
Using Column Aliases
 SQL> SELECT ename AS name, sal salary
   2 FROM    emp;


  NAME            SALARY
  ------------- ---------
  ...


 SQL> SELECT ename "Name",
   2         sal*12 "Annual Salary"
   3 FROM    emp;


  Name         Annual Salary
  ------------- -------------
  ...

1-17
Concatenation Operator

  • Concatenates columns or character
    strings to other columns
  • Is represented by two vertical bars (||)
  • Creates a resultant column that is a
    character expression




1-18
Using the Concatenation
               Operator
  SQL> SELECT   ename||job AS "Employees"
    2 FROM      emp;


  Employees
  -------------------
  KINGPRESIDENT
  BLAKEMANAGER
  CLARKMANAGER
  JONESMANAGER
  MARTINSALESMAN
  ALLENSALESMAN
  ...
  14 rows selected.


1-19
Literal Character Strings

  • A literal is a character, expression, or
    number included in the SELECT list.
  • Date and character literal values must
    be enclosed within single quotation
    marks.
  • Each character string is output once for
    each row returned.



1-20
Using Literal Character Strings

 SQL> SELECT ename ||' '||'is a'||' '||job
   2               AS "Employee Details"
   3 FROM    emp;


 Employee Details
 -------------------------
 KING is a PRESIDENT
 BLAKE is a MANAGER
 CLARK is a MANAGER
 JONES is a MANAGER
 MARTIN is a SALESMAN
 ...
 14 rows selected.



1-21
Duplicate Rows
The default display of queries is all rows,
including duplicate rows.
  SQL> SELECT deptno
    2 FROM    emp;


     DEPTNO
  ---------
         10
         30
         10
         20
  ...
  14 rows selected.


1-22
Eliminating Duplicate Rows
Eliminate duplicate rows by using the
DISTINCT keyword in the SELECT clause.
 SQL> SELECT DISTINCT deptno
   2 FROM    emp;


    DEPTNO
 ---------
        10
        20
        30




1-23
SQL and SQL*Plus Interaction
       SQL Statements                  SQL Statements
                          Buffer


                                                     Server
SQL*Plus




          SQL*Plus                   Query Results
          Commands
                  Formatted Report


1-24
SQL Statements Versus
         SQL*Plus Commands
SQL                        SQL*Plus
 • A language               • An environment
 • ANSI standard            • Oracle proprietary
 • Keyword cannot be        • Keywords can be
   abbreviated                abbreviated
 • Statements manipulate    • Commands do not
   data and table             allow manipulation of
   definitions in the         values in the database
   database

    SQL          SQL        SQL*Plus       SQL*Plus
statements      buffer     commands         buffer


 1-25
Overview of SQL*Plus
 • Log in to SQL*Plus.
 • Describe the table structure.
 • Edit your SQL statement.
 • Execute SQL from SQL*Plus.
 • Save SQL statements to files and
   append SQL statements to files.
 • Execute saved files.
 • Load commands from file to buffer
   to edit.
1-26
Logging In to SQL*Plus
  • From Windows environment:




  • From command line:
     sqlplus [username[/password
             [@database]]]
1-27
Displaying Table Structure

Use the SQL*Plus DESCRIBE command to
display the structure of a table.
 DESC[RIBE] tablename




1-28
Displaying Table Structure

  SQL> DESCRIBE dept


   Name              Null?      Type
   ----------------- --------   ------------
   DEPTNO            NOT NULL   NUMBER(2)
   DNAME                        VARCHAR2(14)
   LOC                          VARCHAR2(13)




1-29
SQL*Plus Editing Commands

 • A[PPEND] text
 • C[HANGE] / old / new
 • C[HANGE] / text /
 • CL[EAR] BUFF[ER]
 • DEL
 • DEL n
 • DEL m n

1-30
SQL*Plus Editing Commands
  • I[NPUT]
  • I[NPUT] text
  • L[IST]
  • L[IST] n
  • L[IST] m n
  • R[UN]
  •n
  • n text
  • 0 text
1-31
SQL*Plus File Commands

  • SAVE filename
  • GET filename
  • START filename
  • @ filename
  • EDIT filename
  • SPOOL filename



1-32
Summary

 SELECT   [DISTINCT] {*,column [alias],...}
 FROM     table;



Use SQL*Plus as an environment to:
  • Execute SQL statements
  • Edit SQL statements




1-33

Mais conteúdo relacionado

Mais procurados

Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tablessiavosh kaviani
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?Andrej Pashchenko
 
Les01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL StatementsLes01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL Statementssiavosh kaviani
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02Angel G Diaz
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorialGiuseppe Maxia
 
Les09[1]Manipulating Data
Les09[1]Manipulating DataLes09[1]Manipulating Data
Les09[1]Manipulating Datasiavosh kaviani
 
Les22[1]Advanced Explicit Cursor Concepts
Les22[1]Advanced Explicit Cursor ConceptsLes22[1]Advanced Explicit Cursor Concepts
Les22[1]Advanced Explicit Cursor Conceptssiavosh kaviani
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQLsuriyae1
 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Datasiavosh kaviani
 
Les16[1]Declaring Variables
Les16[1]Declaring VariablesLes16[1]Declaring Variables
Les16[1]Declaring Variablessiavosh kaviani
 
Les08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*PlusLes08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*Plussiavosh kaviani
 
Database Management System
Database Management SystemDatabase Management System
Database Management SystemHitesh Mohapatra
 

Mais procurados (20)

Les12[1]Creating Views
Les12[1]Creating ViewsLes12[1]Creating Views
Les12[1]Creating Views
 
Sqlplus
SqlplusSqlplus
Sqlplus
 
Les10[1]Creating and Managing Tables
Les10[1]Creating and Managing TablesLes10[1]Creating and Managing Tables
Les10[1]Creating and Managing Tables
 
Best sql plsql material
Best sql plsql materialBest sql plsql material
Best sql plsql material
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?SQL Macros - Game Changing Feature for SQL Developers?
SQL Macros - Game Changing Feature for SQL Developers?
 
Les01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL StatementsLes01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL Statements
 
Les06[1]Subqueries
Les06[1]SubqueriesLes06[1]Subqueries
Les06[1]Subqueries
 
Les02
Les02Les02
Les02
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
 
Mysql rab2-student
Mysql rab2-studentMysql rab2-student
Mysql rab2-student
 
MySQL partitions tutorial
MySQL partitions tutorialMySQL partitions tutorial
MySQL partitions tutorial
 
Les09[1]Manipulating Data
Les09[1]Manipulating DataLes09[1]Manipulating Data
Les09[1]Manipulating Data
 
Les12 creating views
Les12 creating viewsLes12 creating views
Les12 creating views
 
Les22[1]Advanced Explicit Cursor Concepts
Les22[1]Advanced Explicit Cursor ConceptsLes22[1]Advanced Explicit Cursor Concepts
Les22[1]Advanced Explicit Cursor Concepts
 
Oracle SQL AND PL/SQL
Oracle SQL AND PL/SQLOracle SQL AND PL/SQL
Oracle SQL AND PL/SQL
 
Les02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting DataLes02[1]Restricting and Sorting Data
Les02[1]Restricting and Sorting Data
 
Les16[1]Declaring Variables
Les16[1]Declaring VariablesLes16[1]Declaring Variables
Les16[1]Declaring Variables
 
Les08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*PlusLes08[1] Producing Readable Output with SQL*Plus
Les08[1] Producing Readable Output with SQL*Plus
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 

Destaque

Network assessment
Network assessmentNetwork assessment
Network assessmentBeth Kanter
 
Lesson 01 - Network Assessment
Lesson 01 - Network AssessmentLesson 01 - Network Assessment
Lesson 01 - Network AssessmentAngel G Diaz
 
CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4Nil Menon
 
CCNA Exam 200-120 pdf
CCNA Exam 200-120 pdfCCNA Exam 200-120 pdf
CCNA Exam 200-120 pdfMadhan Banda
 
How to configure vlan, stp, dtp step by step guide
How to configure vlan, stp, dtp step by step guideHow to configure vlan, stp, dtp step by step guide
How to configure vlan, stp, dtp step by step guideIT Tech
 
CCNA Router Startup and Configuration
CCNA Router Startup and ConfigurationCCNA Router Startup and Configuration
CCNA Router Startup and ConfigurationDsunte Wilson
 
Lab practice 1 configuring basic routing and switching (with answer)
Lab practice 1   configuring basic routing and switching (with answer) Lab practice 1   configuring basic routing and switching (with answer)
Lab practice 1 configuring basic routing and switching (with answer) Arz Sy
 
CCNA Routing Protocols
CCNA Routing ProtocolsCCNA Routing Protocols
CCNA Routing ProtocolsDsunte Wilson
 

Destaque (12)

Assessing network security
Assessing network securityAssessing network security
Assessing network security
 
Network assessment
Network assessmentNetwork assessment
Network assessment
 
Lesson 01 - Network Assessment
Lesson 01 - Network AssessmentLesson 01 - Network Assessment
Lesson 01 - Network Assessment
 
The Complete Guide to Assessments
The Complete Guide to AssessmentsThe Complete Guide to Assessments
The Complete Guide to Assessments
 
Router commands
Router commandsRouter commands
Router commands
 
CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4CCNA 2 Routing and Switching v5.0 Chapter 4
CCNA 2 Routing and Switching v5.0 Chapter 4
 
CCNA Exam 200-120 pdf
CCNA Exam 200-120 pdfCCNA Exam 200-120 pdf
CCNA Exam 200-120 pdf
 
How to configure vlan, stp, dtp step by step guide
How to configure vlan, stp, dtp step by step guideHow to configure vlan, stp, dtp step by step guide
How to configure vlan, stp, dtp step by step guide
 
CCNA Router Startup and Configuration
CCNA Router Startup and ConfigurationCCNA Router Startup and Configuration
CCNA Router Startup and Configuration
 
Router commands
Router commandsRouter commands
Router commands
 
Lab practice 1 configuring basic routing and switching (with answer)
Lab practice 1   configuring basic routing and switching (with answer) Lab practice 1   configuring basic routing and switching (with answer)
Lab practice 1 configuring basic routing and switching (with answer)
 
CCNA Routing Protocols
CCNA Routing ProtocolsCCNA Routing Protocols
CCNA Routing Protocols
 

Semelhante a COIS 420 - Practice01

CHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxCHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxMuhammadSheraz836877
 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oraclesuman1248
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9Umair Amjad
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developersInSync Conference
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorialbunny0143
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلMohamed Moustafa
 
Sql intro
Sql introSql intro
Sql introglubox
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatementsSubash T
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statementSyed Zaid Irshad
 

Semelhante a COIS 420 - Practice01 (20)

Les01
Les01Les01
Les01
 
Lecture02_IDB.pptx
Lecture02_IDB.pptxLecture02_IDB.pptx
Lecture02_IDB.pptx
 
CHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxCHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptx
 
Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
 
Les01.ppt
Les01.pptLes01.ppt
Les01.ppt
 
Les01.pptx
Les01.pptxLes01.pptx
Les01.pptx
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Sql 3
Sql 3Sql 3
Sql 3
 
SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9SQL WORKSHOP::Lecture 9
SQL WORKSHOP::Lecture 9
 
UNIT2.ppt
UNIT2.pptUNIT2.ppt
UNIT2.ppt
 
SQL Notes
SQL NotesSQL Notes
SQL Notes
 
SQLQueries
SQLQueriesSQLQueries
SQLQueries
 
Connor McDonald 11g for developers
Connor McDonald 11g for developersConnor McDonald 11g for developers
Connor McDonald 11g for developers
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
 
Sql intro
Sql introSql intro
Sql intro
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
 
Retrieving data using the sql select statement
Retrieving data using the sql select statementRetrieving data using the sql select statement
Retrieving data using the sql select statement
 
DBMS Chapter-3.ppsx
DBMS Chapter-3.ppsxDBMS Chapter-3.ppsx
DBMS Chapter-3.ppsx
 

Mais de Angel G Diaz

SQL Developer installation-guide
SQL Developer installation-guideSQL Developer installation-guide
SQL Developer installation-guideAngel G Diaz
 
Lesson - 02 Network Design and Management
Lesson - 02 Network Design and ManagementLesson - 02 Network Design and Management
Lesson - 02 Network Design and ManagementAngel G Diaz
 
Lesson 01 - Introduction to SQL
Lesson 01 - Introduction to SQLLesson 01 - Introduction to SQL
Lesson 01 - Introduction to SQLAngel G Diaz
 
OracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper InstallOracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper InstallAngel G Diaz
 
GNS3 Simulator Installation
GNS3 Simulator InstallationGNS3 Simulator Installation
GNS3 Simulator InstallationAngel G Diaz
 
WAMP & Joomla! Installation
WAMP & Joomla! InstallationWAMP & Joomla! Installation
WAMP & Joomla! InstallationAngel G Diaz
 
COIS 420 - Practice04
COIS 420 - Practice04COIS 420 - Practice04
COIS 420 - Practice04Angel G Diaz
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03Angel G Diaz
 
Lesson02 - Network Design & LAN
Lesson02 - Network Design & LANLesson02 - Network Design & LAN
Lesson02 - Network Design & LANAngel G Diaz
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlAngel G Diaz
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlAngel G Diaz
 
Making Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and CompressionMaking Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and CompressionAngel G Diaz
 
Making Connections
Making ConnectionsMaking Connections
Making ConnectionsAngel G Diaz
 
Conducted and Wireless Media
Conducted and Wireless MediaConducted and Wireless Media
Conducted and Wireless MediaAngel G Diaz
 
Fundamentals of Data and Signals
Fundamentals of Data and SignalsFundamentals of Data and Signals
Fundamentals of Data and SignalsAngel G Diaz
 
Introduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data CommunicationsIntroduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data CommunicationsAngel G Diaz
 

Mais de Angel G Diaz (17)

SQL Developer installation-guide
SQL Developer installation-guideSQL Developer installation-guide
SQL Developer installation-guide
 
Lesson - 02 Network Design and Management
Lesson - 02 Network Design and ManagementLesson - 02 Network Design and Management
Lesson - 02 Network Design and Management
 
Lesson 01 - Introduction to SQL
Lesson 01 - Introduction to SQLLesson 01 - Introduction to SQL
Lesson 01 - Introduction to SQL
 
OracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper InstallOracleXE & SQLDeveloper Install
OracleXE & SQLDeveloper Install
 
GNS3 Simulator Installation
GNS3 Simulator InstallationGNS3 Simulator Installation
GNS3 Simulator Installation
 
WAMP & Joomla! Installation
WAMP & Joomla! InstallationWAMP & Joomla! Installation
WAMP & Joomla! Installation
 
COIS 420 - Practice04
COIS 420 - Practice04COIS 420 - Practice04
COIS 420 - Practice04
 
COIS 420 - Practice 03
COIS 420 - Practice 03COIS 420 - Practice 03
COIS 420 - Practice 03
 
Lesson02 - Network Design & LAN
Lesson02 - Network Design & LANLesson02 - Network Design & LAN
Lesson02 - Network Design & LAN
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error Control
 
Errors, Error Detection, and Error Control
Errors, Error Detection, and Error ControlErrors, Error Detection, and Error Control
Errors, Error Detection, and Error Control
 
Making Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and CompressionMaking Connections Efficient: Multiplexing and Compression
Making Connections Efficient: Multiplexing and Compression
 
Making Connections
Making ConnectionsMaking Connections
Making Connections
 
Conducted and Wireless Media
Conducted and Wireless MediaConducted and Wireless Media
Conducted and Wireless Media
 
Fundamentals of Data and Signals
Fundamentals of Data and SignalsFundamentals of Data and Signals
Fundamentals of Data and Signals
 
Introduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data CommunicationsIntroduction to Computer Networks and Data Communications
Introduction to Computer Networks and Data Communications
 
Cois240 lesson01
Cois240 lesson01Cois240 lesson01
Cois240 lesson01
 

Último

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 

Último (20)

How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

COIS 420 - Practice01

  • 1. 1 Writing Basic SQL Statements
  • 2. Objectives After completing this lesson, you should be able to do the following: • List the capabilities of SQL SELECT statements • Execute a basic SELECT statement • Differentiate between SQL statements and SQL*Plus commands 1-2
  • 3. Capabilities of SQL SELECT Statements Selection Projection Table 1 Table 1 Join Table 1 Table 2 1-3
  • 4. Basic SELECT Statement SELECT [DISTINCT] {*, column [alias],...} FROM table; • SELECT identifies what columns. • FROM identifies which table. 1-4
  • 5. Writing SQL Statements • SQL statements are not case sensitive. • SQL statements can be on one or more lines. • Keywords cannot be abbreviated or split across lines. • Clauses are usually placed on separate lines. • Tabs and indents are used to enhance readability. 1-5
  • 6. Selecting All Columns SQL> SELECT * 2 FROM dept; DEPTNO DNAME LOC --------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 1-6
  • 7. Selecting Specific Columns SQL> SELECT deptno, loc 2 FROM dept; DEPTNO LOC --------- ------------- 10 NEW YORK 20 DALLAS 30 CHICAGO 40 BOSTON 1-7
  • 8. Column Heading Defaults • Default justification – Left: Date and character data – Right: Numeric data • Default display: Uppercase 1-8
  • 9. Arithmetic Expressions Create expressions on NUMBER and DATE data by using arithmetic operators. Operator Description + Add - Subtract * Multiply / Divide 1-9
  • 10. Using Arithmetic Operators SQL> SELECT ename, sal, sal+300 2 FROM emp; ENAME SAL SAL+300 ---------- --------- --------- KING 5000 5300 BLAKE 2850 3150 CLARK 2450 2750 JONES 2975 3275 MARTIN 1250 1550 ALLEN 1600 1900 ... 14 rows selected. 1-10
  • 11. Operator Precedence / + _ * • Multiplication and division take priority over addition and subtraction. • Operators of the same priority are evaluated from left to right. • Parentheses are used to force prioritized evaluation and to clarify statements. 1-11
  • 12. Operator Precedence SQL> SELECT ename, sal, 12*sal+100 2 FROM emp; ENAME SAL 12*SAL+100 ---------- --------- ---------- KING 5000 60100 BLAKE 2850 34300 CLARK 2450 29500 JONES 2975 35800 MARTIN 1250 15100 ALLEN 1600 19300 ... 14 rows selected. 1-12
  • 13. Using Parentheses SQL> SELECT ename, sal, 12*(sal+100) 2 FROM emp; ENAME SAL 12*(SAL+100) ---------- --------- ----------- KING 5000 61200 BLAKE 2850 35400 CLARK 2450 30600 JONES 2975 36900 MARTIN 1250 16200 ... 14 rows selected. 1-13
  • 14. Defining a Null Value • A null is a value that is unavailable, unassigned, unknown, or inapplicable. • A null is not the same as zero or a blank space. SQL> SELECT ename, job, comm 2 FROM emp; ENAME JOB COMM ---------- --------- --------- KING PRESIDENT BLAKE MANAGER ... TURNER SALESMAN 0 ... 14 rows selected. 1-14
  • 15. Null Values in Arithmetic Expressions Arithmetic expressions containing a null value evaluate to null. SQL> select ename, 12*sal+comm 2 from emp 3 WHERE ename='KING'; ENAME 12*SAL+COMM ---------- ----------- KING 1-15
  • 16. Defining a Column Alias • Renames a column heading • Is useful with calculations • Immediately follows column name; optional AS keyword between column name and alias • Requires double quotation marks if it contains spaces or special characters or is case sensitive 1-16
  • 17. Using Column Aliases SQL> SELECT ename AS name, sal salary 2 FROM emp; NAME SALARY ------------- --------- ... SQL> SELECT ename "Name", 2 sal*12 "Annual Salary" 3 FROM emp; Name Annual Salary ------------- ------------- ... 1-17
  • 18. Concatenation Operator • Concatenates columns or character strings to other columns • Is represented by two vertical bars (||) • Creates a resultant column that is a character expression 1-18
  • 19. Using the Concatenation Operator SQL> SELECT ename||job AS "Employees" 2 FROM emp; Employees ------------------- KINGPRESIDENT BLAKEMANAGER CLARKMANAGER JONESMANAGER MARTINSALESMAN ALLENSALESMAN ... 14 rows selected. 1-19
  • 20. Literal Character Strings • A literal is a character, expression, or number included in the SELECT list. • Date and character literal values must be enclosed within single quotation marks. • Each character string is output once for each row returned. 1-20
  • 21. Using Literal Character Strings SQL> SELECT ename ||' '||'is a'||' '||job 2 AS "Employee Details" 3 FROM emp; Employee Details ------------------------- KING is a PRESIDENT BLAKE is a MANAGER CLARK is a MANAGER JONES is a MANAGER MARTIN is a SALESMAN ... 14 rows selected. 1-21
  • 22. Duplicate Rows The default display of queries is all rows, including duplicate rows. SQL> SELECT deptno 2 FROM emp; DEPTNO --------- 10 30 10 20 ... 14 rows selected. 1-22
  • 23. Eliminating Duplicate Rows Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SQL> SELECT DISTINCT deptno 2 FROM emp; DEPTNO --------- 10 20 30 1-23
  • 24. SQL and SQL*Plus Interaction SQL Statements SQL Statements Buffer Server SQL*Plus SQL*Plus Query Results Commands Formatted Report 1-24
  • 25. SQL Statements Versus SQL*Plus Commands SQL SQL*Plus • A language • An environment • ANSI standard • Oracle proprietary • Keyword cannot be • Keywords can be abbreviated abbreviated • Statements manipulate • Commands do not data and table allow manipulation of definitions in the values in the database database SQL SQL SQL*Plus SQL*Plus statements buffer commands buffer 1-25
  • 26. Overview of SQL*Plus • Log in to SQL*Plus. • Describe the table structure. • Edit your SQL statement. • Execute SQL from SQL*Plus. • Save SQL statements to files and append SQL statements to files. • Execute saved files. • Load commands from file to buffer to edit. 1-26
  • 27. Logging In to SQL*Plus • From Windows environment: • From command line: sqlplus [username[/password [@database]]] 1-27
  • 28. Displaying Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table. DESC[RIBE] tablename 1-28
  • 29. Displaying Table Structure SQL> DESCRIBE dept Name Null? Type ----------------- -------- ------------ DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13) 1-29
  • 30. SQL*Plus Editing Commands • A[PPEND] text • C[HANGE] / old / new • C[HANGE] / text / • CL[EAR] BUFF[ER] • DEL • DEL n • DEL m n 1-30
  • 31. SQL*Plus Editing Commands • I[NPUT] • I[NPUT] text • L[IST] • L[IST] n • L[IST] m n • R[UN] •n • n text • 0 text 1-31
  • 32. SQL*Plus File Commands • SAVE filename • GET filename • START filename • @ filename • EDIT filename • SPOOL filename 1-32
  • 33. Summary SELECT [DISTINCT] {*,column [alias],...} FROM table; Use SQL*Plus as an environment to: • Execute SQL statements • Edit SQL statements 1-33