Sie sind auf Seite 1von 47

SQL> show user

USER is "SHUBHAM"
SQL> desc user_constraints
Name
----------------------------------------OWNER
CONSTRAINT_NAME
CONSTRAINT_TYPE
TABLE_NAME
SEARCH_CONDITION
R_OWNER
R_CONSTRAINT_NAME
DELETE_RULE
STATUS
DEFERRABLE
DEFERRED
VALIDATED
GENERATED
BAD
RELY
LAST_CHANGE
INDEX_OWNER
INDEX_NAME
INVALID
VIEW_RELATED
SQL> desc user_cons_columns;
Name
----------------------------------------OWNER
CONSTRAINT_NAME
TABLE_NAME
COLUMN_NAME
POSITION
SQL> delete emp;
14 rows deleted.
SQL> savepoint s1
2 ;
Savepoint created.
SQL> delete dept;
4 rows deleted.
SQL> select * from dept;
no rows selected
SQL> select * from emp;
no rows selected
SQL> rollback to s1;
Rollback complete.

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

Type
---------------------------VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(1)
NOT NULL VARCHAR2(30)
LONG
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(9)
VARCHAR2(8)
VARCHAR2(14)
VARCHAR2(9)
VARCHAR2(13)
VARCHAR2(14)
VARCHAR2(3)
VARCHAR2(4)
DATE
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(7)
VARCHAR2(14)
Null?
-------NOT NULL
NOT NULL
NOT NULL

Type
---------------------------VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(4000)
NUMBER

SQL> select * from dept;


DEPTNO
---------10
20
30
40

DNAME
-------------ACCOUNTING
RESEARCH
SALES
OPERATIONS

LOC
------------NEW YORK
DALLAS
CHICAGO
BOSTON

SQL> select * from emp;


no rows selected
SQL> rollback;
Rollback complete.
SQL> select * from emp;
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
---------- ---------- --------- ---------- --------- ---------- ---------DEPTNO
---------7369 SMITH
CLERK
7902 17-DEC-80
800
20
7499 ALLEN
30

SALESMAN

7698 20-FEB-81

1600

300

7521 WARD
30

SALESMAN

7698 22-FEB-81

1250

500

EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
---------- ---------- --------- ---------- --------- ---------- ---------DEPTNO
---------7566 JONES
MANAGER
7839 02-APR-81
2975
20
7654 MARTIN
30

SALESMAN

7698 28-SEP-81

1250

7698 BLAKE
30

MANAGER

7839 01-MAY-81

2850

1400

EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
---------- ---------- --------- ---------- --------- ---------- ---------DEPTNO
---------7782 CLARK
MANAGER
7839 09-JUN-81
2450
10
7788 SCOTT
20

ANALYST

7839 KING
10

PRESIDENT

7566 09-DEC-82

3000

17-NOV-81

5000

EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
---------- ---------- --------- ---------- --------- ---------- ---------DEPTNO
---------7844 TURNER
SALESMAN
7698 08-SEP-81
1500
0
30
7876 ADAMS
20

CLERK

7788 12-JAN-83

1100

7900 JAMES
30

CLERK

7698 03-DEC-81

950

EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
---------- ---------- --------- ---------- --------- ---------- ---------DEPTNO
---------7902 FORD
ANALYST
7566 03-DEC-81
3000
20
7934 MILLER
10

CLERK

7782 23-JAN-82

1300

MGR HIREDATE

SAL

14 rows selected.
SQL> set lines 100
SQL> /
EMPNO
EPTNO
-------------7369
20
7499
30
7521
30
7566
20
7654
30
7698
30
7782
10
7788
20
7839
10
7844
30
7876
20

ENAME

JOB

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

TURNER

SALESMAN

7698 08-SEP-81

1500

ADAMS

CLERK

7788 12-JAN-83

1100

MGR HIREDATE

SAL

EMPNO ENAME

JOB

1400

COMM

EPTNO
-------------7900
30
7902
20
7934
10

---------- --------- ---------- --------- ---------- ---------- ----JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

MGR HIREDATE

SAL

14 rows selected.
SQL> set page 400
SP2-0158: unknown SET option "page"
SQL> /
EMPNO
EPTNO
-------------7369
20
7499
30
7521
30
7566
20
7654
30
7698
30
7782
10
7788
20
7839
10
7844
30
7876
20

ENAME

EMPNO
EPTNO
-------------7900
30
7902
20
7934
10

JOB

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

TURNER

SALESMAN

7698 08-SEP-81

1500

ADAMS

CLERK

7788 12-JAN-83

1100

ENAME

JOB

MGR HIREDATE

SAL

1400

COMM

---------- --------- ---------- --------- ---------- ---------- ----JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

MGR HIREDATE

SAL

14 rows selected.
SQL> set pagesize 400
SQL> /
EMPNO ENAME

JOB

COMM

EPTNO
-------------7369
20
7499
30
7521
30
7566
20
7654
30
7698
30
7782
10
7788
20
7839
10
7844
30
7876
20
7900
30
7902
20
7934
10

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

TURNER

SALESMAN

7698 08-SEP-81

1500

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

MGR HIREDATE

SAL

1400

14 rows selected.
SQL> select * from emp
2 where deptno=10;
EMPNO
EPTNO
-------------7782
10
7839
10
7934
10

ENAME

JOB

COMM

---------- --------- ---------- --------- ---------- ---------- ----CLARK

MANAGER

KING

PRESIDENT

MILLER

CLERK

7839 09-JUN-81

2450

17-NOV-81

5000

7782 23-JAN-82

1300

SQL> select * from emp where deptno=10 or deptno=20;


EMPNO
EPTNO
-------------7369
20
7566
20
7782

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

JONES

MANAGER

7839 02-APR-81

2975

CLARK

MANAGER

7839 09-JUN-81

2450

10
7788 SCOTT

ANALYST

7566 09-DEC-82

3000

7839 KING

PRESIDENT

17-NOV-81

5000

7876 ADAMS

CLERK

7788 12-JAN-83

1100

7902 FORD

ANALYST

7566 03-DEC-81

3000

7934 MILLER

CLERK

7782 23-JAN-82

1300

20
10
20
20
10
8 rows selected.
SQL> select * from emp where deptno in(10,30);
EMPNO
EPTNO
-------------7499
30
7521
30
7654
30
7698
30
7782
10
7839
10
7844
30
7900
30
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

KING

PRESIDENT

17-NOV-81

5000

TURNER

SALESMAN

7698 08-SEP-81

1500

JAMES

CLERK

7698 03-DEC-81

950

MILLER

CLERK

7782 23-JAN-82

1300

9 rows selected.
SQL> select * from emp where deptno=10 and deptno=20;
no rows selected
SQL> select * from emp where job in(clerk,manager);
select * from emp where job in(clerk,manager)
*
ERROR at line 1:
ORA-00904: "MANAGER": invalid identifier
SQL> select * from emp where job in('CLERK','MANAGER');
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- --------7369 SMITH
CLERK
7902 17-DEC-80
800
20

7566 JONES

MANAGER

7839 02-APR-81

2975

7698 BLAKE

MANAGER

7839 01-MAY-81

2850

7782 CLARK

MANAGER

7839 09-JUN-81

2450

7876 ADAMS

CLERK

7788 12-JAN-83

1100

7900 JAMES

CLERK

7698 03-DEC-81

950

7934 MILLER

CLERK

7782 23-JAN-82

1300

20
30
10
20
30
10
7 rows selected.
SQL> select * from emp where sal>=1500;
EMPNO
EPTNO
-------------7499
30
7566
20
7698
30
7782
10
7788
20
7839
10
7844
30
7902
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

JONES

MANAGER

7839 02-APR-81

2975

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

TURNER

SALESMAN

7698 08-SEP-81

1500

FORD

ANALYST

7566 03-DEC-81

3000

300

8 rows selected.
SQL> select * from emp where sal<=1500;
EMPNO
EPTNO
-------------7369
20
7521
30
7654
30
7844
30
7876
20
7900
30
7934

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

