SlideShare uma empresa Scribd logo
1 de 34
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
Capabilities of SQL SELECT Statements Projection Selection Table 1 Table 1 Join Table 2 Table 1
Basic SELECT Statement SELECT	[DISTINCT] {*, column [alias],...} FROMtable; SELECT identifies what columns. FROM identifies which table.
Writing SQL Statements SQL statements are not case sensitive.  SQL statements can be on one ormore lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Tabs and indents are used to enhance readability.
Selecting All Columns SQL> SELECT * 2  FROM dept;    DEPTNO DNAME          LOC --------- -------------- ------------- 10 ACCOUNTING     NEW YORK 20 RESEARCH       DALLAS 30 SALES          CHICAGO 40 OPERATIONS     BOSTON
Selecting Specific Columns SQL> SELECT deptno, loc 2  FROM   dept;    DEPTNO LOC --------- ------------- 10 NEW YORK 20 DALLAS 30 CHICAGO 40 BOSTON
Column Heading Defaults Default justification Left: Date and character data Right: Numeric data Default display: Uppercase
Arithmetic Expressions Create expressions on NUMBER and DATE data by using arithmetic operators. Operator + - *       /       	 Description Add Subtract  Multiply  Divide
Using Arithmetic Operators SQL> SELECT ename, sal, sal+300 2  FROMemp; ENAME            SAL   SAL+300 ---------- --------- --------- KING            50005300 BLAKE           28503150 CLARK           24502750 JONES           29753275 MARTIN          12501550 ALLEN           16001900 ... 14 rows selected.
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.
Operator Precedence SQL> SELECT ename, sal, 12*sal+100 2  FROM   emp; ENAME            SAL 12*SAL+100 ---------- --------- ---------- KING            500060100 BLAKE           285034300 CLARK           245029500 JONES           297535800 MARTIN          125015100 ALLEN           160019300 ... 14 rows selected.
Using Parentheses SQL> SELECT ename, sal, 12*(sal+100) 2  FROM   emp; ENAME            SAL 12*(SAL+100) ---------- --------- ----------- KING            500061200 BLAKE           285035400 CLARK           245030600 JONES           297536900 MARTIN          125016200 ... 14 rows selected.
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  FROMemp; ENAME      JOB            COMM ---------- --------- --------- KING       PRESIDENT BLAKE      MANAGER ... TURNER     SALESMAN          0 ... 14 rows selected.
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
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
Using Column Aliases Name          Annual Salary ------------- -------------... SQL> SELECT ename AS name, sal salary 2  FROM   emp; NAME             SALARY ------------- ---------... SQL> SELECT ename "Name", 2         sal*12 "Annual Salary" 3  FROM   emp;
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
Using the Concatenation Operator SQL> SELECTename||job AS "Employees" 2  FROM emp; Employees ------------------- KINGPRESIDENT BLAKEMANAGER CLARKMANAGER JONESMANAGER MARTINSALESMAN ALLENSALESMAN ... 14 rows selected.
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.
Using Literal Character Strings SQL> SELECT ename||' '||'is a'||' '||job  2AS "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.
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.
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
SQL and SQL*Plus Interaction SQL Statements SQL Statements Server Query Results SQL*Plus  Commands Formatted Report Buffer SQL*Plus
SQL Statements Versus SQL*Plus Commands  SQL  ,[object Object]
ANSI standard
Keyword cannot be abbreviated
Statements manipulate data and table definitions in the  databaseSQL*Plus ,[object Object]
Oracle proprietary
Keywords can be abbreviated
Commands do not allow manipulation of values in the databaseSQL statements SQL buffer SQL*Plus commands SQL*Plus buffer
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 bufferto edit. Overview of SQL*Plus
Logging In to SQL*Plus From Windows environment: From command line:  sqlplus [username[/password                 [@database]]]
Displaying Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table. DESC[RIBE] tablename

Mais conteúdo relacionado

Mais procurados (20)

Les03
Les03Les03
Les03
 
Les00 Intoduction
Les00 IntoductionLes00 Intoduction
Les00 Intoduction
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Les01
Les01Les01
Les01
 
Les12
Les12Les12
Les12
 
Les10
Les10Les10
Les10
 
Les11
Les11Les11
Les11
 
Les09
Les09Les09
Les09
 
SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12SQL WORKSHOP::Lecture 12
SQL WORKSHOP::Lecture 12
 
MERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known FacetsMERGE SQL Statement: Lesser Known Facets
MERGE SQL Statement: Lesser Known Facets
 
ORACLE NOTES
ORACLE NOTESORACLE NOTES
ORACLE NOTES
 
Les05[1]Aggregating Data Using Group Functions
Les05[1]Aggregating Data  Using Group FunctionsLes05[1]Aggregating Data  Using Group Functions
Les05[1]Aggregating Data Using Group Functions
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
 
