文本描述
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
Basic SELECT Statement
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 onseparate lines.
Tabs and indents are used to enhance readability.
Selecting All Columns
Selecting Specific Columns
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.
Using Arithmetic Operators
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
Using Parentheses
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.
Null Values in Arithmetic Expressions
Arithmetic expressions containing a null value evaluate to null.
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
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
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
Duplicate Rows
The default display of queries is all rows, including duplicate rows.
Eliminating Duplicate Rows
SQL and SQL*Plus Interaction
SQL Statements Versus SQL*Plus Commands
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 bufferto edit.
Logging In to SQL*Plus
From Windows environment:
From command line:
sqlplus [username[/password
[@database]]]