TURNER

SALESMAN

7698 08-SEP-81

1500

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

MILLER

CLERK

7782 23-JAN-82

1300

10
7 rows selected.
SQL> select * from emp where sal<1500;
EMPNO
EPTNO
-------------7369
20
7521
30
7654
30
7876
20
7900
30
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

MILLER

CLERK

7782 23-JAN-82

1300

6 rows selected.
SQL> select * from emp where sal<>1500;
EMPNO
EPTNO
-------------7369
20
7499
30
7521
30
7566
20
7654
30
7698
30
7782
10
7788
20
7839
10
7876
20
7900
30
7902
20
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

13 rows selected.

1400

SQL> select * from emp where sal>=1500 and sal<=2450;


EMPNO
EPTNO
-------------7499
30
7782
10
7844
30

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

300

CLARK

MANAGER

7839 09-JUN-81

2450

TURNER

SALESMAN

7698 08-SEP-81

1500

SAL

COMM

SQL>
SQL> select * from emp where sal<1500 and sal>2450;
no rows selected
SQL> select * from emp where sal<1500 or sal>2450;
EMPNO
EPTNO
-------------7369
20
7521
30
7566
20
7654
30
7698
30
7788
20
7839
10
7876
20
7900
30
7902
20
7934
10

ENAME

JOB

MGR HIREDATE

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

WARD

SALESMAN

7698 22-FEB-81

1250

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

500

1400

11 rows selected.
SQL> select * from emp where sal between 1500 and 2450;
EMPNO
EPTNO
-------------7499
30
7782

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

CLARK

MANAGER

7839 09-JUN-81

2450

300

10
7844 TURNER

SALESMAN

7698 08-SEP-81

1500

30
SQL> select * from emp where sal not between 1500 and 2450;
EMPNO
EPTNO
-------------7369
20
7521
30
7566
20
7654
30
7698
30
7788
20
7839
10
7876
20
7900
30
7902
20
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

WARD

SALESMAN

7698 22-FEB-81

1250

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

500

1400

11 rows selected.
SQL> select * from emp where sal<1500;
EMPNO
EPTNO
-------------7369
20
7521
30
7654
30
7876
20
7900
30
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

MILLER

CLERK

7782 23-JAN-82

1300

6 rows selected.
SQL> select * from emp where comm=null;
no rows selected

SQL> select * from emp where comm!=null;


no rows selected
SQL> select * from emp where comm is null;
EMPNO
EPTNO
-------------7369
20
7566
20
7698
30
7782
10
7788
20
7839
10
7876
20
7900
30
7902
20
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

JONES

MANAGER

7839 02-APR-81

2975

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

10 rows selected.
SQL> select * from emp where comm is not null;
EMPNO
EPTNO
-------------7499
30
7521
30
7654
30
7844
30

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

TURNER

SALESMAN

7698 08-SEP-81

1500

SAL

COMM

SQL> select * from emp where comm is not null and comm!=0;
EMPNO
EPTNO
-------------7499
30
7521
30
7654

ENAME

JOB

MGR HIREDATE

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

30

SQL> select * from emp where comm is null and comm!=0;


no rows selected
SQL> select * from emp where comm is null or comm=0;
EMPNO
EPTNO
-------------7369
20
7566
20
7698
30
7782
10
7788
20
7839
10
7844
30
7876
20
7900
30
7902
20
7934
10

ENAME

JOB

MGR HIREDATE

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

JONES

MANAGER

7839 02-APR-81

2975

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

KING

PRESIDENT

17-NOV-81

5000

TURNER

SALESMAN

7698 08-SEP-81

1500

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

FORD

ANALYST

7566 03-DEC-81

3000

MILLER

CLERK

7782 23-JAN-82

1300

11 rows selected.
SQL> select * from emp where comm is null and comm!=0;
no rows selected
SQL> select * from emp where comm is null and comm=0;
no rows selected
SQL> select empno,ename,sal,comm,sal+comm from emp;
EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839

SAL

ENAME
SAL
COMM SAL+COMM
---------- ---------- ---------- ---------SMITH
800
ALLEN
1600
300
1900
WARD
1250
500
1750
JONES
2975
MARTIN
1250
1400
2650
BLAKE
2850
CLARK
2450
SCOTT
3000
KING
5000

7844
7876
7900
7902
7934

TURNER
ADAMS
JAMES
FORD
MILLER

1500
1100
950
3000
1300

1500

14 rows selected.
SQL>
SQL>
SQL> select empno,ename,sal,comm,sal+nvl(comm,0) from emp;
EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

ENAME
SAL
COMM SAL+NVL(COMM,0)
---------- ---------- ---------- --------------SMITH
800
800
ALLEN
1600
300
1900
WARD
1250
500
1750
JONES
2975
2975
MARTIN
1250
1400
2650
BLAKE
2850
2850
CLARK
2450
2450
SCOTT
3000
3000
KING
5000
5000
TURNER
1500
0
1500
ADAMS
1100
1100
JAMES
950
950
FORD
3000
3000
MILLER
1300
1300

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0) as total_sal from emp;
EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

ENAME
SAL
COMM TOTAL_SAL
---------- ---------- ---------- ---------SMITH
800
800
ALLEN
1600
300
1900
WARD
1250
500
1750
JONES
2975
2975
MARTIN
1250
1400
2650
BLAKE
2850
2850
CLARK
2450
2450
SCOTT
3000
3000
KING
5000
5000
TURNER
1500
0
1500
ADAMS
1100
1100
JAMES
950
950
FORD
3000
3000
MILLER
1300
1300

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0) total_sal from emp;
EMPNO
---------7369
7499
7521
7566

ENAME
SAL
COMM TOTAL_SAL
---------- ---------- ---------- ---------SMITH
800
800
ALLEN
1600
300
1900
WARD
1250
500
1750
JONES
2975
2975

7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

1250
2850
2450
3000
5000
1500
1100
950
3000
1300

1400

2650
2850
2450
3000
5000
1500
1100
950
3000
1300

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0) "toTAl salARY" FROM emp;
EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

ENAME
SAL
COMM toTAl salARY
---------- ---------- ---------- -----------SMITH
800
800
ALLEN
1600
300
1900
WARD
1250
500
1750
JONES
2975
2975
MARTIN
1250
1400
2650
BLAKE
2850
2850
CLARK
2450
2450
SCOTT
3000
3000
KING
5000
5000
TURNER
1500
0
1500
ADAMS
1100
1100
JAMES
950
950
FORD
3000
3000
MILLER
1300
1300

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp;
EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------SMITH
800
800
20
ALLEN
1600
300
1900
30
WARD
1250
500
1750
30
JONES
2975
2975
20
MARTIN
1250
1400
2650
30
BLAKE
2850
2850
30
CLARK
2450
2450
10
SCOTT
3000
3000
20
KING
5000
5000
10
TURNER
1500
0
1500
30
ADAMS
1100
1100
20
JAMES
950
950
30
FORD
3000
3000
20
MILLER
1300
1300
10

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno
;
EMPNO ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- ---------- --------------- ----------

7782
7839
7934
7566
7902
7876
7369
7788
7521
7844
7499
7900
7698
7654

CLARK
KING
MILLER
JONES
FORD
ADAMS
SMITH
SCOTT
WARD
TURNER
ALLEN
JAMES
BLAKE
MARTIN

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

500
0
300
1400

2450
5000
1300
2975
3000
1100
800
3000
1750
1500
1900
950
2850
2650