Les02
Les02Les02
Les02
 
SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2SQL WORKSHOP::Lecture 2
SQL WORKSHOP::Lecture 2
 
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?
 
COIS 420 - Practice02
COIS 420 - Practice02COIS 420 - Practice02
COIS 420 - Practice02
 
SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1SQL WORKSHOP::Lecture 1
SQL WORKSHOP::Lecture 1
 
Single row functions
Single row functionsSingle row functions
Single row functions
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 

Destaque

Destaque (20)

SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Lecture 07 - Basic SQL
Lecture 07 - Basic SQLLecture 07 - Basic SQL
Lecture 07 - Basic SQL
 
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT StatementsWriting Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
 
Introduction to mysql part 2
Introduction to mysql part 2Introduction to mysql part 2
Introduction to mysql part 2
 
No sql and sql - open analytics summit
No sql and sql - open analytics summitNo sql and sql - open analytics summit
No sql and sql - open analytics summit
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Sql basics joi ns and common commands (1)
Sql basics  joi ns and common commands (1)Sql basics  joi ns and common commands (1)
Sql basics joi ns and common commands (1)
 
Sql Basic Selects
Sql Basic SelectsSql Basic Selects
Sql Basic Selects
 
1 ddl
1 ddl1 ddl
1 ddl
 
Sql basics
Sql basicsSql basics
Sql basics
 
What Is SQL?
What Is SQL?What Is SQL?
What Is SQL?
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
 
php basic sql
php basic sqlphp basic sql
php basic sql
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
Tables And SQL basics
Tables And SQL basicsTables And SQL basics
Tables And SQL basics
 
SQL Basic Queries
SQL Basic Queries SQL Basic Queries
SQL Basic Queries
 
개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축개발자가 도전하는 MariaDB 서버구축
개발자가 도전하는 MariaDB 서버구축
 
개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝개발자도 알아야 하는 DBMS튜닝
개발자도 알아야 하는 DBMS튜닝
 
Sql Server 2012
Sql Server 2012Sql Server 2012
Sql Server 2012
 

Semelhante a Les01 Writing Basic Sql Statements

Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oraclesuman1248
 
CHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxCHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxMuhammadSheraz836877
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01Angel G Diaz
 
Sql statments c ha p# 1
Sql statments c ha p# 1Sql statments c ha p# 1
Sql statments c ha p# 1Nargis Ehsan
 
Les01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL StatementsLes01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL Statementssiavosh kaviani
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sqlN.Jagadish Kumar
 
Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oraclesuman1248
 
Sql intro
Sql introSql intro
Sql introglubox
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلMohamed Moustafa
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Achmad Solichin
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatementsAnjac
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatementsSubash T
 

Semelhante a Les01 Writing Basic Sql Statements (20)

Les01-Oracle
Les01-OracleLes01-Oracle
Les01-Oracle
 
CHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptxCHAPTER 1 BASIC sql STATEMENTS.pptx
CHAPTER 1 BASIC sql STATEMENTS.pptx
 
COIS 420 - Practice01
COIS 420 - Practice01COIS 420 - Practice01
COIS 420 - Practice01
 
Sql statments c ha p# 1
Sql statments c ha p# 1Sql statments c ha p# 1
Sql statments c ha p# 1
 
Basic sql statements
Basic sql statementsBasic sql statements
Basic sql statements
 
Lecture02_IDB.pptx
Lecture02_IDB.pptxLecture02_IDB.pptx
Lecture02_IDB.pptx
 
Les01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL StatementsLes01[1]Writing Basic SQL Statements
Les01[1]Writing Basic SQL Statements
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Les01.ppt
Les01.pptLes01.ppt
Les01.ppt
 
Les01.pptx
Les01.pptxLes01.pptx
Les01.pptx
 
Sqlplus
SqlplusSqlplus
Sqlplus
 
Les08-Oracle
Les08-OracleLes08-Oracle
Les08-Oracle
 
Sql intro
Sql introSql intro
Sql intro
 
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكلحل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
حل اسئلة الكتاب السعودى فى شرح قواعد البيانات اوراكل
 
Les01
Les01Les01
Les01
 
Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)Les01 (retrieving data using the sql select statement)
Les01 (retrieving data using the sql select statement)
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
 
Basic sqlstatements
Basic sqlstatementsBasic sqlstatements
Basic sqlstatements
 
Sql 3
Sql 3Sql 3
Sql 3
 
Sql dml & tcl 2
Sql   dml & tcl 2Sql   dml & tcl 2
Sql dml & tcl 2
 

Último

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 

