Vous êtes sur la page 1sur 21

SQL>

SP2-0042: unknown command " - rest of line ignored.


SQL> SQL> select * from jps.employee;
SP2-0734: unknown command beginning "SQL> selec..." - rest of line ignored.
SQL> select * from jps.employee;
NAME
------------------John B Smith
Franklin T Wong
Alicia J Zelaya
Jennifer S Wallace
Ramesh K Narayan
Joyce A English
Ahmad V Jabbar
James E Borg

SSN
--------123456789
333445555
999887777
987654321
666884444
453453453
987987987
888665555

BDATE
--------09-JAN-55
08-DEC-45
19-JUL-85
20-JUN-31
15-SEP-52
31-JUL-62
29-MAR-59
10-NOV-27

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
F
25000 987654321 4
F
43000 888665555 4
M
38000 333445555 5
F
25000 333445555 5
M
25000 987654321 4
M
55000
1

8 rows selected.
SQL> select *
2 2 from jps.employee;
2 from jps.employee
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
SQL> select *
2 from jps.employee;
NAME
------------------John B Smith
Franklin T Wong
Alicia J Zelaya
Jennifer S Wallace
Ramesh K Narayan
Joyce A English
Ahmad V Jabbar
James E Borg

SSN
--------123456789
333445555
999887777
987654321
666884444
453453453
987987987
888665555

BDATE
--------09-JAN-55
08-DEC-45
19-JUL-85
20-JUN-31
15-SEP-52
31-JUL-62
29-MAR-59
10-NOV-27

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
F
25000 987654321 4
F
43000 888665555 4
M
38000 333445555 5
F
25000 333445555 5
M
25000 987654321 4
M
55000
1

8 rows selected.
SQL> clear buffer
buffer cleared
SQL> select *
2 from tab
3 where tabtype = 'TABLE';
no rows selected
SQL> select *
2 from system.tab;
no rows selected
SQL> select object_name, object_type
2 from all_objects
3 where owner = 'JPS' and object_type = 'TABLE';

OBJECT_NAME
-----------------------------BRANCH
CLIENT
DEPARTMENT
DEPENDENT
DEPTLOCATION
EMPLOYEE
LANCAP
PRIVATEOWNER
PROJECT
PROPERTYFORRENT
R

OBJECT_TYPE
------------------TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE
TABLE

OBJECT_NAME
-----------------------------REGISTRATION
S
STAFF
VIEWING
WORKSON

OBJECT_TYPE
------------------TABLE
TABLE
TABLE
TABLE
TABLE

16 rows selected.
SQL> describe jps.employee;
Name
----------------------------------------NAME
SSN
BDATE
SEX
SALARY
SUPERSSN
DNO

Null?
-------NOT NULL
NOT NULL

Type
---------------------------VARCHAR2(19)
CHAR(9)
DATE
CHAR(3)
NUMBER(8,2)
CHAR(9)
VARCHAR2(8)

Null?
-------NOT NULL
NOT NULL

Type
---------------------------VARCHAR2(15)
VARCHAR2(8)
CHAR(9)
DATE

Null?
-------NOT NULL
NOT NULL

Type
---------------------------CHAR(9)
VARCHAR2(15)
CHAR(3)
DATE
VARCHAR2(12)

SQL> describe jps.deptlocation;


Name
----------------------------------------DNUMBER
DLOCATION

Null?
-------NOT NULL
NOT NULL

Type
---------------------------VARCHAR2(8)
VARCHAR2(15)

SQL> describe jps.project;


Name

Null?

Type

SQL> describe jps.department;


Name
----------------------------------------DNAME
DNUMBER
MGRSSN
MGRSTARTDATE
SQL> describe jps.dependent;
Name
----------------------------------------ESSN
DEPENDENTNAME
SEX
BDATE
RELATIONSHIP

----------------------------------------- -------- ---------------------------PNAME


NOT NULL VARCHAR2(15)
PNUMBER
NOT NULL VARCHAR2(8)
PLOCATION
VARCHAR2(15)
DNUM
VARCHAR2(8)
SQL> describe jps.workson;
Name
----------------------------------------ESSN
PNO
HOURS