10
10
10
20
20
20
20
20
30
30
30
30
30
30

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno
desc;
EMPNO
---------7698
7844
7499
7654
7521
7900
7788
7566
7369
7876
7902
7839
7934
7782

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------BLAKE
2850
2850
30
TURNER
1500
0
1500
30
ALLEN
1600
300
1900
30
MARTIN
1250
1400
2650
30
WARD
1250
500
1750
30
JAMES
950
950
30
SCOTT
3000
3000
20
JONES
2975
2975
20
SMITH
800
800
20
ADAMS
1100
1100
20
FORD
3000
3000
20
KING
5000
5000
10
MILLER
1300
1300
10
CLARK
2450
2450
10

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno
,sal;
EMPNO
---------7934
7782
7839
7369
7876
7566
7788
7902
7900
7654
7521
7844
7499
7698

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------MILLER
1300
1300
10
CLARK
2450
2450
10
KING
5000
5000
10
SMITH
800
800
20
ADAMS
1100
1100
20
JONES
2975
2975
20
SCOTT
3000
3000
20
FORD
3000
3000
20
JAMES
950
950
30
MARTIN
1250
1400
2650
30
WARD
1250
500
1750
30
TURNER
1500
0
1500
30
ALLEN
1600
300
1900
30
BLAKE
2850
2850
30

14 rows selected.

SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno


desc sal;
select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno desc
sal
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno
desc,sal;
EMPNO
---------7900
7521
7654
7844
7499
7698
7369
7876
7566
7788
7902
7934
7782
7839

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------JAMES
950
950
30
WARD
1250
500
1750
30
MARTIN
1250
1400
2650
30
TURNER
1500
0
1500
30
ALLEN
1600
300
1900
30
BLAKE
2850
2850
30
SMITH
800
800
20
ADAMS
1100
1100
20
JONES
2975
2975
20
SCOTT
3000
3000
20
FORD
3000
3000
20
MILLER
1300
1300
10
CLARK
2450
2450
10
KING
5000
5000
10

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptn
o desc,sal desc;
EMPNO
---------7698
7499
7844
7521
7654
7900
7902
7788
7566
7876
7369
7839
7782
7934

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------BLAKE
2850
2850
30
ALLEN
1600
300
1900
30
TURNER
1500
0
1500
30
WARD
1250
500
1750
30
MARTIN
1250
1400
2650
30
JAMES
950
950
30
FORD
3000
3000
20
SCOTT
3000
3000
20
JONES
2975
2975
20
ADAMS
1100
1100
20
SMITH
800
800
20
KING
5000
5000
10
CLARK
2450
2450
10
MILLER
1300
1300
10

14 rows selected.
SQL>
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptno
desc,sal;

EMPNO
---------7900
7521
7654
7844
7499
7698
7369
7876
7566
7788
7902
7934
7782
7839

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------JAMES
950
950
30
WARD
1250
500
1750
30
MARTIN
1250
1400
2650
30
TURNER
1500
0
1500
30
ALLEN
1600
300
1900
30
BLAKE
2850
2850
30
SMITH
800
800
20
ADAMS
1100
1100
20
JONES
2975
2975
20
SCOTT
3000
3000
20
FORD
3000
3000
20
MILLER
1300
1300
10
CLARK
2450
2450
10
KING
5000
5000
10

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0),deptno from emp order by deptn
o desc,sal desc;
EMPNO
---------7698
7499
7844
7521
7654
7900
7902
7788
7566
7876
7369
7839
7782
7934

ENAME
SAL
COMM SAL+NVL(COMM,0)
DEPTNO
---------- ---------- ---------- --------------- ---------BLAKE
2850
2850
30
ALLEN
1600
300
1900
30
TURNER
1500
0
1500
30
WARD
1250
500
1750
30
MARTIN
1250
1400
2650
30
JAMES
950
950
30
FORD
3000
3000
20
SCOTT
3000
3000
20
JONES
2975
2975
20
ADAMS
1100
1100
20
SMITH
800
800
20
KING
5000
5000
10
CLARK
2450
2450
10
MILLER
1300
1300
10

14 rows selected.
SQL> select empno,ename,sal,comm,sal+nvl(comm,0) "total sal" ,deptno from emp or
der by deptno desc,
"total sal" desc;
EMPNO
---------7698
7654
7499
7521
7844
7900
7902
7788
7566
7876
7369
7839
7782

ENAME
SAL
COMM total sal
DEPTNO
---------- ---------- ---------- ---------- ---------BLAKE
2850
2850
30
MARTIN
1250
1400
2650
30
ALLEN
1600
300
1900
30
WARD
1250
500
1750
30
TURNER
1500
0
1500
30
JAMES
950
950
30
FORD
3000
3000
20
SCOTT
3000
3000
20
JONES
2975
2975
20
ADAMS
1100
1100
20
SMITH
800
800
20
KING
5000
5000
10
CLARK
2450
2450
10

7934 MILLER

1300

1300

10

14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select empno,ename,sal,comm,sal+nvl(comm,0) "total sal" ,deptno where "tota
l sal">500 from emp
SQL> /
select empno,ename,sal,comm,sal+nvl(comm,0) "total sal" ,deptno where "total sal
">500 from emp order
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected
SQL> ed
Wrote file afiedt.buf
1* select empno,ename,sal,comm,sal+nvl(comm,0) "total sal" ,deptno from emp wh
ere "total sal">500
SQL> /
select empno,ename,sal,comm,sal+nvl(comm,0) "total sal" ,deptno from emp where "
total sal">500 order
*
ERROR at line 1:
ORA-00904: "total sal": invalid identifier

SQL> ed
Wrote file afiedt.buf
1* select empno,ename,sal,comm,sal+nvl(comm,0) "total sal" ,deptno from emp or
der by 5 desc
SQL> /
EMPNO
---------7839
7902
7788
7566
7698
7654
7782
7499
7521
7844
7934
7876
7900
7369

ENAME
SAL
COMM total sal
DEPTNO
---------- ---------- ---------- ---------- ---------KING
5000
5000
10
FORD
3000
3000
20
SCOTT
3000
3000
20
JONES
2975
2975
20
BLAKE
2850
2850
30
MARTIN
1250
1400
2650
30
CLARK
2450
2450
10
ALLEN
1600
300
1900
30
WARD
1250
500
1750
30
TURNER
1500
0
1500
30
MILLER
1300
1300
10
ADAMS
1100
1100
20
JAMES
950
950
30
SMITH
800
800
20

14 rows selected.
SQL> select * from emp where deptno=&deptno;
Enter value for deptno: 10
old 1: select * from emp where deptno=&deptno

new

1: select * from emp where deptno=10

EMPNO
EPTNO
-------------7782
10
7839
10
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----CLARK

MANAGER

KING

PRESIDENT

MILLER

CLERK

7839 09-JUN-81

2450

17-NOV-81

5000

7782 23-JAN-82

1300

SQL> /
Enter value for deptno: 20
old 1: select * from emp where deptno=&deptno
new 1: select * from emp where deptno=20
EMPNO
EPTNO
-------------7369
20
7566
20
7788
20
7876
20
7902
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

JONES

MANAGER

7839 02-APR-81

2975

SCOTT

ANALYST

7566 09-DEC-82

3000

ADAMS

CLERK

7788 12-JAN-83

1100

FORD

ANALYST

7566 03-DEC-81

3000

SQL> l
1* select * from emp where deptno=&deptno
SQL> select * from &tname;
Enter value for tname: emp
old 1: select * from &tname
new 1: select * from emp
EMPNO
EPTNO
-------------7369
20
7499
30
7521
30
7566
20
7654
30
7698
30
7782
10
7788
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

1400

7839 KING

PRESIDENT

17-NOV-81

5000

7844 TURNER

SALESMAN

7698 08-SEP-81

1500

7876 ADAMS

CLERK

7788 12-JAN-83

1100

7900 JAMES

CLERK

7698 03-DEC-81

950

7902 FORD

ANALYST

7566 03-DEC-81

3000

7934 MILLER

CLERK

7782 23-JAN-82

1300

10
0

30
20
30
20
10
14 rows selected.
SQL> /
Enter value for tname: dept
old 1: select * from &tname
new 1: select * from dept
DEPTNO
---------10
20
30
40

DNAME
-------------ACCOUNTING
RESEARCH
SALES
OPERATIONS

