You are on page 1of 21

SQL> create table kumar_details (firstname varchar2(2), lastname varchar2(10), a

ddress varchar(25), age number(3), desgination varchar(10));


Table created.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(2)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(10)
SQL> alter table kumar_details modify(firstname varchar2(10));
Table altered.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(10)
SQL> alter table kumar_details add(salary number(5,2);
alter table kumar_details add(salary number(5,2)
*
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> alter table kumar_details add(salary number(7,2);


alter table kumar_details add(salary number(7,2)
*
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> alter table kumar_details add(salary number(7,2));


Table altered.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(10)
SALARY NUMBER(7,2)
SQL> alter table kumar_details drop(salary);
Table altered.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(10)
SQL> insert into kumar_details(firstname, lastname, address, age, desgination) v
alues('kumar','a', 'afaasdfsdf', 35,'Test Engineer');
insert into kumar_details(firstname, lastname, address, age, desgination) values
('kumar','a', 'afaasdfsdf', 35,'Test Engineer')
*
ERROR at line 1:
ORA-12899: value too large for column "SCOTT"."KUMAR_DETAILS"."DESGINATION" (act
ual: 13, maximum:
10)

SQL> insert into kumar_details(firstname, lastname, address, age)values('kumar',


'a', 'afaasdfsdf', 35);
1 row created.
SQL> alter table kumar_details modify(desgination varchar2(20));
Table altered.
SQL> insert into kumar_details(designation) values('Test Engineer");
ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into kumar_details(designation) values('Test Engineer');


insert into kumar_details(designation) values('Test Engineer')
*
ERROR at line 1:
ORA-00904: "DESIGNATION": invalid identifier

SQL> insert into kumar_details(desgination) values('Test Engineer");


ERROR:
ORA-01756: quoted string not properly terminated

SQL> insert into kumar_details(desgination) values('Test Engineer');


1 row created.
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION
---------- ---------- ------------------------- ---------- --------------------
kumar a afaasdfsdf 35
Test Engineer

SQL> update table kumar_deatils set desgination='Test Engineer" where age=35;


ERROR:
ORA-01756: quoted string not properly terminated

SQL> update table kumar_deatils set desgination='Test Engineer' where age=35;


update table kumar_deatils set desgination='Test Engineer' where age=35
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> update table kumar_details set desgination='Test Engineer' where age=35;


update table kumar_details set desgination='Test Engineer' where age=35
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> alter table kumar_details modify(desgination varchar2(15));


Table altered.
SQL> update table kumar_details set desgination='Test Engineer' where age=35;
update table kumar_details set desgination='Test Engineer' where age=35
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> updatekumar_details set desgination='Test Engineer' where age=35;


SP2-0734: unknown command beginning "updatekuma..." - rest of line ignored.
SQL> update kumar_details set desgination='Test Engineer' where age=35;
1 row updated.
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION

---------- ---------- ------------------------- ---------- ---------------


kumar a afaasdfsdf 35 Test Engineer
Test Engineer

SQL> update kumar_details set firstname='faroz', lastname='basha', address='afaf


asdfasd', age=31, wh
2
SQL> update kumar_details set firstname='faroz', lastname='basha', address='afa
fasdfasd', age=31 were
2
SQL> update kumar_details set firstname='faroz', lastname='basha', address='afaf
asdfasd', age=31
2 where desgination ='Test Engineer';
2 rows updated.
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION
---------- ---------- ------------------------- ---------- ---------------
faroz basha afafasdfasd 31 Test Engineer
faroz basha afafasdfasd 31 Test Engineer

SQL>
SQL> /
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION
---------- ---------- ------------------------- ---------- ---------------
faroz basha afafasdfasd 31 Test Engineer
faroz basha afafasdfasd 31 Test Engineer

SQL> /
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION
---------- ---------- ------------------------- ---------- ---------------
faroz basha afafasdfasd 31 Test Engineer
faroz basha afafasdfasd 31 Test Engineer

SQL> \
SP2-0042: unknown command "\" - rest of line ignored.
SQL> /
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION
---------- ---------- ------------------------- ---------- ---------------
faroz basha afafasdfasd 31 Test Engineer
faroz basha afafasdfasd 31 Test Engineer

SQL> edit
Wrote file afiedt.buf
1* select * from kumar_details
SQL> edit
Wrote file afiedt.buf
1* alter table kumar_details add(Emp_id varchar(5)
2 );
Table altered.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(15)
EMP_ID VARCHAR2(5)
SQL> /
alter table kumar_details add(Emp_id varchar(5)
*
ERROR at line 1:
ORA-01430: column being added already exists in table

SQL> edit
Wrote file afiedt.buf
1 alter table kumar_details add(Emp_id varchar(5)
2* )
SQL>
SQL> edit
Wrote file afiedt.buf
1* select * from kumar_details;
2 \
3
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION EMP_I
---------- ---------- ------------------------- ---------- --------------- -----
faroz basha afafasdfasd 31 Test Engineer
faroz basha afafasdfasd 31 Test Engineer

SQL> update kumar_details set ADDRESS="gbpalaya"


2
SQL>
SQL> truncate table kumar_details;
Table truncated.
SQL> select * from kumar_details;
no rows selected
SQL> insert into kumar_details value('&a','&b','&c', &d, '&e','&f');
Enter value for a: kumar
Enter value for b: a
Enter value for c: adfasf
Enter value for d: 35
Enter value for e: Test Engineer
Enter value for f: MI025
old 1: insert into kumar_details value('&a','&b','&c', &d, '&e','&f')
new 1: insert into kumar_details value('kumar','a','adfasf', 35, 'Test Enginee
r','MI025')
insert into kumar_details value('kumar','a','adfasf', 35, 'Test Engineer','MI025
')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> select * from kumar_details;


no rows selected
SQL> desc kumar_details
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(15)
EMP_ID VARCHAR2(5)
SQL> insert into kumar_details value('kumar','a','adfasf',35,'Test Engineer','MI
025');
insert into kumar_details value('kumar','a','adfasf',35,'Test Engineer','MI025')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> insert into kumar_details value('kumar','a','adfasf',35,'Test Engineer','02


5');
insert into kumar_details value('kumar','a','adfasf',35,'Test Engineer','025')
*
ERROR at line 1:
ORA-00928: missing SELECT keyword

SQL> insert into kumar_details values('kumar','a','adfasf',35,'Test Engineer','0


25');
1 row created.
SQL> alter table kumar_details modify(Emp_id varchar(10));
Table altered.
SQL> insert into kumar_details values('faroz','basha','adfas',31,'Test Engineer
','MI035');
1 row created.
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION EMP_I
D
---------- ---------- ------------------------- ---------- --------------- -----
-----
kumar a adfasf 35 Test Engineer 025
faroz basha adfas 31 Test Engineer MI035

SQL> delete table kumar_details where age=31;


delete table kumar_details where age=31
*
ERROR at line 1:
ORA-00903: invalid table name

SQL> delete kumar_details where age=31;


1 row deleted.
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION EMP_I
D
---------- ---------- ------------------------- ---------- --------------- -----
-----
kumar a adfasf 35 Test Engineer 025

SQL> drop table kumar_details;


Table dropped.
SQL> rollback
2
SQL> select * from kumar_details;
select * from kumar_details
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> create table kumar_details (firstname varchar2(2), lastname varchar2(10),


address varchar(25),age number(3), desgination varchar(10));
Table created.
SQL> alter table kumar_details add(Emp_id varchar(5));
Table altered.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(2)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(10)
EMP_ID VARCHAR2(5)
SQL> insert into kumar_details values('faroz','basha','adfas',31,'Test Engineer'
,'MI035');
insert into kumar_details values('faroz','basha','adfas',31,'Test Engineer','MI0
35')
*
ERROR at line 1:
ORA-12899: value too large for column "SCOTT"."KUMAR_DETAILS"."FIRSTNAME" (actua
l: 5, maximum: 2)

SQL> alter table kumar_details modify(fistname varchar2(10));


alter table kumar_details modify(fistname varchar2(10))
*
ERROR at line 1:
ORA-00904: "FISTNAME": invalid identifier

SQL> alter table kumar_details modify(firstname varchar2(10));


Table altered.
SQL> insert into kumar_details values('faroz','basha','adfas',31,'Test Engineer'
,'MI035');
insert into kumar_details values('faroz','basha','adfas',31,'Test Engineer','MI0
35')
*
ERROR at line 1:
ORA-12899: value too large for column "SCOTT"."KUMAR_DETAILS"."DESGINATION" (act
ual: 13, maximum:
10)

SQL> alter table kumar_details modify(desgination varchar2(15));


Table altered.
SQL> insert into kumar_details values('faroz','basha','adfas',31,'Test Engineer'
,'MI035');
1 row created.
SQL> insert into kumar_details values('kumar','a','adfasf',35,'Test Engineer','0
25');
1 row created.
SQL> select * from kumar_details;
FIRSTNAME LASTNAME ADDRESS AGE DESGINATION EMP_I
---------- ---------- ------------------------- ---------- --------------- -----
faroz basha adfas 31 Test Engineer MI035
kumar a adfasf 35 Test Engineer 025

SQL> desc kumar_details;


Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(15)
EMP_ID VARCHAR2(5)
SQL> alter table kumar_details modify(Emp_id varchar2(5) primary key);
Table altered.
SQL> desc kumar_details;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
FIRSTNAME VARCHAR2(10)
LASTNAME VARCHAR2(10)
ADDRESS VARCHAR2(25)
AGE NUMBER(3)
DESGINATION VARCHAR2(15)
EMP_ID NOT NULL VARCHAR2(5)
SQL> select distinct(Desgination) from kumar_details;
DESGINATION
---------------
Test Engineer

SQL> select distinct(firstname) from kumar_details;


FIRSTNAME
----------
kumar
faroz

SQL> select distinct(firstname,age) from kumar_detail;s


2
SQL> select distinct(firstname,age) from kumar_details;
select distinct(firstname,age) from kumar_details
*
ERROR at line 1:
ORA-00907: missing right parenthesis

SQL> select * from kumar_details;


FIRSTNAME LASTNAME ADDRESS AGE DESGINATION EMP_I
---------- ---------- ------------------------- ---------- --------------- -----
faroz basha adfas 31 Test Engineer MI035
kumar a adfasf 35 Test Engineer 025

SQL> select address as resident from kumar_detailsl;


select address as resident from kumar_detailsl
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> select address as resident from kumar_details;


RESIDENT
-------------------------
adfas
adfasf

SQL> select firstname,lastname, address as resident, age, desgination, emp_id fr


om kumar_details;
FIRSTNAME LASTNAME RESIDENT AGE DESGINATION EMP_I
---------- ---------- ------------------------- ---------- --------------- -----
faroz basha adfas 31 Test Engineer MI035
kumar a adfasf 35 Test Engineer 025

SQL> select * from emp;


EMPNO ENAME JOB MGR HIREDATE SAL COMM D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
-----
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10
14 rows selected.
SQL> select salary, salary+3000 from emp;
select salary, salary+3000 from emp
*
ERROR at line 1:
ORA-00904: "SALARY": invalid identifier

SQL> select salary, salary + 3000 from emp;


select salary, salary + 3000 from emp
*
ERROR at line 1:
ORA-00904: "SALARY": invalid identifier

SQL> select firstname, salary, salary + 3000 from emp;


select firstname, salary, salary + 3000 from emp
*
ERROR at line 1:
ORA-00904: "SALARY": invalid identifier

SQL> select firstname, salary, (salary + 3000) from emp;


select firstname, salary, (salary + 3000) from emp
*
ERROR at line 1:
ORA-00904: "SALARY": invalid identifier

SQL> select firstname,salary + 3000, salary from emp;


select firstname,salary + 3000, salary from emp
*
ERROR at line 1:
ORA-00904: "SALARY": invalid identifier

SQL> select firstname,salary + 3000 salary from emp;


select firstname,salary + 3000 salary from emp
*
ERROR at line 1:
ORA-00904: "SALARY": invalid identifier

SQL> select firstname,salgrade + 3000 salgrade from emp;


select firstname,salgrade + 3000 salgrade from emp
*
ERROR at line 1:
ORA-00904: "SALGRADE": invalid identifier
SQL> desc emp;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL> select firstname,sal + 3000 sal from emp;
select firstname,sal + 3000 sal from emp
*
ERROR at line 1:
ORA-00904: "FIRSTNAME": invalid identifier

SQL> select sal, sal + 3000 from emp;


SAL SAL+3000
---------- ----------
800 3800
1600 4600
1250 4250
2975 5975
1250 4250
2850 5850
2450 5450
3000 6000
5000 8000
1500 4500
1100 4100
950 3950
3000 6000
1300 4300

14 rows selected.
SQL> select sal, sal *2 from emp;
SAL SAL*2
---------- ----------
800 1600
1600 3200
1250 2500
2975 5950
1250 2500
2850 5700
2450 4900
3000 6000
5000 10000
1500 3000

1100 2200
950 1900
3000 6000
1300 2600

14 rows selected.
SQL> select sal, sal *2+100 from emp;
SAL SAL*2+100
---------- ----------
800 1700
1600 3300

1250 2600
2975 6050
1250 2600
2850 5800
2450 5000
3000 6100
5000 10100
1500 3100
1100 2300
950 2000
3000 6100
1300 2700

14 rows selected.
SQL> select sal, sal *2+100-100 from emp;
SAL SAL*2+100-100
---------- -------------
800 1600
1600 3200
1250 2500
2975 5950
1250 2500
2850 5700
2450 4900
3000 6000
5000 10000
1500 3000
1100 2200
950 1900
3000 6000
1300 2600

14 rows selected.
SQL> select firstname||lastname from kumar_details;
FIRSTNAME||LASTNAME
--------------------
farozbasha
kumara

SQL> select lastname from kumar_details where like'%basha';


select lastname from kumar_details where like'%basha'
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select lastname from kumar_details where like "%basha";


select lastname from kumar_details where like "%basha"
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select lastname from kumar_details where lastname='basha';


LASTNAME
----------
basha

SQL> select lastname from kumar_details where like'%sha';


select lastname from kumar_details where like'%sha'
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select * from kumar_details where like '%sha';


select * from kumar_details where like '%sha'
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select * from kumar_details where like '%a';


select * from kumar_details where like '%a'
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select * from kumar_details;


FIRSTNAME LASTNAME ADDRESS AGE DESGINATION EMP_I
---------- ---------- ------------------------- ---------- --------------- -----
faroz basha adfas 31 Test Engineer MI035
kumar a adfasf 35 Test Engineer 025

SQL> select firstname from kumar_details where like '%z'


2 ;
select firstname from kumar_details where like '%z'
*
ERROR at line 1:
ORA-00936: missing expression
SQL> select firstname from kumar_details where firstname like '%z';
FIRSTNAME
----------
faroz

SQL> select firstname from kumar_details where firstname like '__r';


no rows selected
SQL> select firstname from kumar_details where firstname like '__r%';
FIRSTNAME
----------
faroz

SQL> select * from emp;


EMPNO ENAME JOB MGR HIREDATE SAL COMM D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
-----
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10
14 rows selected.
SQL> desac emp;
SP2-0042: unknown command "desac emp" - rest of line ignored.
SQL> desc emp;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)
SQL> select ename, deptno, sal from emp where orderby deptno, sal desc;
select ename, deptno, sal from emp where orderby deptno, sal desc
*
ERROR at line 1:
ORA-00920: invalid relational operator

SQL> select ename, deptno, sal from emp where order by deptno, sal desc;
select ename, deptno, sal from emp where order by deptno, sal desc
*
ERROR at line 1:
ORA-00936: missing expression

SQL> select ename, deptno, sal from emp order by deptno, sal desc;
ENAME DEPTNO SAL
---------- ---------- ----------
KING 10 5000
CLARK 10 2450
MILLER 10 1300
SCOTT 20 3000
FORD 20 3000

JONES 20 2975
ADAMS 20 1100
SMITH 20 800
BLAKE 30 2850
ALLEN 30 1600
TURNER 30 1500
MARTIN 30 1250
WARD 30 1250
JAMES 30 950

14 rows selected.
SQL> select ename, deptno, sal from emp order by sal desc;
ENAME DEPTNO SAL
---------- ---------- ----------
KING 10 5000
FORD 20 3000
SCOTT 20 3000
JONES 20 2975
BLAKE 30 2850
CLARK 10 2450
ALLEN 30 1600
TURNER 30 1500
MILLER 10 1300
WARD 30 1250
MARTIN 30 1250
ADAMS 20 1100
JAMES 30 950
SMITH 20 800

14 rows selected.
SQL> select ename, deptno, sal from emp order by deptno desc;
ENAME DEPTNO SAL
---------- ---------- ----------
BLAKE 30 2850
TURNER 30 1500
ALLEN 30 1600
MARTIN 30 1250
WARD 30 1250
JAMES 30 950
SCOTT 20 3000
JONES 20 2975
SMITH 20 800
ADAMS 20 1100
FORD 20 3000
KING 10 5000
MILLER 10 1300
CLARK 10 2450

14 rows selected.
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
-----
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7839 KING PRESIDENT 17-NOV-81 5000
10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7934 MILLER CLERK 7782 23-JAN-82 1300
10
14 rows selected.
SQL> select * from emp x where 5>(select count(*) from emp where deptno=x.deptno
and sal>x.sal
2 ) order by deptno, sal desc;
EMPNO ENAME JOB MGR HIREDATE SAL COMM D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----
-----
7839 KING PRESIDENT 17-NOV-81 5000
10
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7934 MILLER CLERK 7782 23-JAN-82 1300
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7902 FORD ANALYST 7566 03-DEC-81 3000
20
7566 JONES MANAGER 7839 02-APR-81 2975
20
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7369 SMITH CLERK 7902 17-DEC-80 800
20
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
13 rows selected.
SQL> desc dept;
Name Null? Type
----------------------------------------------------- -------- ----------------
--------------------
DEPTNO NOT NULL NUMBER(2)
DNAME VARCHAR2(14)
LOC VARCHAR2(13)
SQL> select * from emp x where 5>(select count(*) from emp where dept=x.dept and
sal>x.sal
2 ) order by dept,sal desc;
) order by dept,sal desc
*
ERROR at line 2:
ORA-00904: "DEPT": invalid identifier

SQL> SELECT max(salary) FROM Employee WHERE Employee.salary <


2 (SELECT max(salary) FROM Employee)
3
SQL> select max(sal) from emp where emp.sal < (select max(sal) from emp);
MAX(SAL)
----------
3000

SQL> select sal from emp order by sal desc;


SAL
----------
5000
3000
3000
2975
2850
2450
1600
1500
1300
1250
1250
1100
950
800

14 rows selected.
SQL> select employee_name
2 from employee
3 order by salary desc
4 where ROWNUM=2
5
SQL> select sal from emp order by sal desc where rownum=2;
select sal from emp order by sal desc where rownum=2
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

SQL> spool off

You might also like