03 SQLDataRetrieval
03 SQLDataRetrieval
objectives :
•list oracle9i data-types
•state what is sql
•list sql components
•state the syntax for data retrieval using select statement
•state & demonstrate the use of where clause
•state & demonstrate the use of order by clause
•explain and demonstrate the use of various operators in where
clause
•demonstrate sql*plus environment
•varchar2(n)
–variable length character data
–maximum length `n’ must be specified
–maximum length is 4000 bytes
–all alpha-numeric characters are allowed
•varchar (n)
–synonymous with varchar2
–oracle has reserved this data type for future use
•long
–large amounts of variable length text
–any length up to 2 gb can be specified
restrictions :
•only one column per table can be defined as long
•a long column can’t be indexed
•a long column can’t be passed as argument to a procedure or function
•a function can’t be used to return a long column
•a long column can’t be used in where, order by, group by and other
clauses
numeric data types
•number
–the number data type is used to store zero, negative, positive, fixed and
floating point numbers with up to 38 digits of precision having
magnitude between 1.0 * 10 -130 to
9.9….9 * 10 125
number can be defined in three ways :
–number(p, s)
–number(p)
–number
•number(p,s) :
–where p is the precision up to 38 digits
–s is the scale ranging
•number (p) :
–a fixed point number with a scale of 0 and a precision of p
•number :
–a floating point number with a precision of 38
–storage space 21 bytes / row
•long raw
–used to store binary data up to 2 gb
date data type
•date and time data
•storage space 7 bytes / row
•can store data ranging from january 1, 4712 bc to december 31,
4712 ad
•default format is : dd-mon-yy
•clob
–used to store large single byte character data
•nclob
–used to store large nls character data
•bfile
–used with large binary data stored out side the database in an external
file
introduction to sql
•what is sql, sql*plus and pl/sql?
–sql :
•structured query language
•the language used to access the data from rdbms
•non-procedural language
–pl/sql
•oracle’s procedural language extension of sql
•used by oracle tools
–sql* plus :
•powerful oracle support product
•programmer’s tool
•command line interpreter
•used in conjunction with sql and pl/sql
sql * plus
•using sql*plus you can
–enter, edit, store, retrieve and run sql command and pl/sql blocks
–format, perform calculations on, store and print query results
–list column definitions for a table
components of sql
•sql is made of three sub-languages
–data definition language (ddl)
–data manipulation language (dml)
–data control language (dcl)
components of sql
•data definition language (ddl) :
–consists of commands to create the objects such as tables, views,
indexes etc.
•dept
–department information
•syntax :
select <column_list>
from <table_name>
[where <condition>]
[group by <column_name(s)>]
[having <condition>]
[order by <expression>];
examples :
1. list the information of all employees.
•relational operators :
= equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
<>, !=,^= not equal to
•logical operators
and logical and
or logical or
not logical not
special operators:
•special operators :
in checking value in a set
between checking value within a range
is nullchecking for null value
like matching pattern from a column
|| concatenation of strings
special operators: in
•in operator :
–the in operator can be used to select rows that match one of the values
included in the list
•examples :
1. list the name of the employees whose employee numbers are 7369,
7521, 7839, 7934, 7788.
2. list the employees not belonging to department numbers 30 and 10.
•examples :
1. list the employee name and salary, whose salary is in the range 1000
to 2000.
2. list employee names, who have joined before 30 june 81 and after
december 81.
•examples :
1. list the employee names, who are not eligible for commission.
2. list the name and job of the employees, who do not report to
anybody.
•examples :
1. list the employees whose name start with an `s’.
2. list the details of employees in the department wise ascending order and
in the descending order of salary.