LOC
------------NEW YORK
DALLAS
CHICAGO
BOSTON

SQL> select * from emp where deptno=&&deptno;


Enter value for deptno: 10
old 1: select * from emp where deptno=&&deptno
new 1: select * from emp where deptno=10
EMPNO
EPTNO
-------------7782
10
7839
10
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----CLARK

MANAGER

KING

PRESIDENT

MILLER

CLERK

7839 09-JUN-81

2450

17-NOV-81

5000

7782 23-JAN-82

1300

SQL> /
old 1: select * from emp where deptno=&&deptno
new 1: select * from emp where deptno=10
EMPNO
EPTNO
-------------7782
10
7839
10
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----CLARK

MANAGER

KING

PRESIDENT

MILLER

CLERK

7839 09-JUN-81

2450

17-NOV-81

5000

7782 23-JAN-82

1300

SQL> select * from &tname where deptno=&deptno;


Enter value for tname: emp

old
new

1: select * from &tname where deptno=&deptno


1: select * from emp where deptno=10

EMPNO
EPTNO
-------------7782
10
7839
10
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----CLARK

MANAGER

KING

PRESIDENT

MILLER

CLERK

7839 09-JUN-81

2450

17-NOV-81

5000

7782 23-JAN-82

1300

note: it will not ask for deptno number beacause previously i give a query for &
& and for this complete session
it will save the value of deptno=10'
so i give dept=&dno
SQL>
Enter
Enter
old
new

select * from &tname where deptno=&dno;


value for tname: emp
value for dno: 20
1: select * from &tname where deptno=&dno
1: select * from emp where deptno=20

EMPNO
EPTNO
-------------7369
20
7566
20
7788
20
7876
20
7902
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

JONES

MANAGER

7839 02-APR-81

2975

SCOTT

ANALYST

7566 09-DEC-82

3000

ADAMS

CLERK

7788 12-JAN-83

1100

FORD

ANALYST

7566 03-DEC-81

3000

SQL> select * from emp where ename like'A%';


EMPNO
EPTNO
-------------7499
30
7876
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

ADAMS

CLERK

7788 12-JAN-83

1100

300

SQL> select * from emp where ename like'____';


EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- -----

----7521 WARD

SALESMAN

7839 KING

PRESIDENT

7902 FORD

ANALYST

7698 22-FEB-81

1250

17-NOV-81

5000

7566 03-DEC-81

3000

500

30
10
20
SQL> select * from emp where ename like'_____&';
no rows selected
SQL> select * from emp where ename like'_____%';
EMPNO
EPTNO
-------------7369
20
7499
30
7566
20
7654
30
7698
30
7782
10
7788
20
7844
30
7876
20
7900
30
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ALLEN

SALESMAN

7698 20-FEB-81

1600

JONES

MANAGER

7839 02-APR-81

2975

MARTIN

SALESMAN

7698 28-SEP-81

1250

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

SCOTT

ANALYST

7566 09-DEC-82

3000

TURNER

SALESMAN

7698 08-SEP-81

1500

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

MILLER

CLERK

7782 23-JAN-82

1300

300

1400

11 rows selected.
SQL> select * from emp where ename like'%A%';
EMPNO
EPTNO
-------------7499
30
7521
30
7654
30
7698
30
7782
10
7876

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

300

WARD

SALESMAN

7698 22-FEB-81

1250

500

MARTIN

SALESMAN

7698 28-SEP-81

1250

1400

BLAKE

MANAGER

7839 01-MAY-81

2850

CLARK

MANAGER

7839 09-JUN-81

2450

ADAMS

CLERK

7788 12-JAN-83

1100

20
7900 JAMES

CLERK

7698 03-DEC-81

950

30
7 rows selected.
SQL> select * from emp where ename like'%LE%';
EMPNO
EPTNO
-------------7499
30
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----ALLEN

SALESMAN

7698 20-FEB-81

1600

MILLER

CLERK

7782 23-JAN-82

1300

300

SQL> DEFINE DNO=10;


SQL> SELECT * FROM EMP WHERE DEPTNO=&DN0;
Enter value for dn0:
old 1: SELECT * FROM EMP WHERE DEPTNO=&DN0
new 1: SELECT * FROM EMP WHERE DEPTNO=
SELECT * FROM EMP WHERE DEPTNO=
*
ERROR at line 1:
ORA-00936: missing expression
SQL>
SQL> SELECT * FROM EMP WHERE DEPTNO=&DNO;
old 1: SELECT * FROM EMP WHERE DEPTNO=&DNO
new 1: SELECT * FROM EMP WHERE DEPTNO=10
EMPNO
EPTNO
-------------7782
10
7839
10
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----CLARK

MANAGER

KING

PRESIDENT

MILLER

CLERK

7839 09-JUN-81

2450

17-NOV-81

5000

7782 23-JAN-82

1300

SQL> DEFINE DNO;


DEFINE DNO
= "10" (CHAR)
SQL> UNDEFINE DNO;
SQL> DEFINE DNO;
SP2-0135: symbol dno is UNDEFINED
SQL> SELECT * FROM EMP WHERE JOB='ANALYST';
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
D
EPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- --------7788 SCOTT
ANALYST
7566 09-DEC-82
3000

20
7902 FORD

ANALYST

7566 03-DEC-81

3000

20
SQL> SELECT * FROM EMP WHERE LOWER(JOB)='analyst';
EMPNO
EPTNO
-------------7788
20
7902
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SCOTT

ANALYST

7566 09-DEC-82

3000

FORD

ANALYST

7566 03-DEC-81

3000

SQL> show feedback


FEEDBACK ON for 6 or more rows
SQL> set feedback on
SQL> SELECT * FROM EMP WHERE LOWER(JOB)='analyst';
EMPNO
EPTNO
-------------7788
20
7902
20

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SCOTT

ANALYST

7566 09-DEC-82

3000

FORD

ANALYST

7566 03-DEC-81

3000

2 rows selected.
SQL> select ename ||'earns salary'|| sal from emp;
ENAME||'EARNSSALARY'||SAL
-------------------------------------------------------------SMITHearns salary800
ALLENearns salary1600
WARDearns salary1250
JONESearns salary2975
MARTINearns salary1250
BLAKEearns salary2850
CLARKearns salary2450
SCOTTearns salary3000
KINGearns salary5000
TURNERearns salary1500
ADAMSearns salary1100
JAMESearns salary950
FORDearns salary3000
MILLERearns salary1300
14 rows selected.
SQL> select ename ||' earns salary'|| sal from emp;
ENAME||'EARNSSALARY'||SAL
--------------------------------------------------------------SMITH earns salary800
ALLEN earns salary1600
WARD earns salary1250

JONES earns salary2975


MARTIN earns salary1250
BLAKE earns salary2850
CLARK earns salary2450
SCOTT earns salary3000
KING earns salary5000
TURNER earns salary1500
ADAMS earns salary1100
JAMES earns salary950
FORD earns salary3000
MILLER earns salary1300
14 rows selected.
SQL> select ename ||' earns salary'|| sal " Employee Information" from emp;
Employee Information
--------------------------------------------------------------SMITH earns salary800
ALLEN earns salary1600
WARD earns salary1250
JONES earns salary2975
MARTIN earns salary1250
BLAKE earns salary2850
CLARK earns salary2450
SCOTT earns salary3000
KING earns salary5000
TURNER earns salary1500
ADAMS earns salary1100
JAMES earns salary950
FORD earns salary3000
MILLER earns salary1300
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select ename ||' earns salary '|| sal " Employee Information" from emp
SQL> /
Employee Information
---------------------------------------------------------------SMITH earns salary 800
ALLEN earns salary 1600
WARD earns salary 1250
JONES earns salary 2975
MARTIN earns salary 1250
BLAKE earns salary 2850
CLARK earns salary 2450
SCOTT earns salary 3000
KING earns salary 5000
TURNER earns salary 1500
ADAMS earns salary 1100
JAMES earns salary 950
FORD earns salary 3000
MILLER earns salary 1300
14 rows selected.

