Documentos de Académico
Documentos de Profesional
Documentos de Cultura
1-1
Vasumathi M
Objectives
After After completing completing this this lesson, lesson, you you should should be be able able to to do do the the following: following: List List the the capabilities capabilities of of SQL SQL SELECT SELECT statements statements Execute Execute a a basic basic SELECT SELECT statement statement Differentiate Differentiate between between SQL SQL statements statements and and SQL*Plus SQL*Plus commands commands
1-2
Vasumathi M
Table 1
Join
Table 1
Table 1
1-3 Antrix Consultancy Services
Table 2
Vasumathi M
SELECT SELECT identifies identifies what what columns columns FROM FROM identifies identifies which which table table
1-4
Vasumathi M
DEPTNO --------10 20 30 40
1-6
Vasumathi M
1-7
Vasumathi M
1-8
Vasumathi M
Arithmetic Expressions
Create Create expressions expressions on on NUMBER NUMBER and and DATE DATE data data by by using using arithmetic arithmetic operators. operators.
Operator + * / Description Add Subtract Multiply Divide
1-9
Vasumathi M
1-10
Vasumathi M
Operator Precedence
/ +
Multiplication Multiplication and and division division take take priority priority over over addition addition and and subtraction. subtraction. Operators Operators of of the the same same priority priority are are evaluated evaluated from from left left to to right. right. Parentheses Parentheses are are used used to to force force prioritized prioritized evaluation evaluation and and to to clarify clarify statements. statements.
1-11 Antrix Consultancy Services Vasumathi M
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
Vasumathi M
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
Vasumathi M
ENAME JOB COMM ---------- --------- --------KING PRESIDENT BLAKE MANAGER ... TURNER SALESMAN 0 ... 14 rows selected.
1-14 Antrix Consultancy Services Vasumathi M
1-15
Vasumathi M
Concatenation Operator
Concatenates Concatenates columns columns or or character character strings strings to to other other columns columns Is Is represented represented by by two two vertical vertical bars bars (||) (||) Creates Creates a a resultant resultant column column that that is is a a character character expression expression
1-18
Vasumathi M
Employees ------------------KINGPRESIDENT BLAKEMANAGER CLARKMANAGER JONESMANAGER MARTINSALESMAN ALLENSALESMAN ... 14 rows selected.
Antrix Consultancy Services
1-19
Vasumathi M
1-20
Vasumathi M
Employee Employee Details Details ------------------------------------------------KING KING is is a a PRESIDENT PRESIDENT BLAKE BLAKE is is a a MANAGER MANAGER CLARK CLARK is is a a MANAGER MANAGER JONES JONES is is a a MANAGER MANAGER MARTIN MARTIN is is a a SALESMAN SALESMAN ... ... 14 14 rows rows selected. selected.
1-21
Vasumathi M
Duplicate Rows
The The default default display display of of queries queries is is all all rows, rows, including including duplicate duplicate rows. rows.
SQL> SQL> 2 2 SELECT SELECT FROM FROM deptno deptno emp; emp;
1-22
Vasumathi M
DEPTNO --------10 20 30
1-23
Vasumathi M
Buffer
SQL Statements
Server
SQL*Plus
Query Results
1-24
Vasumathi M
SQL*Plus An environment Oracle proprietary Keywords can be abbreviated Commands do not allow manipulation of values in the database
SQL*Plus commands
SQL*Plus buffer
1-25
Vasumathi M
Overview of SQL*Plus
Log Log in in to to SQL*Plus. SQL*Plus. Describe Describe the the table table structure. structure. Edit Edit your your SQL SQL statement. statement. Execute Execute SQL SQL from from SQL*Plus. SQL*Plus. Save Save SQL SQL statements statements to to files files and and append append SQL SQL statements statements to to files. files. Execute Execute saved saved files. files. Load Load commands commands from from file file to to buffer buffer to to edit. edit.
1-26 Antrix Consultancy Services Vasumathi M
Logging In to SQL*Plus
From Windows environment:
1-28
Vasumathi M
1-29
Vasumathi M
n n n n text text
Antrix Consultancy Services Vasumathi M
0 0 text text
1-32
Vasumathi M
Summary
SELECT SELECT FROM FROM [DISTINCT] column [ alias ],...} [DISTINCT] {*, {*, column [ alias ],...} table; table;
Use Use SQL*Plus SQL*Plus as as an an environment environment to: to: Execute Execute SQL SQL statements statements Edit Edit SQL SQL statements statements
1-33
Vasumathi M
Practice Overview
Selecting Selecting all all data data from from different different tables tables Describing Describing the the structure structure of of tables tables Performing Performing arithmetic arithmetic calculations calculations and and specifying specifying column column names names Using Using SQL*Plus SQL*Plus editor editor
1-34
Vasumathi M
1-35
Vasumathi M
1-36
Vasumathi M
1-37
Vasumathi M
1-38
Vasumathi M