Null?
-------NOT NULL
NOT NULL

Type
---------------------------CHAR(9)
VARCHAR2(8)
NUMBER(5,1)

SQL> describe jps.r;


Name
Null?
----------------------------------------- -------A
B
C

Type
---------------------------CHAR(2)
CHAR(2)
CHAR(2)

SQL> describe jps.s;


Name
Null?
----------------------------------------- -------B
C
D

Type
---------------------------CHAR(2)
CHAR(2)
CHAR(2)

SQL> select *
2 from jps.employee;
NAME
------------------John B Smith
Franklin T Wong
Alicia J Zelaya
Jennifer S Wallace
Ramesh K Narayan
Joyce A English
Ahmad V Jabbar
James E Borg

SSN
--------123456789
333445555
999887777
987654321
666884444
453453453
987987987
888665555

BDATE
--------09-JAN-55
08-DEC-45
19-JUL-85
20-JUN-31
15-SEP-52
31-JUL-62
29-MAR-59
10-NOV-27

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
F
25000 987654321 4
F
43000 888665555 4
M
38000 333445555 5
F
25000 333445555 5
M
25000 987654321 4
M
55000
1

8 rows selected.
SQL> select *
2 from jps.department;
DNAME
--------------Research
Administration
Headquarters

DNUMBER
-------5
4
1

MGRSSN
--------333445555
987654321
888665555

MGRSTARTD
--------22-MAY-78
01-JAN-85
19-JUN-71

SQL> select *
2 from jps.dependent;
ESSN
--------333445555
333445555
333445555

DEPENDENTNAME
--------------Alice
Theodore
Joy

SEX
--F
M
F

BDATE
--------05-APR-76
25-OCT-73
03-MAY-48

RELATIONSHIP
-----------Daughter
Son
Spouse

987654321
123456789
123456789
123456789

Abner
Michael
Alice
Elizabeth

M
M
F
F

29-FEB-32
01-JAN-78
31-DEC-78
05-MAY-57

Spouse
Son
Daughter
Spouse

7 rows selected.
SQL> select *
2 from jps.deptlocation;
DNUMBER
-------1
4
5
5
5

DLOCATION
--------------Houston
Stafford
Bellaire
Houston
Sugarland

SQL> select *
2 from jps.project;
PNAME
--------------ProductX
ProductY
ProductZ
Computerization
Reorganization
Newbenefits

PNUMBER
-------1
2
3
10
20
30

PLOCATION
--------------Bellaire
Sugarland
Houston
Stafford
Houston
Stafford

6 rows selected.
SQL> select *
2 from jps.workson;
ESSN
--------123456789
123456789
666884444
453453453
453453453
333445555
333445555
333445555
333445555
999887777
999887777

PNO
HOURS
-------- ---------1
32.5
2
7.5
3
40
1
20
2
20
2
10
3
10
10
10
20
10
30
30
10
10

ESSN
--------987987987
987987987
987654321
987654321
888665555

PNO
HOURS
-------- ---------10
35
30
5
30
20
20
15
20

16 rows selected.
SQL> select *

DNUM
-------5
5
5
4
1
4

2 from jps.r;
A
-a1
a1

B
-b1
b2

C
-c1
c2

SQL> select *
2 from jps.s;
B
-b1
b1

C
-c1
c3

D
-d1
d2

SQL> select *
2 from jps.employee
3 where dno = 5;
NAME
------------------John B Smith
Franklin T Wong
Ramesh K Narayan
Joyce A English

SSN
--------123456789
333445555
666884444
453453453

BDATE
--------09-JAN-55
08-DEC-45
15-SEP-52
31-JUL-62

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
M
38000 333445555 5
F
25000 333445555 5

BDATE
--------08-DEC-45
20-JUN-31
15-SEP-52
10-NOV-27

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
40000 888665555 5
F
43000 888665555 4
M
38000 333445555 5
M
55000
1

