Professional Documents
Culture Documents
2 /
NVL2(NULL,1000,2000)
-------------------2000
SQL> ed
Wrote file afiedt.buf
1* select
2 /
NVL2(100,1000,2000)
------------------1000
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1 select ename,sal,comm,sal+nvl2(comm,comm+comm*0.25,100)
2* from emp
3 /
ENAME
SAL
COMM SAL+NVL2(COMM,COMM+COMM*0.25,100)
---------- --------- --------- --------------------------------SMITH
800
900
ALLEN
1600
300
1975
WARD
1250
500
1875
JONES
2975
3075
MARTIN
1250
1400
3000
BLAKE
2850
2950
CLARK
2450
2550
SCOTT
3000
3100
KING
5000
5100
TURNER
1500
0
1500
ADAMS
1100
1200
JAMES
950
1050
FORD
3000
3100
MILLER
1300
1400
14 rows selected.
SQL> ED
Wrote file afiedt.buf
1 select ename,sal,comm,nvl2(comm,'sal+comm','sal')
2* from emp
3 /
ENAME
SAL
COMM NVL2(COM
---------- --------- --------- -------SMITH
800
sal
ALLEN
1600
300 sal+comm
WARD
1250
500 sal+comm
JONES
2975
sal
MARTIN
1250
1400 sal+comm
BLAKE
2850
sal
CLARK
2450
sal
SCOTT
3000
sal
KING
TURNER
ADAMS
JAMES
FORD
MILLER
5000
1500
1100
950
3000
1300
sal
0 sal+comm
sal
sal
sal
sal
14 rows selected.
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1 select ename,sal,comm,nvl2(comm,'sal+comm','sal')
2* from emp
3
SQL> clear screen
SQL> select nullif(
2
SQL> ed
Wrote file afiedt.buf
1* select nullif(100,200) from dual
2 /
NULLIF(100,200)
--------------100
SQL> ed
Wrote file afiedt.buf
1* select nullif(100,100) from dual
2 /
NULLIF(100,100)
--------------SQL> ed
Wrote file afiedt.buf
1* select nullif(100,100) from dual
2
SQL> /
NULLIF(100,100)
--------------SQL> clear screen
SQL> ed
Wrote file afiedt.buf
line 1 truncated.
1* SELECT coalesce(100,600,200) FROM dua
SQL>
SQL>
SQL> ed
Wrote file afiedt.buf
select ename,sal,sal*0.45,sal*0.35,sal*0.15,
sal+sal*0.45+sal*0.35-sal*0.15
from emp
/
ENAME
SAL SAL*0.45 SAL*0.35 SAL*0.15 SAL+SAL*0.45+SAL*0.35SAL*0.15
---------- --------- --------- --------- -------------------------------------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
4908.75
MARTIN
2062.5
BLAKE
4702.5
CLARK
4042.5
SCOTT
4950
KING
8250
TURNER
2475
ADAMS
1815
JAMES
1567.5
FORD
4950
MILLER
2145
2975
1338.75
1041.25
446.25
1250
562.5
437.5
187.5
2850
1282.5
997.5
427.5
2450
1102.5
857.5
367.5
3000
1350
1050
450
5000
2250
1750
750
1500
675
525
225
1100
495
385
165
950
427.5
332.5
142.5
3000
1350
1050
450
1300
585
455
195
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1
2
3*
4
ENAME
BASIC
HRA
DA
PF
GROSS
---------- --------- --------- --------- --------- --------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
2975
1338.75
1041.25
446.25
4908.75
MARTIN
1250
562.5
437.5
187.5
2062.5
BLAKE
2850
1282.5
997.5
427.5
4702.5
CLARK
2450
1102.5
857.5
367.5
4042.5
SCOTT
3000
1350
1050
450
4950
KING
5000
2250
1750
750
8250
TURNER
1500
675
525
225
2475
ADAMS
1100
495
385
165
1815
JAMES
950
427.5
332.5
142.5
1567.5
FORD
3000
1350
1050
450
4950
MILLER
1300
585
455
195
2145
14 rows selected.
SQL> clear screen
SQL> /
ENAME
BASIC
HRA
DA
PF
GROSS
---------- --------- --------- --------- --------- --------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
2975
1338.75
1041.25
446.25
4908.75
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
1250
2850
2450
3000
5000
1500
1100
950
3000
1300
562.5
1282.5
1102.5
1350
2250
675
495
427.5
1350
585
437.5
997.5
857.5
1050
1750
525
385
332.5
1050
455
187.5
427.5
367.5
450
750
225
165
142.5
450
195
2062.5
4702.5
4042.5
4950
8250
2475
1815
1567.5
4950
2145
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1
2
3
4*
5
ENAME
Basic
Hra
Da
Pf
Gross
---------- --------- --------- --------- --------- --------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
2975
1338.75
1041.25
446.25
4908.75
MARTIN
1250
562.5
437.5
187.5
2062.5
BLAKE
2850
1282.5
997.5
427.5
4702.5
CLARK
2450
1102.5
857.5
367.5
4042.5
SCOTT
3000
1350
1050
450
4950
KING
5000
2250
1750
750
8250
TURNER
1500
675
525
225
2475
ADAMS
1100
495
385
165
1815
JAMES
950
427.5
332.5
142.5
1567.5
FORD
3000
1350
1050
450
4950
MILLER
1300
585
455
195
2145
14 rows selected.
SQL> clear screen
SQL> /
ENAME
Basic
Hra
Da
Pf
Gross
---------- --------- --------- --------- --------- --------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
2975
1338.75
1041.25
446.25
4908.75
MARTIN
1250
562.5
437.5
187.5
2062.5
BLAKE
2850
1282.5
997.5
427.5
4702.5
CLARK
2450
1102.5
857.5
367.5
4042.5
SCOTT
3000
1350
1050
450
4950
KING
5000
2250
1750
750
8250
TURNER
1500
675
525
225
2475
ADAMS
1100
495
385
165
1815
JAMES
950
427.5
332.5
142.5
1567.5
FORD
3000
1350
1050
450
4950
MILLER
1300
585
455
195
2145
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select ename,sal "Basic",sal*0.45 "Hra",sal*0.35 "Da",
2 sal*0.15 "Pf",
3 sal+hra+sal*0.35-sal*0.15 "Gross"
4* from emp
5 /
sal+hra+sal*0.35-sal*0.15 "Gross"
*
ERROR at line 3:
ORA-00904: "HRA": invalid identifier
SQL> ed
Wrote file afiedt.buf
1
2
3
4*
5
Emp Name
Basic
Hra
Da
Pf
Gross
---------- --------- --------- --------- --------- --------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
2975
1338.75
1041.25
446.25
4908.75
MARTIN
1250
562.5
437.5
187.5
2062.5
BLAKE
2850
1282.5
997.5
427.5
4702.5
CLARK
2450
1102.5
857.5
367.5
4042.5
SCOTT
3000
1350
1050
450
4950
KING
5000
2250
1750
750
8250
TURNER
1500
675
525
225
2475
ADAMS
1100
495
385
165
1815
JAMES
950
427.5
332.5
142.5
1567.5
FORD
3000
1350
1050
450
4950
MILLER
1300
585
455
195
2145
14 rows selected.
SQL> clear screen
SQL> /
Emp Name
Basic
Hra
Da
Pf
Gross
---------- --------- --------- --------- --------- --------SMITH
800
360
280
120
1320
ALLEN
1600
720
560
240
2640
WARD
1250
562.5
437.5
187.5
2062.5
JONES
2975
1338.75
1041.25
446.25
4908.75
MARTIN
1250
562.5
437.5
187.5
2062.5
BLAKE
2850
1282.5
997.5
427.5
4702.5
CLARK
2450
1102.5
857.5
367.5
4042.5
SCOTT
3000
1350
1050
450
4950
KING
5000
2250
1750
750
8250
TURNER
1500
675
525
225
2475
ADAMS
1100
495
385
165
1815
JAMES
950
427.5
332.5
142.5
1567.5
FORD
MILLER
3000
1300
1350
585
1050
455
450
195
14 rows selected.
4950
2145
SQL> ed
Wrote file afiedt.buf
1
2
3
4*
5
6
SQL>
SQL>
ENAME
---------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1* select 'The emp name is '||ename from emp
2 /
'THEEMPNAMEIS'||ENAME
-------------------------The emp name is SMITH
The emp name is ALLEN
The emp name is WARD
The emp name is JONES
The emp name is MARTIN
The emp name is BLAKE
The emp name is CLARK
The emp name is SCOTT
The emp name is KING
The emp name is TURNER
The emp name is ADAMS
The emp name is JAMES
The emp name is FORD
The emp name is MILLER
14 rows selected.
The
The
The
The
The
emp
emp
emp
emp
emp
name
name
name
name
name
is
is
is
is
is
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select 'The emp name is '||ename
2* from emp
3 /
"Emp Name"
Emp Name
-------------------------The emp name is SMITH
The emp name is ALLEN
The emp name is WARD
The emp name is JONES
The emp name is MARTIN
The emp name is BLAKE
The emp name is CLARK
The emp name is SCOTT
The emp name is KING
The emp name is TURNER
The emp name is ADAMS
The emp name is JAMES
The emp name is FORD
The emp name is MILLER
14 rows selected.
SQL> clear screen
SQL> /
Emp Name
-------------------------The emp name is SMITH
The emp name is ALLEN
The emp name is WARD
The emp name is JONES
The emp name is MARTIN
The emp name is BLAKE
The emp name is CLARK
The emp name is SCOTT
The emp name is KING
The emp name is TURNER
The emp name is ADAMS
The emp name is JAMES
The emp name is FORD
The emp name is MILLER
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select 'The emp name is '||ename
2* from emp
"Emp Name"
3
SQL>
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
1 select 'The emp name is '||ename
2* from emp
3
SQL>
SQL> clear screen
SQL> ed
Wrote file afiedt.buf
"Emp Name"
14 rows selected.
SQL> ed
Wrote file afiedt.buf
1 select 'The '||ename||''s job is '||job "Emp and Job"
2* from emp
SQL> /
ERROR:
ORA-01756: quoted string not properly terminated
SQL> ed
Wrote file afiedt.buf
1 select 'The '||ename||'''s job is '||job "Emp and Job"
2* from emp
SQL> /
Emp and Job
--------------------------------The SMITH's job is CLERK
The ALLEN's job is SALESMAN
The WARD's job is SALESMAN
The JONES's job is MANAGER
The MARTIN's job is SALESMAN
The BLAKE's job is MANAGER
The CLARK's job is MANAGER
The SCOTT's job is ANALYST
The KING's job is PRESIDENT
The TURNER's job is SALESMAN
The ADAMS's job is CLERK
The JAMES's job is CLERK
The FORD's job is ANALYST
The MILLER's job is CLERK
14 rows selected.
SQL> clear screen
SQL> /
Emp and Job
--------------------------------The SMITH's job is CLERK
The ALLEN's job is SALESMAN
The WARD's job is SALESMAN
The JONES's job is MANAGER
The MARTIN's job is SALESMAN
The BLAKE's job is MANAGER
The CLARK's job is MANAGER
The SCOTT's job is ANALYST
The KING's job is PRESIDENT
The TURNER's job is SALESMAN
The ADAMS's job is CLERK
The JAMES's job is CLERK
The FORD's job is ANALYST
The MILLER's job is CLERK
14 rows selected.
is '||(sal+sal*0.45+sal*0.35-
Type
---NUMBER(4)
VARCHAR2(10)
VARCHAR2(9)
NUMBER(4)
DATE
NUMBER(7,2)
NUMBER(7,2)
NUMBER(2)