Professional Documents
Culture Documents
WWW - Kutub.info 4150
WWW - Kutub.info 4150
WWW - Kutub.info 4150
com
SQL & SQL * PLUS
( oracle 9i)
8 / 2009
....
:
) ( sql
) (220
.
:
mmah_1550@hotmail.com
mmah_1550@yahoo.com
.
.
-2009-
2
/
4-3
2 -1 sql
9-8
4 -1 sql * plus
10
5 -1
13 - 11
6 -1
16 - 13
7 -1
17
: select
1 -2
20 - 19
2 -2
22 - 21
3 -2 )| |(
23 - 22
4 -2 ) ( distinct
24
5 -2 ) ( where
31 - 25
6 -2 ) ( order by
33 - 31
7 -2 ) ( sql functions
52 - 33
8 -2
56 - 52
9 -2 ) ( subquery
61 - 56
10 -2
62
68 - 64
2 -3
69 - 68
3 -3
70 - 69
4 -3
71
3
: ) ( transection command
1 -4
73
2 -4
74
88 - 76
2 -5 ) ( views
90 - 88
3 -5 ) ( sequences
91 - 90
4 -5 ) ( indexes
92 - 91
5 -5 ) ( synonym
93 - 92
6 -5 ) ( users
94 - 93
7 -5 ) ( system
96 - 94
8 -5
97
100 - 99
2 -6
100
3 -6
101
102
103
4
/
5
/
1-1 ) ( sql
) Sql ( structure query language
: sql .
:
Data Retrieval -1
select DML
Transection command -3
) ( .
) (
.
) : ( sql
. . - .
- .
6
/
) ( sql .
) ( sql ) ( .
) ( sql ) ; ( .
CONNECT
DISC
SHOW
GET
. SQL * PLUS
SET
ED
R RUN
.
.
@
START
DEL
SAVE FILENAME
) ( .
SAVE FILENAME
APPEND
SAVE FILENAME
REPLACE
QUIT
.
.
.
EXIT
7
oracle orahome92
Application Development
. sql plus
:
.
sql
.
..... .
8
/
ENTER ) (
.
) * ( :
catalog
:
/ c /
ENTER .
9
/
filename.sql
GET
GET
append save
replace save
.sql
:
spool filename.sql
...........
...........
Spool off
. spool off
:
10
/
5-1
:
11
/
tiger
Connect and resource
demo
Connect and resource
manager DBA
:
scott
demo
system
cat catalog .
sql :
/ connect
12
/
DISC ENTER
Not connected .
:
6-1
:
desc describe
) ( emp
) . ( scott
) ( dept
) . ( scott
13
/
select * from
) . ( emp
) . ( dept
.
14
/
) ( emp ) ( dept
:
) : ( deptno .
) : ( dname .
) : ( loc .
) : ( empno .
) : ( ename .
) : ( job .
) : ( mgr .
) : ( hiredate .
) : ( sal .
) : ( comm .
) : ( deptno .
15
/
- ) : ( dual
16
/
7 -1
17
/
select
18
/
: select
select :
select . - ) . ( ,
1-2
as :
19
/
) ( ename ) ( name as
as
.
20
/
2-2
sql from
) ( salary
21
/
3-2 ) || (
) || ( :
) ( ename ) ( job
) . ( employees
22
/
) ( sal ) ( comm . 10
) ( sal ) ( comm
.
23
/
4-2 ) ( distinct
distinct ) ( .
10 20 30
distinct :
distinct
.
24
/
5-2 where
select
:
.
where
.
:
-1 ) ' ' ( .
-2 .
-3 sql . DD MON YY
:
DD
. 09 :
MON SEP : .
YY
09 : . 2009
where
=!=,>,<,>=,<=,<>,
)'_like ( ' %
) ' soundex ( ' excerption
is null
and , or , not
25
not :
not between
not like
not in
is not null
) ( where :
) ( ename ) ( job
) ( deptno . 10
) ( ename ) ( sal
. 2000
26
/
) ( ename ) ( sal
2000 . 4000
like
% .
)'( ' m%
. m
. m
. M
. M
M .
27
/
soundex
.
) ( SMOTH SMITH
.
) ( no rows selected
:
and
) ( and :
true
true
false
false
true
false
true
false
true
false
false
false
28
/
2000
. 10
) ( .
or
) ( or :
true
true
false
false
true
false
true
false
true
true
true
false
29
/
2000 10
) ( .
) ( emp
6600 40 .
not
) ( not :
false
true
true
false
) ( JENES ) ( JAMES ) . ( JONES
30
/
1000 . 3000
6-2 order by
ascending descending
. select
) ( deptno
) ( .
31
/
10 ) . ( hiredate
desc :
) ( deptno
desc ) ( .
32
/
) ( deptno
) ( sal .
-2
33
/
-1 :
lower
upper
initcap
concat
substr
length
instr
lpad
rpad
trim
ltrim
rtrim
-2 :
.
.
.
round
trunc
mod
34
/
-3 :
sysdate
months_between
add_months
next_day
last_day
round
trunc
new_time
-4 :
to_char
to_number
to_date
:
select . where
35
/
) lower -1 ( :
) upper -2 ( :
) initcap -3 ( :
- .
) concat -4 ( :
36
/
) substr -5 (:
.
) length -6 ( :
) instr -7 ( :
) lpad -8 ( :
8 ) ( maher
) . ( #
37
/
10 ) ( maher
) * ( .
) rpad -9 ( :
8 ) ( maher
) . ( #
) trim -10 ( :
) ( from
.
38
/
) ( trim .
) rtrim -11 ( :
) . ( from
) ltrim -12 ( :
select . where
) round -1 ( :
39
/
. 0
) ( 1- .
) trunc -2 ( :
40
/
) mod -3 ( :
) ( sal ) . ( comm
) sysdate -1 ( :
) month_between -2 ( :
) add_months -3 ( :
41
/
) next_day -4 ( :
) last_day -5 ( :
) round -6 ( :
42
/
) trunc -7 ( :
.
) new_time -8 ( :
) (HST
) ( EST .
43
/
-1 :
)'to_char(date ,'fmt
-2 :
)'to_char( number ,'fmt
-3 :
)'to date ( char ,'fmt
.
44
/
-4 :
)'to_number ( char ,'fmt
:
) nvl -1 ( :
) ( comm
45
/
) translate -2 ( :
:
)translate(string , if , then
) ( if
) ( then .
) ( if
) ( then .
decode -3
translate decode
:
)Decode ( value , if 1 , then 1 , if 2 , then 2 , if 3 , then 3 , else .
46
/
) ascii -4 ( :
) ( M,R .
47
/
) chr -5 : ( ascii
) (77,82 . ascii
) ( .
sum
max,min,greatest,least . .
avg
) ( .
.
count
stddevdevttion
variance
select . where
:
) sum -1 ( :
. 10
48
/
) max -2 ( :
. 10
) min -3 ( :
. 10
) greatest -4 ( :
) z . ( a
49
/
) least -5 ( :
) a . ( z
) avg -6 ( :
. 10
) count -7 ( :
) ( count
) ( deptno ) . ( sal
50
/
- group by .
) ( deptno
) ( sum ) ( where
) . ( where
) ( having
) . ( group by
) : ( having .
51
/
) : ( select
10
8500 .
select ) ( from
) ( where ) ( group by ) ( having ) . ( order by
8-2
. select
: ) ( select .
- :
-1 . equal join
-2 . non-equal join
-3 . outer join
-4 . self join
-5 .
52
/
-1 equal join
.
) ( emp , dept
) ( where ) ( deptno
) . ( dept
:
53
/
-2 non-equal join
.
) . ( salgrade
-3 outer join
.
54
/
40
) ( dept ) (+ ) ( deptno .
-4 self join
.
) ( KING ) (.
-5
) . ( 1
.....
and or .
55
/
) . ( where
9-2 ) ( subquery
:
) : ( WARD
56
/
30 ) . ( ALLEN
- :
- .
- .
: select
where having . from
) . ( WARD
) . ( 7934
58
/
-2 ) : ( multiple-row subquery
) in , =any , <any ,
. ( exist , not exist, >any , =all , <all , >all
-3 ) : ( multiple-column subquery
.
59
/
) ( emp e
. m
union
intersect
minus
) . ( union
) . ( intersect
60
/
) ( minus
) ( emp ) . ( deptno
40 ) ( dept
) . ( emp
) ( union .
61
/
10 -2
-1 7566
.7369
-2
.30
-3
) . ( SALESMAN , CLERK
62
/
:
Data Manipulating Language
( DML)
63
/
-1 ) . ( insert
-2 ) . ( update
-3 ) . ( delete
1-3
) ( insert :
:
. insert - .
. - .
- scott
) ( emp2
) : ( emp2
64
/
) . ( dept2
65
/
) (/
) (R :
66
/
). ( emp2
67
/
) ( : substitution variables
) ( sql ) ( sql
) & ( .
2-3
) ( update :
update table name set column1= value , column2= value
; where condition
) . ( MAHER
) ( loc . 50
68
/
8000 8001
8001 :
3-3
) ( delete :
delete from table_name
; where condition
) . ( rollback - .
- .
69
/
) . ( KING
truncate
delete
rollback . delete
70
/
4 -3
-1 : emp
71
/
:
Transection command
72
/
.
.
commit
Auto commit
rollback
. commit
. rollback
savepoint
: commit .
: auto commit .
- : rollback
commit
.
: savepoint . rollback
73
/
2 -4
.
74
/
:
Data Definition Language
75
/
1-5 ) ( tables
) : ( creating tables ) . ( create
number
date
char
varchar2
2 .
4 .
long
long row
4 clob-blob .
dfile
4 .
- 30 .
) . ( create ) ( # , $ , _ , , - .
- .
38 . 240 . 9 . - .
76
/
create
:
( create table table name
column1
data type
column2
data type
)column(n
;) data type
) ( emp :
) ( empno 4
15 ) ( job 15
) ( mgr 4 ) ( hiredate
) ( sal
) (5,2 ) ( comm
) ( 5,2
) ( deptno . 2
77
/
) ( emp :
) ( emp :
) ( emp 10 20 .
) ( emp
12 ) . ( annual_salary
78
/
- ) : ( altering table
alter
) ( alter :
-1 .
:
;))1- alter table_name add ( column_name type(size
) . ( dept2
-2 .
:
;))2- alter table_name modify ( column_name type(size
) ( deptno 2 . 3
79
/
) ( .
-3 .
:
) ( ) . ( comm
-4 .
:
; 4- rename old_name to new_name
) ( emp2 ) . ( emp22
80
/
-5 .
:
; 5- drop table table_name
) ( ) . ( emp22
-6 .
:
) . ( dept2
) . ( not null . - ) ( .
) ( . - .
-1 .
-2 ) ( oracle server :
- ) _ ( user .
) _ ( all .
- ) _ ( dba
81
/
) : ( constraints .
: ( primary key ) -3 )
( .
: ( foreign key ) -4 .
: ( check ) -5 .
: ( default ) -6 .
- :
) ( not null
) ( .
) ( unique
- :
) ( dname .
82
/
- :
) ( dname .
) (primary key
.
- :
) ( dname .
- :
) ( dname
83
/
) ( foreign key
) ( primary key
.
- :
84
/
- :
) ( check
.
- :
) ( deptno ) (5 ) (85
85
/
- :
) ( default
:
) ( default ) ( st_age . 25
- :
) ( alter :
alter table table_name
; add constraint constraint_name constraint_type
86
/
) ( primary key
- .
: :
) ( .
cascade
disable
enable
) ( primary key ) ( .
87
/
- :
) . ( primary key
) . ( foreign key
) . ( unique
) ( emp ) ( dept
) . ( user_constraints
2-5 ) ( views
) : ( creating views
.
88
/
) ( emp
. 2500
) : ( emp_view
) ( emp_view
89
/
3-5 ) ( sequences
) : ( creating sequences
) ( primary key .
increment by
Start with
maxvalue
.
.
.
.
cache
nocache
Cycle
nocycle
) ( empno ) ( emp 1
) ( 1 ) ( 50 .
90
/
2 ) . (100
) ( emp2 ) . ( empno
4-5 ) ( indexes
) : ( creating indexes :
) . ( dba_indexes
:
) ( dept3 ) . ( deptno
91
/
- 16 .
- ) ( null .
- .
) ( dept3 ) . ( deptno
5-5 ) ( synonym
) : ( creating synonyms :
.
:
) . ( dept3
92
/
- ) : ( canceling synonyms
) . ( drop
:
) . ( dept3
6-5 ) ( users
- ) : ( creating user
93
/
7-5 ) ( system
: : connect -1
) ( connect
.
94
/
) : resource -2 (
: Dba -3
.
: ) . ( exp_full_database - ) . ( imp_full_database
- ) : ( creating roles
.
.
) ( maher
.
) ( maher .
) ( identified ) ( by :
95
/
: :
:
) ( maher :
.
:
:
96
/
8 -5
-1
-1 :
) ( birth_date . - ) ( grade .
-2 ) ( grade ) . ( mark
-2
-1 ) ( user ) . ( maher
-2 .
-3
-1 ) . ( stud
-2 .
-3 .
-4 .
-5 .
-6 .
97
/
Data Control Language
98
/
1-6
) ( grant :
grant privilege1 , privilege2 , ..
; on table_name to user_name or role_name
:
) ( connect ) ( resource ) ( dba
) . ( the_fire_heart
) ( the_fire_heart
:
) ( create table ) . ( maher
:
-1 :
-2 ) ( maher :
99
/
- .
) ( emp .
2 -6
) ( revoke :
revoke privilege1 , privilege2 , ..
; from table_name to user_name or role_name
) . ( the_fire_heart
100
/
3 -6
-1 ) ( connect ) ( resource .
-2 ) ( create table ) ( alter table ) ( stud
.
-3 ) ( connect ) ( resource .
101
/
sql international 9i -1 . oracle
-2 oracle 8i / / .
oracle 9i -3 / / .
-4 ) oracle 9i ( sql & sql * plus & pl/sql / .
-5 ) ( .
102
/
103
/
:
:
1989 - 11 18 :
: -
-
:
104
/