SQL> select *
2 from jps.employee
3 where salary > 30000;
NAME
------------------Franklin T Wong
Jennifer S Wallace
Ramesh K Narayan
James E Borg

SSN
--------333445555
987654321
666884444
888665555

SQL> select *
2 from jps.employee
3 where sex = 'F' and salary > 30000;
NAME
SSN
BDATE
SEX
SALARY SUPERSSN DNO
------------------- --------- --------- --- ---------- --------- -------Jennifer S Wallace 987654321 20-JUN-31 F
43000 888665555 4
SQL> select *
2 from jps.workson w
3 where w.pno = 1 or w.pno = 2 or w.pno = 3;
ESSN
--------123456789
123456789
666884444
453453453
453453453
333445555
333445555

PNO
HOURS
-------- ---------1
32.5
2
7.5
3
40
1
20
2
20
2
10
3
10

7 rows selected.

SQL> select *
2 from jps.workson w
3 where w.pno in (1,2,3);
ESSN
--------123456789
123456789
666884444
453453453
453453453
333445555
333445555

PNO
HOURS
-------- ---------1
32.5
2
7.5
3
40
1
20
2
20
2
10
3
10

7 rows selected.
SQL> select e.name, e.ssn
2 from jps.employee e, jps.workson w
3 where w.pno in (1,2,3) and e.ssn = w.essn;
NAME
------------------John B Smith
John B Smith
Franklin T Wong
Franklin T Wong
Joyce A English
Joyce A English
Ramesh K Narayan

SSN
--------123456789
123456789
333445555
333445555
453453453
453453453
666884444

7 rows selected.
SQL>
2
3
4
5

select e.name, e.ssn


from jps.employee e
where e.ssn in (select w.essn
from jps.workson w
where w.pno in (1,2,3));

NAME
------------------John B Smith
Franklin T Wong
Joyce A English
Ramesh K Narayan
SQL>
2
3
4
5

SSN
--------123456789
333445555
453453453
666884444

select e.name, e.ssn


from jps.employee e
where e.ssn in (select w.essn
from jps.workson w
where w.pno not in (1,2,3));

NAME
------------------Franklin T Wong
James E Borg
Jennifer S Wallace
Ahmad V Jabbar
Alicia J Zelaya

SSN
--------333445555
888665555
987654321
987987987
999887777

SQL>
2
3
4
5

select e.name, e.ssn


from jps.employee e
where e.ssn not in (select w.essn
from jps.workson w
where w.pno in (1,2,3));

NAME
------------------James E Borg
Jennifer S Wallace
Ahmad V Jabbar
Alicia J Zelaya
SQL>
2
3
4
5

select e.name, e.ssn


from jps.employee e
where e.ssn not in (select w.essn
from jps.workson w
where w.pno in (1,2,3));

NAME
------------------James E Borg
Jennifer S Wallace
Ahmad V Jabbar
Alicia J Zelaya
SQL>
2
3
4
5
6

SSN
--------888665555
987654321
987987987
999887777

select e.name, e.ssn


from jps.employee e
where exists (select *
from jps.workson w
where w.pno in (1,2,3)
and e.ssn = w.essn);

NAME
------------------John B Smith
Franklin T Wong
Joyce A English
Ramesh K Narayan
SQL>
2
3
4
5
6

SSN
--------888665555
987654321
987987987
999887777

SSN
--------123456789
333445555
453453453
666884444

select e.name, e.ssn


from jps.employee e
where not exists (select *
from jps.workson w
where w.pno in (1,2,3)
and e.ssn = w.essn);

NAME
------------------James E Borg
Jennifer S Wallace
Ahmad V Jabbar
Alicia J Zelaya

SSN
--------888665555
987654321
987987987
999887777

SQL> select distinct (e.superssn)


2 from jps.employee e;
SUPERSSN
--------987654321

