Professional Documents
Culture Documents
DBMS LAB 22-09-2020 @11.30 View All Public Scripts Login to Run Script
Contributor
Statement
REM Script: EMP and DEPT
1
Script: EMP and DEPT
Statement
REM Example EMP and DEPT tables. Classic Oracle tables with 4 departments and 14 employees. Includes a j
2
Example EMP and DEPT tables. Classic Oracle tables with 4 departments and 14 employees. Includes a join
query example.
Statement
create table dept(
3 deptno number(2,0),
dname varchar2(14),
loc varchar2(13),
constraint pk_dept primary key (deptno)
)
Table created.
Statement
create table emp(
4 empno number(4,0),
ename varchar2(10),
job varchar2(9),
mgr number(4,0),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2,0),
constraint pk_emp primary key (empno),
constraint fk_deptno foreign key (deptno) references dept (deptno)
)
Table created.
/
Statement
insert into DEPT (DEPTNO, DNAME, LOC)
5 values(10, 'ACCOUNTING', 'NEW YORK')
1 row(s) inserted.
Statement
insert into dept
6 values(20, 'RESEARCH', 'DALLAS')
1 row(s) inserted.
Statement
insert into dept
7 values(30, 'SALES', 'CHICAGO')
1 row(s) inserted.
Statement
insert into dept
8 values(40, 'OPERATIONS', 'BOSTON')
1 row(s) inserted.
Statement
insert into emp
9 values(
7839, 'KING', 'PRESIDENT', null,
to_date('17-11-1981','dd-mm-yyyy'),
5000, null, 10
)
1 row(s) inserted.
Statement
insert into emp
10 values(
7698, 'BLAKE', 'MANAGER', 7839,
to_date('1-5-1981','dd-mm-yyyy'),
2850, null, 30
)
1 row(s) inserted.
Statement
insert into emp
11 values(
7782, 'CLARK', 'MANAGER', 7839,
to_date('9-6-1981','dd-mm-yyyy'),
2450, null, 10
)
1 row(s) inserted.
Statement
insert into emp
12 values(
7566, 'JONES', 'MANAGER', 7839,
to_date('2-4-1981','dd-mm-yyyy'),
/
2975, null, 20
)
1 row(s) inserted.
Statement
insert into emp
13 values(
7788, 'SCOTT', 'ANALYST', 7566,
to_date('13-JUL-87','dd-mm-rr') - 85,
3000, null, 20
)
1 row(s) inserted.
Statement
insert into emp
14 values(
7902, 'FORD', 'ANALYST', 7566,
to_date('3-12-1981','dd-mm-yyyy'),
3000, null, 20
)
1 row(s) inserted.
Statement
insert into emp
15 values(
7369, 'SMITH', 'CLERK', 7902,
to_date('17-12-1980','dd-mm-yyyy'),
800, null, 20
)
1 row(s) inserted.
Statement
insert into emp
16 values(
7499, 'ALLEN', 'SALESMAN', 7698,
to_date('20-2-1981','dd-mm-yyyy'),
1600, 300, 30
)
1 row(s) inserted.
Statement
insert into emp
17 values(
7521, 'WARD', 'SALESMAN', 7698,
to_date('22-2-1981','dd-mm-yyyy'),
1250, 500, 30
)
1 row(s) inserted.
Statement
insert into emp
18 values(
7654, 'MARTIN', 'SALESMAN', 7698,
to_date('28-9-1981','dd-mm-yyyy'),
/
1250, 1400, 30
)
1 row(s) inserted.
Statement
insert into emp
19 values(
7844, 'TURNER', 'SALESMAN', 7698,
to_date('8-9-1981','dd-mm-yyyy'),
1500, 0, 30
)
1 row(s) inserted.
Statement
insert into emp
20 values(
7876, 'ADAMS', 'CLERK', 7788,
to_date('13-JUL-87', 'dd-mm-rr') - 51,
1100, null, 20
)
1 row(s) inserted.
Statement
insert into emp
21 values(
7900, 'JAMES', 'CLERK', 7698,
to_date('3-12-1981','dd-mm-yyyy'),
950, null, 30
)
1 row(s) inserted.
Statement
insert into emp
22 values(
7934, 'MILLER', 'CLERK', 7782,
to_date('23-1-1982','dd-mm-yyyy'),
1300, null, 10
)
1 row(s) inserted.
Statement
select* from tab
23
DBMS_XPLAN SYNONYM -
DEPT TABLE -
EMP TABLE -
V$SESSION SYNONYM -
V$SQL SYNONYM -
V$SQLSTATS SYNONYM -
V$SQL_PLAN SYNONYM -
/
V$SQL_PLAN_STATISTICS_ALL SYNONYM -
8 rows selected.
Statement
select*
24 from emp
14 rows selected.
Statement
REM Script: EMP and DEPT
25
Script: EMP and DEPT
Statement
REM Example EMP and DEPT tables. Classic Oracle tables with 4 departments and 14 employees. Includes a j
26
Example EMP and DEPT tables. Classic Oracle tables with 4 departments and 14 employees. Includes a join
query example.
Statement
create table dept(
27 deptno number(2,0),
dname varchar2(14),
loc varchar2(13),
constraint pk_dept primary key (deptno)
)
Statement
create table emp(
28 empno number(4,0),
ename varchar2(10),
job varchar2(9),
/
mgr number(4,0),
hiredate date,
sal number(7,2),
comm number(7,2),
deptno number(2,0),
constraint pk_emp primary key (empno),
constraint fk_deptno foreign key (deptno) references dept (deptno)
)
Statement
insert into DEPT (DEPTNO, DNAME, LOC)
29 values(10, 'ACCOUNTING', 'NEW YORK')
Statement
insert into dept
30 values(20, 'RESEARCH', 'DALLAS')
Statement
insert into dept
31 values(30, 'SALES', 'CHICAGO')
Statement
insert into dept
32 values(40, 'OPERATIONS', 'BOSTON')
Statement
insert into emp
33 values(
7839, 'KING', 'PRESIDENT', null,
to_date('17-11-1981','dd-mm-yyyy'),
5000, null, 10
)
Statement
insert into emp
34 values(
7698, 'BLAKE', 'MANAGER', 7839,
to_date('1-5-1981','dd-mm-yyyy'),
/
2850, null, 30
)
Statement
insert into emp
35 values(
7782, 'CLARK', 'MANAGER', 7839,
to_date('9-6-1981','dd-mm-yyyy'),
2450, null, 10
)
Statement
insert into emp
36 values(
7566, 'JONES', 'MANAGER', 7839,
to_date('2-4-1981','dd-mm-yyyy'),
2975, null, 20
)
Statement
insert into emp
37 values(
7788, 'SCOTT', 'ANALYST', 7566,
to_date('13-JUL-87','dd-mm-rr') - 85,
3000, null, 20
)
Statement
insert into emp
38 values(
7902, 'FORD', 'ANALYST', 7566,
to_date('3-12-1981','dd-mm-yyyy'),
3000, null, 20
)
Statement
insert into emp
39 values(
7369, 'SMITH', 'CLERK', 7902,
to_date('17-12-1980','dd-mm-yyyy'),
800, null, 20
)
/
ORA-00001: unique constraint (SQL_LASSCZJLGWLVYLHNPQFOOAOZY.PK_EMP) violated ORA-06512: at "SYS.DBMS_SQL",
line 1721
Statement
insert into emp
40 values(
7499, 'ALLEN', 'SALESMAN', 7698,
to_date('20-2-1981','dd-mm-yyyy'),
1600, 300, 30
)
Statement
insert into emp
41 values(
7521, 'WARD', 'SALESMAN', 7698,
to_date('22-2-1981','dd-mm-yyyy'),
1250, 500, 30
)
Statement
insert into emp
42 values(
7654, 'MARTIN', 'SALESMAN', 7698,
to_date('28-9-1981','dd-mm-yyyy'),
1250, 1400, 30
)
Statement
insert into emp
43 values(
7844, 'TURNER', 'SALESMAN', 7698,
to_date('8-9-1981','dd-mm-yyyy'),
1500, 0, 30
)
Statement
insert into emp
44 values(
7876, 'ADAMS', 'CLERK', 7788,
to_date('13-JUL-87', 'dd-mm-rr') - 51,
1100, null, 20
)
/
ORA-00001: unique constraint (SQL_LASSCZJLGWLVYLHNPQFOOAOZY.PK_EMP) violated ORA-06512: at "SYS.DBMS_SQL",
line 1721
Statement
insert into emp
45 values(
7900, 'JAMES', 'CLERK', 7698,
to_date('3-12-1981','dd-mm-yyyy'),
950, null, 30
)
Statement
insert into emp
46 values(
7934, 'MILLER', 'CLERK', 7782,
to_date('23-1-1982','dd-mm-yyyy'),
1300, null, 10
)
Statement
select* from tab
47
DBMS_XPLAN SYNONYM -
DEPT TABLE -
EMP TABLE -
V$SESSION SYNONYM -
V$SQL SYNONYM -
V$SQLSTATS SYNONYM -
V$SQL_PLAN SYNONYM -
V$SQL_PLAN_STATISTICS_ALL SYNONYM -
8 rows selected.
Statement
select*
48 from emp
14 rows selected.
Statement
select ename
49 from emp
ENAME
KING
BLAKE
CLARK
JONES
SCOTT
FORD
SMITH
ALLEN
WARD
MARTIN
TURNER
ADAMS
JAMES
MILLER
14 rows selected.
Statement
select*
50 from dept
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
4 rows selected.
Statement
insert into dept values(60,'Computers','DALLAS')
51
1 row(s) inserted.
/
Statement
52 select*
from dept
60 Computers DALLAS
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
5 rows selected.
Statement
select distict loc
53 from dept
Statement
select distinct loc
54 from dept
LOC
NEW YORK
DALLAS
CHICAGO
BOSTON
4 rows selected.
Statement
select distinct loc as Dept_Location
55 from dept
DEPT_LOCATION
NEW YORK
DALLAS
CHICAGO
BOSTON
4 rows selected.
Statement
select *
56 from emp
14 rows selected.
Statement
select ename,sal
57 from emp
where deptno=20
ENAME SAL
JONES 2975
SCOTT 3000
FORD 3000
SMITH 800
ADAMS 1100
5 rows selected.
Statement
select ename,sal,deptno
58 from emp
where deptno=20
JONES 2975 20
SCOTT 3000 20
FORD 3000 20
SMITH 800 20
ADAMS 1100 20
5 rows selected.
Statement
select ename,sal,deptno
59 from emp
where deptno<>20
KING 5000 10
BLAKE 2850 30
CLARK 2450 10
/
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
TURNER 1500 30
JAMES 950 30
MILLER 1300 10
9 rows selected.
Statement
select ename,sal,deptno
60 from emp
where sal>3000
KING 5000 10
Statement
select ename,sal,deptno
61 from emp
where sal<=3000
BLAKE 2850 30
CLARK 2450 10
JONES 2975 20
SCOTT 3000 20
FORD 3000 20
SMITH 800 20
ALLEN 1600 30
WARD 1250 30
MARTIN 1250 30
TURNER 1500 30
ADAMS 1100 20
JAMES 950 30
MILLER 1300 10
13 rows selected.
Statement
select ename,sal,deptno
62 from emp
where sal>=3000
KING 5000 10
SCOTT 3000 20
FORD 3000 20
3 rows selected.
/
Statement select ename,sal,deptno
63 from emp
where sal>=3000
KING 5000 10
SCOTT 3000 20
FORD 3000 20
3 rows selected.
Statement
select ename,sal,deptno
64 from emp
where sal>=3000
KING 5000 10
SCOTT 3000 20
FORD 3000 20
3 rows selected.
Statement
select ename
65 from emp
where sal>2500 and deptno=20
ENAME
JONES
SCOTT
FORD
3 rows selected.
Statement
select ename
66 from emp
where sal>=2500 and deptno=20
ENAME
JONES
SCOTT
FORD
3 rows selected.
Statement
select ename
67 from emp
where sal>=2500 or deptno=20
ENAME /
KING
BLAKE
JONES
SCOTT
FORD
SMITH
ADAMS
7 rows selected.
Statement
select ename
68 from emp
where sal>=2500 and deptno=20
ENAME
JONES
SCOTT
FORD
3 rows selected.
Statement
SELECT ename
69 FROM emp
WHERE JOB IN('ANALYST', 'CLERK', 'PRESIDENT', 'MANAGER')
ENAME
KING
BLAKE
CLARK
JONES
SCOTT
FORD
SMITH
ADAMS
JAMES
MILLER
10 rows selected.
Statement
SELECT ename
70 FROM emp
WHERE ename like 'B%'
ENAME
BLAKE
/
Statement
71 SELECT ename
FROM emp
WHERE ename like '%A%'
ENAME
BLAKE
CLARK
ALLEN
WARD
MARTIN
ADAMS
JAMES
7 rows selected.
Statement
SELECT ename
72 FROM emp
WHERE ename like '_A%'
ENAME
WARD
MARTIN
JAMES
3 rows selected.
Statement
SELECT ename
73 FROM emp
WHERE ename like '__A_A%'
no data found
Additional Information