Último (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 

Les01 Writing Basic Sql Statements

  • 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
  • 3. Capabilities of SQL SELECT Statements Projection Selection Table 1 Table 1 Join Table 2 Table 1
  • 4. Basic SELECT Statement SELECT [DISTINCT] {*, column [alias],...} FROMtable; SELECT identifies what columns. FROM identifies which table.
  • 5. Writing SQL Statements SQL statements are not case sensitive. SQL statements can be on one ormore lines. Keywords cannot be abbreviated or split across lines. Clauses are usually placed on separate lines. Tabs and indents are used to enhance readability.
  • 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
  • 7. Selecting Specific Columns SQL> SELECT deptno, loc 2 FROM dept; DEPTNO LOC --------- ------------- 10 NEW YORK 20 DALLAS 30 CHICAGO 40 BOSTON
  • 8. Column Heading Defaults Default justification Left: Date and character data Right: Numeric data Default display: Uppercase
  • 9. Arithmetic Expressions Create expressions on NUMBER and DATE data by using arithmetic operators. Operator + - * / Description Add Subtract Multiply Divide
  • 10. Using Arithmetic Operators SQL> SELECT ename, sal, sal+300 2 FROMemp; ENAME SAL SAL+300 ---------- --------- --------- KING 50005300 BLAKE 28503150 CLARK 24502750 JONES 29753275 MARTIN 12501550 ALLEN 16001900 ... 14 rows selected.
  • 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.
  • 12. Operator Precedence SQL> SELECT ename, sal, 12*sal+100 2 FROM emp; ENAME SAL 12*SAL+100 ---------- --------- ---------- KING 500060100 BLAKE 285034300 CLARK 245029500 JONES 297535800 MARTIN 125015100 ALLEN 160019300 ... 14 rows selected.
  • 13. Using Parentheses SQL> SELECT ename, sal, 12*(sal+100) 2 FROM emp; ENAME SAL 12*(SAL+100) ---------- --------- ----------- KING 500061200 BLAKE 285035400 CLARK 245030600 JONES 297536900 MARTIN 125016200 ... 14 rows selected.
  • 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 FROMemp; ENAME JOB COMM ---------- --------- --------- KING PRESIDENT BLAKE MANAGER ... TURNER SALESMAN 0 ... 14 rows selected.
  • 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
  • 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
  • 17. Using Column Aliases Name Annual Salary ------------- -------------... SQL> SELECT ename AS name, sal salary 2 FROM emp; NAME SALARY ------------- ---------... SQL> SELECT ename "Name", 2 sal*12 "Annual Salary" 3 FROM emp;
  • 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
  • 19. Using the Concatenation Operator SQL> SELECTename||job AS "Employees" 2 FROM emp; Employees ------------------- KINGPRESIDENT BLAKEMANAGER CLARKMANAGER JONESMANAGER MARTINSALESMAN ALLENSALESMAN ... 14 rows selected.
  • 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.
  • 21. Using Literal Character Strings SQL> SELECT ename||' '||'is a'||' '||job 2AS "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.
  • 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.
  • 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
  • 24. SQL and SQL*Plus Interaction SQL Statements SQL Statements Server Query Results SQL*Plus Commands Formatted Report Buffer SQL*Plus
  • 25.
  • 27. Keyword cannot be abbreviated
  • 28.
  • 30. Keywords can be abbreviated
  • 31. Commands do not allow manipulation of values in the databaseSQL statements SQL buffer SQL*Plus commands SQL*Plus buffer
  • 32. 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 bufferto edit. Overview of SQL*Plus
  • 33. Logging In to SQL*Plus From Windows environment: From command line: sqlplus [username[/password [@database]]]
  • 34. Displaying Table Structure Use the SQL*Plus DESCRIBE command to display the structure of a table. DESC[RIBE] tablename
  • 35. Displaying Table Structure SQL> DESCRIBE dept Name Null? Type ----------------- -------- ------------ DEPTNO NOT NULL NUMBER(2) DNAME VARCHAR2(14) LOC VARCHAR2(13)
  • 36. SQL*Plus Editing Commands A[PPEND] text C[HANGE] / old / new C[HANGE] / text / CL[EAR] BUFF[ER] DEL DEL n DEL m n
  • 37. SQL*Plus Editing Commands I[NPUT] I[NPUT] text L[IST] L[IST] n L[IST] m n R[UN] n ntext 0text
  • 38. SQL*Plus File Commands SAVE filename GET filename START filename @ filename EDIT filename SPOOL filename
  • 39. Summary SELECT [DISTINCT] {*,column [alias],...} FROMtable; Use SQL*Plus as an environment to: Execute SQL statements Edit SQL statements
  • 40. Practice Overview Selecting all data from different tables Describing the structure of tables Performing arithmetic calculations and specifying column names Using SQL*Plus editor