888665555
333445555
SQL> select *
2 from jps.employee e
3 where e.name like '%Wong';
NAME
SSN
BDATE
SEX
SALARY SUPERSSN DNO
------------------- --------- --------- --- ---------- --------- -------Franklin T Wong
333445555 08-DEC-45 M
40000 888665555 5
SQL> select *
2 from jps.employee e
3 where e.name like '%W%';
NAME
------------------Franklin T Wong
Jennifer S Wallace

SSN
--------333445555
987654321

BDATE
--------08-DEC-45
20-JUN-31

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
40000 888665555 5
F
43000 888665555 4

SQL> select name, ssn, salary


2 from jps.employee
3 where dno = 5;
NAME
------------------John B Smith
Franklin T Wong
Ramesh K Narayan
Joyce A English

SSN
SALARY
--------- ---------123456789
30000
333445555
40000
666884444
38000
453453453
25000

SQL> select *
2 from jps.department;
DNAME
--------------Research
Administration
Headquarters

DNUMBER
-------5
4
1

MGRSSN
--------333445555
987654321
888665555

MGRSTARTD
--------22-MAY-78
01-JAN-85
19-JUN-71

SQL> select *
2 from jps.employee;
NAME
------------------John B Smith
Franklin T Wong
Alicia J Zelaya
Jennifer S Wallace
Ramesh K Narayan
Joyce A English
Ahmad V Jabbar
James E Borg

SSN
--------123456789
333445555
999887777
987654321
666884444
453453453
987987987
888665555

BDATE
--------09-JAN-55
08-DEC-45
19-JUL-85
20-JUN-31
15-SEP-52
31-JUL-62
29-MAR-59
10-NOV-27

8 rows selected.

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
F
25000 987654321 4
F
43000 888665555 4
M
38000 333445555 5
F
25000 333445555 5
M
25000 987654321 4
M
55000
1

SQL> select dnumber, dname, mgrssn, name


2 from jps.department, jps.employee
3 where mgrssn = ssn;

DNUMBER
-------5
1
4

DNAME
--------------Research
Headquarters
Administration

MGRSSN
--------333445555
888665555
987654321

NAME
------------------Franklin T Wong
James E Borg
Jennifer S Wallace

SQL> select d.dnumber, d.dname, d.mgrssn, e.name


2 from jps.department d, jps.employee e
3 where d.mgrssn = e.ssn;
DNUMBER
-------5
1
4

DNAME
--------------Research
Headquarters
Administration

MGRSSN
--------333445555
888665555
987654321

NAME
------------------Franklin T Wong
James E Borg
Jennifer S Wallace

SQL> select * from jps.employee;


NAME
------------------John B Smith
Franklin T Wong
Alicia J Zelaya
Jennifer S Wallace
Ramesh K Narayan
Joyce A English
Ahmad V Jabbar
James E Borg

SSN
--------123456789
333445555
999887777
987654321
666884444
453453453
987987987
888665555

BDATE
--------09-JAN-55
08-DEC-45
19-JUL-85
20-JUN-31
15-SEP-52
31-JUL-62
29-MAR-59
10-NOV-27

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
F
25000 987654321 4
F
43000 888665555 4
M
38000 333445555 5
F
25000 333445555 5
M
25000 987654321 4
M
55000
1

8 rows selected.
SQL> select e.ssn, e.name, s.ssn, s.name
2 from jps.employee e, jps.employee s
3 where e.superssn = s.ssn;
SSN
--------666884444
123456789
453453453
333445555
987654321
999887777
987987987

NAME
------------------Ramesh K Narayan
John B Smith
Joyce A English
Franklin T Wong
Jennifer S Wallace
Alicia J Zelaya
Ahmad V Jabbar

SSN
--------333445555
333445555
333445555
888665555
888665555
987654321
987654321

NAME
------------------Franklin T Wong
Franklin T Wong
Franklin T Wong
James E Borg
James E Borg
Jennifer S Wallace
Jennifer S Wallace

7 rows selected.
SQL> select e.ssn, e.name, s.ssn, s.name
2 from jps.employee e, jps.employee s
3 where e.superssn = s.ssn (+);
SSN
--------453453453
666884444
123456789
987987987
999887777
987654321