SQL> select initcap (ename ||' earns salary '|| sal) " Employee Information" fro
m emp;
Employee Information
---------------------------------------------------------------Smith Earns Salary 800
Allen Earns Salary 1600
Ward Earns Salary 1250
Jones Earns Salary 2975
Martin Earns Salary 1250
Blake Earns Salary 2850
Clark Earns Salary 2450
Scott Earns Salary 3000
King Earns Salary 5000
Turner Earns Salary 1500
Adams Earns Salary 1100
James Earns Salary 950
Ford Earns Salary 3000
Miller Earns Salary 1300
14 rows selected.
SQL> select concat( concat(ename,' earns salary '),sal ) " Employee Information"
from emp;
Employee Information
---------------------------------------------------------------SMITH earns salary 800
ALLEN earns salary 1600
WARD earns salary 1250
JONES earns salary 2975
MARTIN earns salary 1250
BLAKE earns salary 2850
CLARK earns salary 2450
SCOTT earns salary 3000
KING earns salary 5000
TURNER earns salary 1500
ADAMS earns salary 1100
JAMES earns salary 950
FORD earns salary 3000
MILLER earns salary 1300
14 rows selected.
SQL> select concat( concat(ename,' earns salary '),sal ) " Employee Information"
from emp order by s
al;
Employee Information
---------------------------------------------------------------SMITH earns salary 800
JAMES earns salary 950
ADAMS earns salary 1100
WARD earns salary 1250
MARTIN earns salary 1250
MILLER earns salary 1300
TURNER earns salary 1500
ALLEN earns salary 1600
CLARK earns salary 2450
BLAKE earns salary 2850

JONES earns salary 2975


SCOTT earns salary 3000
FORD earns salary 3000
KING earns salary 5000
14 rows selected.
SQL> select concat( concat(ename,' earns salary '),sal ) " Employee Information"
from emp order by e
name;
Employee Information
---------------------------------------------------------------ADAMS earns salary 1100
ALLEN earns salary 1600
BLAKE earns salary 2850
CLARK earns salary 2450
FORD earns salary 3000
JAMES earns salary 950
JONES earns salary 2975
KING earns salary 5000
MARTIN earns salary 1250
MILLER earns salary 1300
SCOTT earns salary 3000
SMITH earns salary 800
TURNER earns salary 1500
WARD earns salary 1250
14 rows selected.

SQL> select ename,sal from emp;


ENAME
SAL
---------- ---------SMITH
800
ALLEN
1600
WARD
1250
JONES
2975
MARTIN
1250
BLAKE
2850
CLARK
2450
SCOTT
3000
KING
5000
TURNER
1500
ADAMS
1100
JAMES
950
FORD
3000
MILLER
1300
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select lpad (ename,15),rpad (sal,15) from emp
SQL> /
LPAD(ENAME,15) RPAD(SAL,15)

--------------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

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

14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select lpad (ename,15)"ename",rpad (sal,15)"salary" from emp
SQL> /
ename
--------------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

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

14 rows selected.
SQL> select initcap (ename ||' earns salary '|| sal) " Employee Information" fro
m emp;
Employee Information
---------------------------------------------------------------Smith Earns Salary 800
Allen Earns Salary 1600
Ward Earns Salary 1250
Jones Earns Salary 2975
Martin Earns Salary 1250
Blake Earns Salary 2850
Clark Earns Salary 2450
Scott Earns Salary 3000
King Earns Salary 5000
Turner Earns Salary 1500
Adams Earns Salary 1100
James Earns Salary 950

Ford Earns Salary 3000


Miller Earns Salary 1300
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select initcap (rpad(ename,15) ||' earns salary '|| sal) " Employee Informa
tion" from emp
SQL> /
Employee Information
--------------------------------------------------------------------Smith
Earns Salary 800
Allen
Earns Salary 1600
Ward
Earns Salary 1250
Jones
Earns Salary 2975
Martin
Earns Salary 1250
Blake
Earns Salary 2850
Clark
Earns Salary 2450
Scott
Earns Salary 3000
King
Earns Salary 5000
Turner
Earns Salary 1500
Adams
Earns Salary 1100
James
Earns Salary 950
Ford
Earns Salary 3000
Miller
Earns Salary 1300
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select initcap (rpad(ename,15,'.') ||' earns salary '|| sal ) " Employee In
formation" from emp
SQL> /
Employee Information
--------------------------------------------------------------------Smith.......... Earns Salary 800
Allen.......... Earns Salary 1600
Ward........... Earns Salary 1250
Jones.......... Earns Salary 2975
Martin......... Earns Salary 1250
Blake.......... Earns Salary 2850
Clark.......... Earns Salary 2450
Scott.......... Earns Salary 3000
King........... Earns Salary 5000
Turner......... Earns Salary 1500
Adams.......... Earns Salary 1100
James.......... Earns Salary 950
Ford........... Earns Salary 3000
Miller......... Earns Salary 1300
14 rows selected.
SQL> ed
Wrote file afiedt.buf