NAME
------------------Joyce A English
Ramesh K Narayan
John B Smith
Ahmad V Jabbar
Alicia J Zelaya
Jennifer S Wallace

SSN
--------333445555
333445555
333445555
987654321
987654321
888665555

NAME
------------------Franklin T Wong
Franklin T Wong
Franklin T Wong
Jennifer S Wallace
Jennifer S Wallace
James E Borg

333445555 Franklin T Wong


888665555 James E Borg

888665555 James E Borg

8 rows selected.
SQL> select e.ssn, e.name, s.ssn, s.name
2 from jps.employee e, jps.employee s
3 where s.ssn (+) = e.superssn;
SSN
--------453453453
666884444
123456789
987987987
999887777
987654321
333445555
888665555

NAME
------------------Joyce A English
Ramesh K Narayan
John B Smith
Ahmad V Jabbar
Alicia J Zelaya
Jennifer S Wallace
Franklin T Wong
James E Borg

SSN
--------333445555
333445555
333445555
987654321
987654321
888665555
888665555

NAME
------------------Franklin T Wong
Franklin T Wong
Franklin T Wong
Jennifer S Wallace
Jennifer S Wallace
James E Borg
James E Borg

8 rows selected.
SQL>
2
3
4
5
6

select s.ssn as supervisorssn,


s.name as supervisorname,
e.ssn as employeessn,
e.name as employeename
from jps.employee e, jps.employee s
where s.ssn = e.superssn (+);

SUPERVISO
--------123456789
333445555
333445555
333445555
453453453
666884444
888665555
888665555
987654321
987654321
987987987

SUPERVISORNAME
------------------John B Smith
Franklin T Wong
Franklin T Wong
Franklin T Wong
Joyce A English
Ramesh K Narayan
James E Borg
James E Borg
Jennifer S Wallace
Jennifer S Wallace
Ahmad V Jabbar

EMPLOYEES EMPLOYEENAME
--------- ------------------666884444 Ramesh K Narayan
123456789 John B Smith
453453453 Joyce A English
333445555
987654321
999887777
987987987

Franklin T Wong
Jennifer S Wallace
Alicia J Zelaya
Ahmad V Jabbar

SUPERVISO SUPERVISORNAME
EMPLOYEES EMPLOYEENAME
--------- ------------------- --------- ------------------999887777 Alicia J Zelaya
12 rows selected.
SQL>
2
3
4
5
6

select e.ssn
from jps.employee e
where e.superssn in
(select s.ssn
from jps.employee s
where s.name = 'James E Borg');

SSN
--------333445555
987654321

SQL> J
SP2-0042: unknown command "J" - rest of line ignored.
SQL> select e.ssn
2 from jps.employee e
3 where e.superssn in
4 (select ssn
5 from jps.employee
6 where name = 'Franklin T Wong');
SSN
--------666884444
123456789
453453453
SQL>
2
3
4
5
6

select e.ssn
from jps.employee e
where superssn in
(select ssn
from jps.employee s
where s.name = 'Jennifer S Wallace');

SSN
--------999887777
987987987
SQL>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

select e1.ssn
from jps.employee e1
where e1.superssn in
(select s1.ssn
from jps.employee s1
where s1.name = 'James E Borg')
union
select e2.ssn
from jps.employee e2
where e2.superssn in
(select s2.ssn
from jps.employee s2
where s2.name = 'Franklin T Wong')
union
select e3.ssn
from jps.employee e3
where e3.superssn in
(select s3.ssn
from jps.employee s3
where s3.name = 'Jennifer S Wallace');

SSN
--------123456789
333445555
453453453
666884444
987654321
987987987
999887777
7 rows selected.

SQL>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

select e.ssn
from jps.employee e
where e.superssn in
(select s.ssn
from jps.employee s
where s.name = 'James E Borg')
union
select e1.ssn
from jps.employee e1
where e1.superssn in
(select s1.ssn
from jps.employee s1
where s1.superssn in
(select s2.ssn
from jps.employee s2
where s2.name = 'James E Borg'));

SSN
--------123456789
333445555
453453453
666884444
987654321
987987987
999887777
7 rows selected.
SQL>
2
3
4
5
6

select e.ssn
from jps.employee e
where e.superssn in
(select s.ssn
from jps.employee s
where s.name = 'James E Borg');

SSN
--------333445555
987654321
SQL>
2
3
4
5
6
7
8
9

select e1.ssn
from jps.employee e1
where e1.superssn in
(select s1.ssn
from jps.employee s1
where s1.superssn in
(select s2.ssn
from jps.employee s2
where s2.name = 'James E Borg'));

SSN
--------123456789
999887777
666884444
453453453
987987987

SQL>
SQL>
SQL> select lpad(' ', (level - 1) * 2) || ssn as padded_ssn
2 from jps.employee
3 connect by prior ssn = superssn
4 start with ssn in (select ssn
5 from jps.employee
6 where name = 'James E Borg')
7
SQL> select lpad(' ', (level - 1) * 2) || ssn as padded_ssn
from jps.employee
connect by prior ssn = superssn
start with ssn in (select ssn from jps.employee where name = 'James E Borg');
2
3
4
PADDED_SSN
-------------------------------------------------------------------------------888665555
333445555
123456789
453453453
666884444
987654321
987987987
999887777
8 rows selected.
SQL>
2
3
4

select e.ssn
from jps.employee e
start with e.name = 'Franklin T Wong'
connect by e.superssn = prior e.ssn;

SSN
--------333445555
123456789
453453453
666884444
SQL>
2
3
4

select e.ssn
from jps.employee e
start with e.name = 'Jennifer S Wallace'
connect by e.superssn = prior e.ssn;

SSN
--------987654321
987987987
999887777
SQL>
2
3
4
5
6
7
SQL>

select lpad(' ', (level - 1) * 2) || ssn as padded_ssn


from jps.employee e
connect by prior ssn = superssn
start with ssn in (select ssn
from jps.employee
where name = 'James E Borg')
select 1pad(' ', (level - 1) * 2) || ssn as padded_ssn

2 from jps.employee e
3 connect by prior ssn = superssn
4 start with ssn in (select ssn
5 from jps.employee
6 where name = 'James E Borg')
7
SQL> select lpad(' ', (level - 1) * 2) || ssn as padded_ssn
from jps.employee e
connect by prior ssn = superssn
start with ssn in (select ssn
from jps.employee
where name = 'James E Borg'); 2
3
4
5
6
PADDED_SSN
-------------------------------------------------------------------------------888665555
333445555
123456789
453453453
666884444
987654321
987987987
999887777
8 rows selected.
SQL> select e.ssn
from jps.employee e
intersect
select d.essn
from jps.dependent d; 2

SSN
--------123456789
333445555
987654321
SQL> select e.ssn
from jps.employee e
minus
select d.essn
from jps.dependent d; 2
SSN
--------453453453
666884444
888665555
987987987
999887777
SQL>
2
3
4
5
6
7
8

select ssn,name
from jps.employee e
where not exists ((select pnumber
from jps.project
where dnum = 5)
minus
(select pno
from jps.workson w

9 where e.ssn = w.essn));


no rows selected
SQL> select pnumber
2 from jps.project
3 where dnum = 5;
PNUMBER
-------1
2
3
SQL> select pno
2 from jps.workson w
3 where e.ssn = w.essn);
where e.ssn = w.essn)
*
ERROR at line 3:
ORA-00933: SQL command not properly ended
SQL>
select pno
2 from jps.workson w
3 where e.ssn = w.essn);
where e.ssn = w.essn)
*
ERROR at line 3:
ORA-00933: SQL command not properly ended
SQL> select pno
2 from jps.workson w
3 where e.ssn = w.essn);
where e.ssn = w.essn)
*
ERROR at line 3:
ORA-00933: SQL command not properly ended
SQL>
2
3
4
5
6
7
8
9
10