1* select initcap (ename ||' earns salary '|| lpad(sal,5,'.') " Employee Infor
mation" from emp
SQL> /
select initcap (ename ||' earns salary '|| lpad(sal,5,'.') " Employee Informatio
n" from emp
*
ERROR at line 1:
ORA-00907: missing right parenthesis
SQL> ed
Wrote file afiedt.buf
1* select initcap (ename ||' earns salary '|| lpad(sal,5,'.')) " Employee Info
rmation" from emp
SQL> /
Employee Information
----------------------------Smith Earns Salary ..800
Allen Earns Salary .1600
Ward Earns Salary .1250
Jones Earns Salary .2975
Martin Earns Salary .1250
Blake Earns Salary .2850
Clark Earns Salary .2450
Scott Earns Salary .3000
King Earns Salary .5000
Turner Earns Salary .1500
Adams Earns Salary .1100
James Earns Salary ..950
Ford Earns Salary .3000
Miller Earns Salary .1300
14 rows selected.
SQL> select substr('DONT WASTE TIME',1,4) FROM DUAL;
SUBS
---DONT
1 row selected.
SQL> select substr('DONT WASTE TIME',6,5) from dual;
SUBST
----WASTE
1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',6,) from dual
SQL> /
select substr('DONT WASTE TIME',6,) from dual
*
ERROR at line 1:

ORA-00936: missing expression


SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',6) from dual
SQL> /
SUBSTR('DO
---------WASTE TIME
1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',-4) from dual
SQL> /
SUBS
---TIME
1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',-10,5) from dual
SQL> /
SUBST
----WASTE
1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',0,5) from dual
SQL> /
SUBST
----DONT
1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',6,0) from dual
SQL> /
S
-

1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select substr('DONT WASTE TIME',0,0) from dual
SQL> /
S
1 row selected.
SQL> ed
Wrote file afiedt.buf
1* select instr('DONT WASTE TIME','TIME') from dual
SQL> /
INSTR('DONTWASTETIME','TIME')
----------------------------12
1 row selected.
SQL> SELECT * FROM EMP WHERE INSTR(JOB,'CLERK')>0;
EMPNO
EPTNO
-------------7369
20
7876
20
7900
30
7934
10

ENAME

JOB

MGR HIREDATE

SAL

COMM

---------- --------- ---------- --------- ---------- ---------- ----SMITH

CLERK

7902 17-DEC-80

800

ADAMS

CLERK

7788 12-JAN-83

1100

JAMES

CLERK

7698 03-DEC-81

950

MILLER

CLERK

7782 23-JAN-82

1300

4 rows selected.
SQL>
SQL> ED
Wrote file afiedt.buf
1* select instr('DONT WASTE TIME AS TIME IS PRECIOUS','TIME',1,2) FROM DUAL
SQL> /
INSTR('DONTWASTETIMEASTIMEISPRECIOUS','TIME',1,2)
------------------------------------------------20
1 row selected.
SQL> select instr('DONT WASTE TIME AS TIME IS PRECIOUS','TIME',-1,2) FROM DUAL
2 ;

INSTR('DONTWASTETIMEASTIMEISPRECIOUS','TIME',-1,2)
-------------------------------------------------12
1 row selected.
SQL> SELECT * FROM EMP WHERE SUBSTR(JOB,1,2)>0;
SELECT * FROM EMP WHERE SUBSTR(JOB,1,2)>0
*
ERROR at line 1:
ORA-01722: invalid number
SQL> DEFINE STR='DONT WASTE TIME AS TIME IS PRECIOUS"
string beginning "'DONT WAST..." missing terminating quote (').
SQL> DEFINE STR='DONT WASTE TIME AS TIME IS PRECIOUS'
SQL> SELECT SUBSTR(&STR,INSTR(&STR,'TIME',1,2)) FROM DUAL;
old 1: SELECT SUBSTR(&STR,INSTR(&STR,'TIME',1,2)) FROM DUAL
new 1: SELECT SUBSTR(DONT WASTE TIME AS TIME IS PRECIOUS,INSTR(DONT WASTE TIME
AS TIME IS PRECIOUS
SELECT SUBSTR(DONT WASTE TIME AS TIME IS PRECIOUS,INSTR(DONT WASTE TIME AS TIME
IS PRECIOUS,'TIME',1
*
ERROR at line 1:
ORA-00907: missing right parenthesis
SQL> ED
Wrote file afiedt.buf
1* SELECT SUBSTR('&STR',INSTR('&STR','TIME',1,2)) FROM DUAL
SQL> /
old 1: SELECT SUBSTR('&STR',INSTR('&STR','TIME',1,2)) FROM DUAL
new 1: SELECT SUBSTR('DONT WASTE TIME AS TIME IS PRECIOUS',INSTR('DONT WASTE T
IME AS TIME IS PRECI
SUBSTR('DONTWAST
---------------TIME IS PRECIOUS
1 row selected.

SQL> ED
Wrote file afiedt.buf
1* SELECT SUBSTR('&STR',INSTR('&STR','TIME',1,2),5) FROM DUAL
SQL> /
old 1: SELECT SUBSTR('&STR',INSTR('&STR','TIME',1,2),5) FROM DUAL
new 1: SELECT SUBSTR('DONT WASTE TIME AS TIME IS PRECIOUS',INSTR('DONT WASTE T
IME AS TIME IS PRECI
SUBST
----TIME
1 row selected.
SQL> SELECT ENAME(LENGTH) FROM EMP;

SELECT ENAME(LENGTH) FROM EMP


*
ERROR at line 1:
ORA-00904: "ENAME": invalid identifier
SQL> SELECT ENAME, LENGTH(ENAME) FROM EMP;
ENAME
LENGTH(ENAME)
---------- ------------SMITH
5
ALLEN
5
WARD
4
JONES
5
MARTIN
6
BLAKE
5
CLARK
5
SCOTT
5
KING
4
TURNER
6
ADAMS
5
JAMES
5
FORD
4
MILLER
6
14 rows selected.
SQL> SELECT ENAME, LENGTH(ENAME) FROM EMP WHERE LENGTH(ENAME)>4;
ENAME
LENGTH(ENAME)
---------- ------------SMITH
5
ALLEN
5
JONES
5
MARTIN
6
BLAKE
5
CLARK
5
SCOTT
5
TURNER
6
ADAMS
5
JAMES
5
MILLER
6
11 rows selected.
SQL> SELECT TRIM('

HELLO

')FROM DUAL;

TRIM(
----HELLO
1 row selected.
SQL> SELECT TRIM (BOTH '.' FROM '.........HELLO......');
SELECT TRIM (BOTH '.' FROM '.........HELLO......')
*
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

SQL> ED
Wrote file afiedt.buf
1* SELECT TRIM (BOTH '.' FROM '.........HELLO......')FROM DUAL
SQL> /
TRIM(
----HELLO
1 row selected.
SQL> SELECT TRIM (LEADING '.'FROM '.......HELLOO...') FROM DUAL;
TRIM(LEAD
--------HELLOO...
1 row selected.
SQL> SELECT TRIM (BOTH '.' FROM '..........HELOOO

') FROM DUAL;

TRIM(BOTH'.'FRO
--------------HELOOO
1 row selected.
SQL> SELECT TRIM (BOTH '.' FROM '

HELLOO......') FROM DUAL;

TRIM(BOTH'.'
-----------HELLOO
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT TRIM (BOTH '.' FROM '
SQL> /

HELLOO..

...') FROM DUAL

TRIM(BOTH'.'FROM'H
-----------------HELLOO..
1 row selected.
SQL> SELECT RTRIM ('......HELLO.....','.') FROM DUAL;
RTRIM('....
----------......HELLO
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT LTRIM ('......HELLO.....','.') FROM DUAL

SQL> /
LTRIM('...
---------HELLO.....
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT LTRIM ('......HELLO.
SQL> /

xx....','.x') FROM DUAL

LTRIM('......HE
--------------HELLO. xx....
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT RTRIM ('......HELLO.
SQL> /

xx....','.x') FROM DUAL

RTRIM('......HE
--------------......HELLO.
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT RTRIM ('......HELLO.
SQL> /

xx....','. x') FROM DUAL

RTRIM('....
----------......HELLO
1 row selected.
SQL>
SQL> ED
Wrote file afiedt.buf
1* SELECT RTRIM ('......HELLO.
SQL> /

xx....','') FROM DUAL

R
1 row selected.
SQL> SELECT ROUND(655.63219,2) FROM DUAL;

ROUND(655.63219,2)
-----------------655.63
1 row selected.
SQL> SELECT ROUND(655.63219,-1) FROM DUAL;
ROUND(655.63219,-1)
------------------660
1 row selected.
SQL> SELECT ROUND(655.63219,-2) FROM DUAL;
ROUND(655.63219,-2)
------------------700
1 row selected.
SQL> SELECT ROUND(655.63219,-3) FROM DUAL;
ROUND(655.63219,-3)
------------------1000
1 row selected.
SQL> SELECT ROUND(655.63219,-5) FROM DUAL;
ROUND(655.63219,-5)
------------------0
1 row selected.
SQL> SELECT TRUNC(49.2342,1) FROM DUAL;
TRUNC(49.2342,1)
---------------49.2
1 row selected.
SQL> SELECT TRUNC(49.2342,-2) FROM DUAL;
TRUNC(49.2342,-2)
----------------0
1 row selected.
SQL> SELECT TRUNC(49.2342,-1) FROM DUAL;
TRUNC(49.2342,-1)
----------------40

1 row selected.
SQL> SELECT TRUNC(49.266,2) FROM DUAL;
TRUNC(49.266,2)
--------------49.26
1 row selected.
SQL> SELECT MOD(2000,300) FROM DUAL;
MOD(2000,300)
------------200
1 row selected.
SQL> SELECT MOD( 2100,300) FROM DUAL;
MOD(2100,300)
------------0
1 row selected.
SQL> SELECT MOD (0,0) FROM DUAL;
MOD(0,0)
---------0
1 row selected.
SQL> SELECT MOD (800,0) FROM DUAL;
MOD(800,0)
---------800
1 row selected.

SQL> SELECT SYSDATE FROM DUAL;


SYSDATE
--------26-APR-14
1 row selected.
SQL> SELECT SYSDATE+1 FROM DUAL;
SYSDATE+1
--------27-APR-14

1 row selected.
SQL> SELECT CURRENT_TIMESTAMP FROM DUAL;
CURRENT_TIMESTAMP
--------------------------------------------------------------------------26-APR-14 02.00.12.138000 PM +05:30
1 row selected.
SQL> SELECT LOCAL_TIMESTAMP FROM DUAL;
SELECT LOCAL_TIMESTAMP FROM DUAL
*
ERROR at line 1:
ORA-00904: "LOCAL_TIMESTAMP": invalid identifier
SQL> SELECT LOCALTIMESTAMP FROM DUAL;
LOCALTIMESTAMP
--------------------------------------------------------------------------26-APR-14 02.01.31.027000 PM
1 row selected.
SQL> ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY HH:MI:SS AM';
Session altered.
SQL> SELECT SYSDATE FROM DUAL;
SYSDATE
----------------------26-APR-2014 02:05:10 PM
1 row selected.
SQL> SELECT SYSDATE FROM DUAL;
SYSDATE
----------------------26-APR-2014 02:05:40 PM
1 row selected.
SQL> SELECT SYSDATE+1 FROM DUAL;
SYSDATE+1
----------------------27-APR-2014 02:05:56 PM
1 row selected.
SQL> SELECT SYSDATE+1/24 FROM DUAL;
SYSDATE+1/24
----------------------26-APR-2014 03:06:14 PM
1 row selected.

SQL> SELECT EMPNO,ENAME,SYSDATE,HIREDATE FROM EMP;


EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

ENAME
---------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

SYSDATE
----------------------26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM
26-APR-2014 02:07:55 PM

HIREDATE
----------------------17-DEC-1980 12:00:00 AM
20-FEB-1981 12:00:00 AM
22-FEB-1981 12:00:00 AM
02-APR-1981 12:00:00 AM
28-SEP-1981 12:00:00 AM
01-MAY-1981 12:00:00 AM
09-JUN-1981 12:00:00 AM
09-DEC-1982 12:00:00 AM
17-NOV-1981 12:00:00 AM
08-SEP-1981 12:00:00 AM
12-JAN-1983 12:00:00 AM
03-DEC-1981 12:00:00 AM
03-DEC-1981 12:00:00 AM
23-JAN-1982 12:00:00 AM

14 rows selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT EMPNO,ENAME,SYSDATE,HIREDATE,SYSDATE-HIREDATE FROM EMP
SQL> /
EMPNO
REDATE
--------------7369
3.5898
7499
8.5898
7521
6.5898
7566
7.5898
7654
8.5898
7698
8.5898
7782
9.5898
7788
1.5898
7839
8.5898
7844
8.5898
7876
7.5898
7900
2.5898
7902
2.5898
7934
1.5898

ENAME

SYSDATE

HIREDATE

SYSDATE-HI

---------- ----------------------- ----------------------- ---------SMITH

26-APR-2014 02:09:21 PM 17-DEC-1980 12:00:00 AM

1218

ALLEN

26-APR-2014 02:09:21 PM 20-FEB-1981 12:00:00 AM

1211

WARD

26-APR-2014 02:09:21 PM 22-FEB-1981 12:00:00 AM

1211

JONES

26-APR-2014 02:09:21 PM 02-APR-1981 12:00:00 AM

1207

MARTIN

26-APR-2014 02:09:21 PM 28-SEP-1981 12:00:00 AM

1189

BLAKE

26-APR-2014 02:09:21 PM 01-MAY-1981 12:00:00 AM

1204

CLARK

26-APR-2014 02:09:21 PM 09-JUN-1981 12:00:00 AM

1200

SCOTT

26-APR-2014 02:09:21 PM 09-DEC-1982 12:00:00 AM

1146

KING

26-APR-2014 02:09:21 PM 17-NOV-1981 12:00:00 AM

1184

TURNER

26-APR-2014 02:09:21 PM 08-SEP-1981 12:00:00 AM

1191

ADAMS

26-APR-2014 02:09:21 PM 12-JAN-1983 12:00:00 AM

1142

JAMES

26-APR-2014 02:09:21 PM 03-DEC-1981 12:00:00 AM

1183

FORD

26-APR-2014 02:09:21 PM 03-DEC-1981 12:00:00 AM

1183

MILLER

26-APR-2014 02:09:21 PM 23-JAN-1982 12:00:00 AM

1178

14 rows selected.
SQL> UPDATE EMP SET HIREDATE-SYSDATE WHERE ENAME='ALLEN';
UPDATE EMP SET HIREDATE-SYSDATE WHERE ENAME='ALLEN'
*
ERROR at line 1:
ORA-00927: missing equal sign
SQL> ED
Wrote file afiedt.buf
1* UPDATE EMP SET HIREDATE=SYSDATE WHERE ENAME='ALLEN'
SQL> /
1 row updated.
SQL> SELECT EMPNO,ENAME,SYSDATE,HIREDATE,TRUNC(SYSDATE-HIREDATE) FROM EMP;
EMPNO ENAME
ATE-HIREDATE)
---------- ---------------------7369 SMITH
12183
7499 ALLEN
0
7521 WARD
12116
7566 JONES
12077
7654 MARTIN
11898
7698 BLAKE
12048
7782 CLARK
12009
7788 SCOTT
11461
7839 KING
11848
7844 TURNER
11918
7876 ADAMS
11427
7900 JAMES
11832
7902 FORD
11832
7934 MILLER
11781

SYSDATE

HIREDATE

TRUNC(SYSD

----------------------- ----------------------- ---------26-APR-2014 02:13:32 PM 17-DEC-1980 12:00:00 AM


26-APR-2014 02:13:32 PM 26-APR-2014 02:12:54 PM
26-APR-2014 02:13:32 PM 22-FEB-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 02-APR-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 28-SEP-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 01-MAY-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 09-JUN-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 09-DEC-1982 12:00:00 AM
26-APR-2014 02:13:32 PM 17-NOV-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 08-SEP-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 12-JAN-1983 12:00:00 AM
26-APR-2014 02:13:32 PM 03-DEC-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 03-DEC-1981 12:00:00 AM
26-APR-2014 02:13:32 PM 23-JAN-1982 12:00:00 AM

14 rows selected.
SQL> SELECT * FROM EMP;
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
---------- ---------- --------- ---------- ----------------------- ---------- --

-------- ---------7369 SMITH


20
7499 ALLEN
300
30
7521 WARD
500
30
7566 JONES
20
7654 MARTIN
1400
30
7698 BLAKE
30
7782 CLARK
10
7788 SCOTT
20
7839 KING
10
7844 TURNER
0
30
7876 ADAMS
20
7900 JAMES
30
7902 FORD
20
7934 MILLER
10

CLERK

7902 17-DEC-1980 12:00:00 AM

800

SALESMAN

7698 26-APR-2014 02:12:54 PM

1600

SALESMAN

7698 22-FEB-1981 12:00:00 AM

1250

MANAGER

7839 02-APR-1981 12:00:00 AM

2975

SALESMAN

7698 28-SEP-1981 12:00:00 AM

1250

MANAGER

7839 01-MAY-1981 12:00:00 AM

2850

MANAGER

7839 09-JUN-1981 12:00:00 AM

2450

ANALYST

7566 09-DEC-1982 12:00:00 AM

3000

17-NOV-1981 12:00:00 AM

5000

SALESMAN

7698 08-SEP-1981 12:00:00 AM

1500

CLERK

7788 12-JAN-1983 12:00:00 AM

1100

CLERK

7698 03-DEC-1981 12:00:00 AM

950

ANALYST

7566 03-DEC-1981 12:00:00 AM

3000

CLERK

7782 23-JAN-1982 12:00:00 AM

1300

PRESIDENT

14 rows selected.
SQL> UPDATE EMP SET HIREDATE='26-APR-2014' WHERE EMPNO=7844;
1 row updated.
SQL> SELECT * FROM EMP;
EMPNO ENAME
COMM
DEPTNO
---------- ----------------- ---------7369 SMITH
20
7499 ALLEN
300
30
7521 WARD
500
30
7566 JONES
20
7654 MARTIN
1400
30
7698 BLAKE
30
7782 CLARK
10
7788 SCOTT
20
7839 KING
10

JOB

MGR HIREDATE

SAL

--------- ---------- ----------------------- ---------- -CLERK

7902 17-DEC-1980 12:00:00 AM

800

SALESMAN

7698 26-APR-2014 02:12:54 PM

1600

SALESMAN

7698 22-FEB-1981 12:00:00 AM

1250

MANAGER

7839 02-APR-1981 12:00:00 AM

2975

SALESMAN

7698 28-SEP-1981 12:00:00 AM

1250

MANAGER

7839 01-MAY-1981 12:00:00 AM

2850

MANAGER

7839 09-JUN-1981 12:00:00 AM

2450

ANALYST

7566 09-DEC-1982 12:00:00 AM

3000

17-NOV-1981 12:00:00 AM

5000

PRESIDENT

7844 TURNER
0
30
7876 ADAMS
20
7900 JAMES
30
7902 FORD
20
7934 MILLER
10

SALESMAN

7698 26-APR-2014 12:00:00 AM

1500

CLERK

7788 12-JAN-1983 12:00:00 AM

1100

CLERK

7698 03-DEC-1981 12:00:00 AM

950

ANALYST

7566 03-DEC-1981 12:00:00 AM

3000

CLERK

7782 23-JAN-1982 12:00:00 AM

1300

14 rows selected.
SQL> SELECT * FROM EMP WHERE HIREDATE='26-APR-2014';
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
---------- ---------- --------- ---------- ----------------------- ---------- --------- ---------7844 TURNER
SALESMAN
7698 26-APR-2014 12:00:00 AM
1500
0
30
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT * FROM EMP WHERE HIREDATE=SYSDATE
SQL> /
no rows selected
SQL> SELECT * FROM EMP WHERE ENAME='ALLEN';
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
---------- ---------- --------- ---------- ----------------------- ---------- --------- ---------7499 ALLEN
SALESMAN
7698 26-APR-2014 02:12:54 PM
1600
300
30
1 row selected.
SQL> SELECT TRUNC(HIREDATE,'DAY') FROM EMP;
TRUNC(HIREDATE,'DAY')
----------------------14-DEC-1980 12:00:00 AM
20-APR-2014 12:00:00 AM
22-FEB-1981 12:00:00 AM
29-MAR-1981 12:00:00 AM
27-SEP-1981 12:00:00 AM
26-APR-1981 12:00:00 AM
07-JUN-1981 12:00:00 AM
05-DEC-1982 12:00:00 AM
15-NOV-1981 12:00:00 AM
20-APR-2014 12:00:00 AM
09-JAN-1983 12:00:00 AM
29-NOV-1981 12:00:00 AM
29-NOV-1981 12:00:00 AM

17-JAN-1982 12:00:00 AM
14 rows selected.
SQL> SELECT EMPNO,ENAME,TRUNC(SYSDATE,HIREDATE) FROM EMP;
SELECT EMPNO,ENAME,TRUNC(SYSDATE,HIREDATE) FROM EMP
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE
SQL> SELECT EMPNO,ENAME,TRUNC(SYSDATE),TRUNC(HIREDATE) FROM EMP;
EMPNO
---------7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

ENAME
---------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

TRUNC(SYSDATE)
----------------------26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM
26-APR-2014 12:00:00 AM

TRUNC(HIREDATE)
----------------------17-DEC-1980 12:00:00 AM
26-APR-2014 12:00:00 AM
22-FEB-1981 12:00:00 AM
02-APR-1981 12:00:00 AM
28-SEP-1981 12:00:00 AM
01-MAY-1981 12:00:00 AM
09-JUN-1981 12:00:00 AM
09-DEC-1982 12:00:00 AM
17-NOV-1981 12:00:00 AM
26-APR-2014 12:00:00 AM
12-JAN-1983 12:00:00 AM
03-DEC-1981 12:00:00 AM
03-DEC-1981 12:00:00 AM
23-JAN-1982 12:00:00 AM

14 rows selected.
SQL>

SQL> SELECT NEXT_DAY (SYSDATE,'FRIDAY') FROM DUAL;


NEXT_DAY(SYSDATE,'FRIDA
----------------------02-MAY-2014 02:36:20 PM
1 row selected.
SQL> SELECT LAST_DAY(SYSDATE) FROM DUAL;
LAST_DAY(SYSDATE)
----------------------30-APR-2014 02:39:55 PM
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT '15-SEP-2014'-1 FROM DUAL
SQL> /
SELECT '15-SEP-2014'-1 FROM DUAL
*

ERROR at line 1:
ORA-01722: invalid number
SQL> ED
Wrote file afiedt.buf
1* SELECT TO_DATE('15-SEP-2014')-1 FROM DUAL
SQL> /
TO_DATE('15-SEP-2014')----------------------14-SEP-2014 12:00:00 AM
1 row selected.
SQL> SELECT TO_CHAR(SYSDATE,'DD-MM-YYYY) FROM DUAL;
ERROR:
ORA-01756: quoted string not properly terminated
SQL> ED
Wrote file afiedt.buf
1* SELECT TO_CHAR(SYSDATE,'DD-MM-YYYY') FROM DUAL
SQL> /
TO_CHAR(SY
---------26-04-2014
1 row selected.
SQL> SELECT TO_CHAR(SYSDATE,'D-DD-DDD') FROM DUAL;
TO_CHAR(
-------7-26-116
1 row selected.
SQL> SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'DD')='17;
ERROR:
ORA-01756: quoted string not properly terminated
SQL> ED
Wrote file afiedt.buf
1* SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'DD')='17'
SQL> /
EMPNO ENAME
COMM
DEPTNO
---------- ----------------- ---------7369 SMITH
20
7839 KING
10

JOB

MGR HIREDATE

SAL

--------- ---------- ----------------------- ---------- -CLERK


PRESIDENT

7902 17-DEC-1980 12:00:00 AM

800

17-NOV-1981 12:00:00 AM

5000

2 rows selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'D')='6'
SQL> /
EMPNO ENAME
JOB
MGR HIREDATE
SAL
COMM
DEPTNO
---------- ---------- --------- ---------- ----------------------- ---------- --------- ---------7698 BLAKE
MANAGER
7839 01-MAY-1981 12:00:00 AM
2850
30
1 row selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'DD')='03'
SQL> /
EMPNO ENAME
COMM
DEPTNO
---------- ----------------- ---------7900 JAMES
30
7902 FORD
20

JOB

MGR HIREDATE

--------- ---------- ----------------------- ---------- -CLERK

7698 03-DEC-1981 12:00:00 AM

950

ANALYST

7566 03-DEC-1981 12:00:00 AM

3000

2 rows selected.
SQL> ED
Wrote file afiedt.buf
1* SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'DD')='3'
SQL> /
no rows selected

SQL> ED
Wrote file afiedt.buf
1*
SQL>
1*
SQL>

SAL

SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'DDD')='135'


;
SELECT * FROM EMP WHERE TO_CHAR(HIREDATE,'DDD')='135'
/

no rows selected
SQL> SELECT EMPNO,ENAME,TO_CHAR(HIREDATE,'Day') from emp;
EMPNO ENAME
TO_CHAR(H
---------- ---------- ---------

7369
7499
7521
7566
7654
7698
7782
7788
7839
7844
7876
7900
7902
7934

SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER

Wednesday
Saturday
Sunday
Thursday
Monday
Friday
Tuesday
Thursday
Tuesday
Saturday
Wednesday
Thursday
Thursday
Saturday

14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* SELECT EMPNO,ENAME,TO_CHAR(HIREDATE,'Day') from emp where TO_CHAR(HIREDATE,
'Day')='Thursday'
SQL> /
no rows selected
SQL> ed
Wrote file afiedt.buf
1* SELECT EMPNO,ENAME,TO_CHAR(HIREDATE,'fmDay') from emp where TO_CHAR(HIREDAT
E,'fmDay')='Thursday
SQL> /
EMPNO
---------7566
7788
7900
7902

ENAME
---------JONES
SCOTT
JAMES
FORD

4 rows selected.

TO_CHAR(H
--------Thursday
Thursday
Thursday
Thursday