select ssn,name
from jps.employee e
where not exists ((select pno
from jps.workson w1, jps.employee e1
where e1.name = 'John B Smith'
and e1.ssn = w1.essn)
minus
(select pno
from jps.workson w
where e.ssn = w.essn));

SSN
--------123456789
453453453

NAME
------------------John B Smith
Joyce A English

SQL> select *
2 2 from jps.R;

2 from jps.R
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
SQL> select *
2 from jps.R;
A
-a1
a1

B
-b1
b2

C
-c1
c2

SQL> select *
2 from jps.S;
B
-b1
b1

C
-c1
c3

D
-d1
d2

SQL> select *
2 from jps.R cross join jps.S;
A
-a1
a1
a1
a1

B
-b1
b1
b2
b2

C
-c1
c1
c2
c2

B
-b1
b1
b1
b1

C
-c1
c3
c1
c3

D
-d1
d2
d1
d2

SQL> select *
2 from jps.R join jps.S on jps.R.B = jps.S.B;
A
-a1
a1

B
-b1
b1

C
-c1
c1

B
-b1
b1

C
-c1
c3

D
-d1
d2

SQL> select *
2 from jps.R join jps.S on jps.R.C = jps.S.C;
A B C B C D
-- -- -- -- -- -a1 b1 c1 b1 c1 d1
SQL> select *
2 from jps.R inner join jps.S on jps.R.C = jps.S.C;
A B C B C D
-- -- -- -- -- -a1 b1 c1 b1 c1 d1
SQL> select *
2 from jps.R natural join jps.S;
B C A D
-- -- -- -b1 c1 a1 d1

SQL> select A, B, C, D
2 from jps.R natural join jps.S;
A B C D
-- -- -- -a1 b1 c1 d1
SQL> select *
2 from jps.R left outer join jps.S on jps.R.B = jps.S.B;
A
-a1
a1
a1

B
-b1
b1
b2

C
-c1
c1
c2

B
-b1
b1

C
-c1
c3

D
-d1
d2

SQL> select *
2 from jps.R left outer join jps.S on jps.R.C = jps.S.C;
A
-a1
a1

B
-b1
b2

C B C D
-- -- -- -c1 b1 c1 d1
c2

SQL> select *
2 from jps.R right outer join jps.S on jps.R.B = jps.S.B;
A
-a1
a1

B
-b1
b1

C
-c1
c1

B
-b1
b1

C
-c3
c1

D
-d2
d1

SQL> select *
2 from jps.R right outer join jps.S on jps.R.C = jps.S.C;
A B C B
-- -- -- -a1 b1 c1 b1
b1

C
-c1
c3

D
-d1
d2

SQL> select *
2 from jps.R full outer join jps.S on jps.R.B = jps.S.B;
A
-a1
a1
a1

B
-b1
b1
b2

C
-c1
c1
c2

B
-b1
b1

C
-c1
c3

D
-d1
d2

SQL> select *
2 from jps.R full outer join jps.S on jps.R.C = jps.S.C;
A B C B
-- -- -- -a1 b1 c1 b1
b1
a1 b2 c2

C
-c1
c3

SQL> select *

D
-d1
d2

2
3

from jps.R full outer join jps.S


on jps.R.B = jps.S.B and jps.R.C = jps.S.C;

A B C B
-- -- -- -a1 b1 c1 b1
b1
a1 b2 c2

C
-c1
c3

D
-d1
d2

SQL> select avg(salary),min(salary),max(salary),sum(salary)


2 from jps.employee;
AVG(SALARY) MIN(SALARY) MAX(SALARY) SUM(SALARY)
----------- ----------- ----------- ----------35125
25000
55000
281000
SQL> select count(ssn), avg(salary), sum(salary)
2 from jps.employee
3 where dno = 5;
COUNT(SSN) AVG(SALARY) SUM(SALARY)
---------- ----------- ----------4
33250
133000
SQL> select dno, count(ssn), avg(salary), sum(salary)
2 from jps.employee
3 group by dno;
DNO
COUNT(SSN) AVG(SALARY) SUM(SALARY)
-------- ---------- ----------- ----------1
1
55000
55000
5
4
33250
133000
4
3
31000
93000
SQL>
2
3
4

select dno, count(ssn), avg(salary), sum(salary)


from jps.employee
group by dno
having count(ssn) > 1;

DNO
COUNT(SSN) AVG(SALARY) SUM(SALARY)
-------- ---------- ----------- ----------5
4
33250
133000
4
3
31000
93000
SQL>
2
3
4
5
6
7
8
9

create table EMPLOYEE


( name varchar2(19) not null,
ssn char (9),
bdate date,
sex char(3),
salary number(8,2),
superssn char(9),
dno varchar(8),
constraint empPK primary key (ssn));

Table created.
SQL> insert into EMPLOYEE values
2 ('John B Smith','123456789','09-JAN 55','M',30000,'333445555','5');
1 row created.

SQL> insert into EMPLOYEE values


2 ('Franklin T Wong','333445555','08-DEC-45','M',40000,'888665555','5');
1 row created.
SQL> insert into EMPLOYEE values
2 ('Alicia J Zelaya','999887777','19-JUL-85','F',25000,'987654321','4');
1 row created.
SQL> insert into EMPLOYEE values
2 ('Jennifer S Wallace','987654321','20-JUN-31','F',43000,'888665555','4');
1 row created.
SQL> insert into EMPLOYEE values
2 ('Ramesh K Narayan','666884444','15-SEP-52','M',38000,'333445555','5');
1 row created.
SQL> insert into EMPLOYEE values
2 ('Joyce A English','453453453','31-JUL-62','F',25000,'333445555','5');
1 row created.
SQL> insert into EMPLOYEE values
2 ('Ahmad V Jabbar','987987987','29-MAR-59','M',25000,'987654321','4');
1 row created.
SQL> insert into EMPLOYEE values
2 ('James E Borg','888665555','10-NOV-27','M',55000,' ','1');
1 row created.
SQL> insert into employee
2 select * from jps.employee
3
SQL> delete from employee;
8 rows deleted.
SQL>
SQL> insert into employee
2 select * from jps.employee;
8 rows created.
SQL> delete from employee;
8 rows deleted.
SQL> insert into employee
2 select * from jps.employee;
8 rows created.
SQL> select * from employee;

NAME
------------------John B Smith
Franklin T Wong
Alicia J Zelaya
Jennifer S Wallace
Ramesh K Narayan
Joyce A English
Ahmad V Jabbar
James E Borg

SSN
--------123456789
333445555
999887777
987654321
666884444
453453453
987987987
888665555

BDATE
--------09-JAN-55
08-DEC-45
19-JUL-85
20-JUN-31
15-SEP-52
31-JUL-62
29-MAR-59
10-NOV-27

SEX
SALARY SUPERSSN DNO
--- ---------- --------- -------M
30000 333445555 5
M
40000 888665555 5
F
25000 987654321 4
F
43000 888665555 4
M
38000 333445555 5
F
25000 333445555 5
M
25000 987654321 4
M
55000
1

8 rows selected.
SQL> delete from employee
2 where name = 'Franklin T Wong';
1 row deleted.
SQL> select owner, constraint_name
2 from user_constraints
3 where owner = 'JPS' and table_name = 'EMPLOYEE';
no rows selected
SQL> select owner, constraint_name
2 from all_constraints
3 where owner = 'JPS' and table_name = 'EMPLOYEE';
OWNER
-----------------------------JPS
JPS
JPS

CONSTRAINT_NAME
-----------------------------EMPSUPERFRK
EMPPK
SYS_C0011008

SQL> drop table employee;


Table dropped.
SQL> drop table employee cascade constraints;
drop table employee cascade constraints
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> drop table employee cascade constraints;
drop table employee cascade constraints
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> flashback table employee to before drop;
Flashback complete.
SQL>
SQL> purge recyclebin;
Recyclebin purged.

SQL> drop table employee purge;


Table dropped.
SQL> spool off

Vous aimerez peut-être aussi