You are on page 1of 37

/

TO_CHAR(

1234.00

SQL> ed
Wrote file afiedt.buf

1* Select TO_CHAR(1234,9999D999') From Dual


SQL> /

TO_CHAR(1

1234.000

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 Select ename,TO_CHAR(sal,9999D99')
2* From emp
3 /

ENAME TO_CHAR(

SMITH 800.00
ALLEN 1600.00
WARD 1250.00
JONES 2975.00
MARTIN 1250.00
BLAKE 2850.00
CLARK 2450.00
SCOTT 3000.00
KING 5000.00
TURNER 1500.00
ADAMS 1100.00

ENAME TO_CHAR(

JAMES 950.00
FORD 3000.00
MILLER 1300.00
JAN 2000.00
JAN 4000.00

16 rows selected.

SQL> set pagesize 100


SQL> /

ENAME TO_CHAR(

SMITH 800.00
ALLEN 1600.00
WARD 1250.00
JONES 2975.00
MARTIN 1250.00
BLAKE 2850.00
CLARK 2450.00
SCOTT 3000.00
KING 5000.00
TURNER 1500.00
ADAMS 1100.00
JAMES 950.00
FORD 3000.00
MILLER 1300.00
JAN 2000.00
JAN 4000.00

16 rows selected.

SQL> delete from emp


2 where ename=JAN;

2 rows deleted.

SQL> commit;

Commit complete.

SQL> Select ename,TO_CHAR(sal,9999D99')


2 From emp
3 /

ENAME TO_CHAR(

SMITH 800.00
ALLEN 1600.00
WARD 1250.00
JONES 2975.00
MARTIN 1250.00
BLAKE 2850.00
CLARK 2450.00
SCOTT 3000.00
KING 5000.00
TURNER 1500.00
ADAMS 1100.00
JAMES 950.00
FORD 3000.00
MILLER 1300.00

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 Select ename,TO_CHAR(sal,9G999D99')
2* From emp
3 /

ENAME TO_CHAR(S

SMITH 800.00
ALLEN 1,600.00
WARD 1,250.00
JONES 2,975.00
MARTIN 1,250.00
BLAKE 2,850.00
CLARK 2,450.00
SCOTT 3,000.00
KING 5,000.00
TURNER 1,500.00
ADAMS 1,100.00
JAMES 950.00
FORD 3,000.00
MILLER 1,300.00

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 Select TO_CHAR(5373484,99G99G999D99')
2* From dual
SQL> /

TO_CHAR(53734
-
53,73,484.00

SQL> clear screen


SQL> /

TO_CHAR(53734
-
53,73,484.00

SQL> ed
Wrote file afiedt.buf

1 Select TO_CHAR(5373484,99,99,999.99')
2* From dual
SQL> /

TO_CHAR(53734
-
53,73,484.00

SQL> ed
Wrote file afiedt.buf

1 Select TO_CHAR(5373484,99,99,999D99')
2* From dual
SQL> /
Select TO_CHAR(5373484,99,99,999D99')
*
ERROR at line 1:
ORA-01481: invalid number format model
SQL> clear screen
SQL> ed
Wrote file afiedt.buf

1 Select ename,sal
2* From emp
3
SQL> clear screen
SQL> /

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 ename,to_char(sal,L9G999D99')
2* From emp
SQL> /

ENAME TO_CHAR(SAL,L9G999
-
SMITH $800.00
ALLEN $1,600.00
WARD $1,250.00
JONES $2,975.00
MARTIN $1,250.00
BLAKE $2,850.00
CLARK $2,450.00
SCOTT $3,000.00
KING $5,000.00
TURNER $1,500.00
ADAMS $1,100.00
JAMES $950.00
FORD $3,000.00
MILLER $1,300.00

14 rows selected.

SQL> clear screen


SQL> /

ENAME TO_CHAR(SAL,L9G999
-
SMITH $800.00
ALLEN $1,600.00
WARD $1,250.00
JONES $2,975.00
MARTIN $1,250.00
BLAKE $2,850.00
CLARK $2,450.00
SCOTT $3,000.00
KING $5,000.00
TURNER $1,500.00
ADAMS $1,100.00
JAMES $950.00
FORD $3,000.00
MILLER $1,300.00

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 Select ename,to_char(sal,C9G999D99')
2* From emp
SQL> /

ENAME TO_CHAR(SAL,C9G
-
SMITH USD800.00
ALLEN USD1,600.00
WARD USD1,250.00
JONES USD2,975.00
MARTIN USD1,250.00
BLAKE USD2,850.00
CLARK USD2,450.00
SCOTT USD3,000.00
KING USD5,000.00
TURNER USD1,500.00
ADAMS USD1,100.00
JAMES USD950.00
FORD USD3,000.00
MILLER USD1,300.00

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 Select ename,Sal,
2 TO_CHAR(Sal*67,L99G99G999D99',NLS_CURRENCY=IndRupees)
3* from emp
SQL> /

ENAME SAL TO_CHAR(SAL*67,L99G99G


-
SMITH 800 IndRupees53,600.00
ALLEN 1600 IndRupees1,07,200.00
WARD 1250 IndRupees83,750.00
JONES 2975 IndRupees1,99,325.00
MARTIN 1250 IndRupees83,750.00
BLAKE 2850 IndRupees1,90,950.00
CLARK 2450 IndRupees1,64,150.00
SCOTT 3000 IndRupees2,01,000.00
KING 5000 IndRupees3,35,000.00
TURNER 1500 IndRupees1,00,500.00
ADAMS 1100 IndRupees73,700.00
JAMES 950 IndRupees63,650.00
FORD 3000 IndRupees2,01,000.00
MILLER 1300 IndRupees87,100.00

14 rows selected.

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(-78567,L99G999D99') From Dual


2 /

TO_CHAR(-78567,L99G

-$78,567.00

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(-78567,L99G999D99MI) From Dual


2 /

TO_CHAR(-78567,L99G

$78,567.00-

SQL> clear screen


SQL> /

TO_CHAR(-78567,L99G

$78,567.00-

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(-78567,L99G999D99PR) From Dual


SQL> /

TO_CHAR(-78567,L99G9

<$78,567.00>

SQL> clear screen


SQL> /

TO_CHAR(-78567,L99G9

<$78,567.00>

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(78567,L99G999D99PR) From Dual


SQL> /

TO_CHAR(78567,L99G99

$78,567.00
SQL> clear screen
SQL> /

TO_CHAR(78567,L99G99

$78,567.00

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(78567,L99G999D99PR)||inetsolv From Dual


SQL> /

TO_CHAR(78567,L99G999D99PR)

$78,567.00 inetsolv

SQL> clear screen


SQL> /

TO_CHAR(78567,L99G999D99PR)

$78,567.00 inetsolv

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(-78567,L99G999D99')||inetsolv From Dual


SQL> /

TO_CHAR(-78567,L99G999D99')
-
-$78,567.00inetsolv

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(-78567,L99G999D99PR)||inetsolv From Dual


SQL> /

TO_CHAR(-78567,L99G999D99PR

<$78,567.00>inetsolv

SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(-78567,L99G999D99MI)||inetsolv From Dual


SQL> /

TO_CHAR(-78567,L99G999D99MI
-
$78,567.00-inetsolv

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select TO_CHAR(12,RN),TO_CHAR(12,rn) From Dual


SQL> /

TO_CHAR(12,RN TO_CHAR(12,RN

XII xii

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 select TO_CHAR(1000,S9999'),TO_CHAR(-1000,S9999')
2* From Dual
3 /

TO_CH TO_CH

+1000 -1000

SQL> ed
Wrote file afiedt.buf

1 select TO_CHAR(1000,S9999'),TO_CHAR(-1000,9999S)
2* From Dual
SQL> /

TO_CH TO_CH

+1000 1000-

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select 2000,TO_CHAR(2000,XXXX) From Dual


SQL> /

2000 TO_CH
-
2000 7D0

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select to_char(23456,$99,999.99') from dual


SQL> /

TO_CHAR(234

$23,456.00

SQL> ed
Wrote file afiedt.buf

1 select ename,to_char(sal,0000')
2* from emp
SQL> /

ENAME TO_CH

SMITH 0800
ALLEN 1600
WARD 1250
JONES 2975
MARTIN 1250
BLAKE 2850
CLARK 2450
SCOTT 3000
KING 5000
TURNER 1500
ADAMS 1100
JAMES 0950
FORD 3000
MILLER 1300

14 rows selected.

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 select TO_CHAR(20.55-20,99999'),
2* TO_CHAR(20.25-20,99999') From Dual
SQL> \/
SP2-0042: unknown command \/ rest of line ignored.
SQL> /

TO_CHA TO_CHA

1 0

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,DD) from dual


SQL> /

TO

28

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,DDDD) from dual


SQL> /

TO_C
-
2096

SQL> clear screen


SQL> /

TO_C
-
2096
SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,D) from dual


SQL> /

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,Dsp) from dual


SQL> /

TO_CH

Six

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,Day) from dual


SQL> /

TO_CHAR(S

Friday

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,DAY) from dual


SQL> /

TO_CHAR(S

FRIDAY

SQL> clear screen


SQL> /

TO_CHAR(S

FRIDAY

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,daY) from dual


SQL> /

TO_CHAR(S

friday

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,daY) from dual


SQL> /

TO_CHAR(S

friday

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,Day/Month/Year) from dual


2 /

TO_CHAR(SYSDATE,DAY/MONTH/YEAR)

Friday /July /Twenty Seventeen

SQL> clear screen


SQL> /

TO_CHAR(SYSDATE,DAY/MONTH/YEAR)

Friday /July /Twenty Seventeen

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,FMDay/Month/Year) from dual


SQL> /

TO_CHAR(SYSDATE,FMDAY/MONTH/YEAR)

Friday/July/Twenty Seventeen

SQL> clear screen


SQL> /

TO_CHAR(SYSDATE,FMDAY/MONTH/YEAR)

Friday/July/Twenty Seventeen

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,Day/Month/YYYY HH:MI:SS AM) from dual


SQL> /

TO_CHAR(SYSDATE,DAY/MONTH/YYYYHH:MI

Friday /July /2017 12:04:56 PM

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,BC) from dual


SQL> /
TO

AD

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,am) from dual


SQL> /

TO

pm

SQL> ed
Wrote file afiedt.buf

1 select ename,to_char(hiredate,PM)
2* from emp
3 /

ENAME TO

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

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,to_char(hiredate,HH:MI:SS PM)


2* from emp
SQL> /

ENAME TO_CHAR(HIR

SMITH 12:00:00 AM
ALLEN 12:00:00 AM
WARD 12:00:00 AM
JONES 12:00:00 AM
MARTIN 12:00:00 AM
BLAKE 12:00:00 AM
CLARK 12:00:00 AM
SCOTT 12:00:00 AM
KING 12:00:00 AM
TURNER 12:00:00 AM
ADAMS 12:00:00 AM
JAMES 12:00:00 AM
FORD 12:00:00 AM
MILLER 12:00:00 AM

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,to_char(hiredate,CC)
2* from emp
SQL> /

ENAME TO

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

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,D)
2* from emp
SQL> /

ENAME HIREDATE T

SMITH 17-DEC-80 4
ALLEN 20-FEB-81 6
WARD 22-FEB-81 1
JONES 02-APR-81 5
MARTIN 28-SEP-81 2
BLAKE 01-MAY-81 6
CLARK 09-JUN-81 3
SCOTT 09-DEC-82 5
KING 17-NOV-81 3
TURNER 08-SEP-81 3
ADAMS 12-JAN-83 4
JAMES 03-DEC-81 5
FORD 03-DEC-81 5
MILLER 23-JAN-82 7

14 rows selected.
SQL> clear screen
SQL> /

ENAME HIREDATE T

SMITH 17-DEC-80 4
ALLEN 20-FEB-81 6
WARD 22-FEB-81 1
JONES 02-APR-81 5
MARTIN 28-SEP-81 2
BLAKE 01-MAY-81 6
CLARK 09-JUN-81 3
SCOTT 09-DEC-82 5
KING 17-NOV-81 3
TURNER 08-SEP-81 3
ADAMS 12-JAN-83 4
JAMES 03-DEC-81 5
FORD 03-DEC-81 5
MILLER 23-JAN-82 7

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,day)
2* from emp
SQL> /

ENAME HIREDATE TO_CHAR(H



SMITH 17-DEC-80 wednesday
ALLEN 20-FEB-81 friday
WARD 22-FEB-81 sunday
JONES 02-APR-81 thursday
MARTIN 28-SEP-81 monday
BLAKE 01-MAY-81 friday
CLARK 09-JUN-81 tuesday
SCOTT 09-DEC-82 thursday
KING 17-NOV-81 tuesday
TURNER 08-SEP-81 tuesday
ADAMS 12-JAN-83 wednesday
JAMES 03-DEC-81 thursday
FORD 03-DEC-81 thursday
MILLER 23-JAN-82 saturday

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DY)
2* from emp
SQL> /

ENAME HIREDATE TO_



SMITH 17-DEC-80 WED
ALLEN 20-FEB-81 FRI
WARD 22-FEB-81 SUN
JONES 02-APR-81 THU
MARTIN 28-SEP-81 MON
BLAKE 01-MAY-81 FRI
CLARK 09-JUN-81 TUE
SCOTT 09-DEC-82 THU
KING 17-NOV-81 TUE
TURNER 08-SEP-81 TUE
ADAMS 12-JAN-83 WED
JAMES 03-DEC-81 THU
FORD 03-DEC-81 THU
MILLER 23-JAN-82 SAT

14 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE TO_



SMITH 17-DEC-80 WED
ALLEN 20-FEB-81 FRI
WARD 22-FEB-81 SUN
JONES 02-APR-81 THU
MARTIN 28-SEP-81 MON
BLAKE 01-MAY-81 FRI
CLARK 09-JUN-81 TUE
SCOTT 09-DEC-82 THU
KING 17-NOV-81 TUE
TURNER 08-SEP-81 TUE
ADAMS 12-JAN-83 WED
JAMES 03-DEC-81 THU
FORD 03-DEC-81 THU
MILLER 23-JAN-82 SAT

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DD)
2* from emp
SQL> /

ENAME HIREDATE TO

SMITH 17-DEC-80 17
ALLEN 20-FEB-81 20
WARD 22-FEB-81 22
JONES 02-APR-81 02
MARTIN 28-SEP-81 28
BLAKE 01-MAY-81 01
CLARK 09-JUN-81 09
SCOTT 09-DEC-82 09
KING 17-NOV-81 17
TURNER 08-SEP-81 08
ADAMS 12-JAN-83 12
JAMES 03-DEC-81 03
FORD 03-DEC-81 03
MILLER 23-JAN-82 23

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DDD)
2* from emp
SQL> /

ENAME HIREDATE TO_



SMITH 17-DEC-80 352
ALLEN 20-FEB-81 051
WARD 22-FEB-81 053
JONES 02-APR-81 092
MARTIN 28-SEP-81 271
BLAKE 01-MAY-81 121
CLARK 09-JUN-81 160
SCOTT 09-DEC-82 343
KING 17-NOV-81 321
TURNER 08-SEP-81 251
ADAMS 12-JAN-83 012
JAMES 03-DEC-81 337
FORD 03-DEC-81 337
MILLER 23-JAN-82 023

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,IW)
2* from emp
SQL> /

ENAME HIREDATE TO

SMITH 17-DEC-80 51
ALLEN 20-FEB-81 08
WARD 22-FEB-81 08
JONES 02-APR-81 14
MARTIN 28-SEP-81 40
BLAKE 01-MAY-81 18
CLARK 09-JUN-81 24
SCOTT 09-DEC-82 49
KING 17-NOV-81 47
TURNER 08-SEP-81 37
ADAMS 12-JAN-83 02
JAMES 03-DEC-81 49
FORD 03-DEC-81 49
MILLER 23-JAN-82 03

14 rows selected.

SQL> clear screen


SQL> /
ENAME HIREDATE TO

SMITH 17-DEC-80 51
ALLEN 20-FEB-81 08
WARD 22-FEB-81 08
JONES 02-APR-81 14
MARTIN 28-SEP-81 40
BLAKE 01-MAY-81 18
CLARK 09-JUN-81 24
SCOTT 09-DEC-82 49
KING 17-NOV-81 47
TURNER 08-SEP-81 37
ADAMS 12-JAN-83 02
JAMES 03-DEC-81 49
FORD 03-DEC-81 49
MILLER 23-JAN-82 03

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,IYYY)
2* from emp
SQL> /

ENAME HIREDATE TO_C


-
SMITH 17-DEC-80 1980
ALLEN 20-FEB-81 1981
WARD 22-FEB-81 1981
JONES 02-APR-81 1981
MARTIN 28-SEP-81 1981
BLAKE 01-MAY-81 1981
CLARK 09-JUN-81 1981
SCOTT 09-DEC-82 1982
KING 17-NOV-81 1981
TURNER 08-SEP-81 1981
ADAMS 12-JAN-83 1983
JAMES 03-DEC-81 1981
FORD 03-DEC-81 1981
MILLER 23-JAN-82 1982

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,IYY)
2* from emp
SQL> /

ENAME HIREDATE TO_



SMITH 17-DEC-80 980
ALLEN 20-FEB-81 981
WARD 22-FEB-81 981
JONES 02-APR-81 981
MARTIN 28-SEP-81 981
BLAKE 01-MAY-81 981
CLARK 09-JUN-81 981
SCOTT 09-DEC-82 982
KING 17-NOV-81 981
TURNER 08-SEP-81 981
ADAMS 12-JAN-83 983
JAMES 03-DEC-81 981
FORD 03-DEC-81 981
MILLER 23-JAN-82 982

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,Year)
2* from emp
SQL> /

ENAME HIREDATE TO_CHAR(HIREDATE,YEAR)



SMITH 17-DEC-80 Nineteen Eighty
ALLEN 20-FEB-81 Nineteen Eighty-One
WARD 22-FEB-81 Nineteen Eighty-One
JONES 02-APR-81 Nineteen Eighty-One
MARTIN 28-SEP-81 Nineteen Eighty-One
BLAKE 01-MAY-81 Nineteen Eighty-One
CLARK 09-JUN-81 Nineteen Eighty-One
SCOTT 09-DEC-82 Nineteen Eighty-Two
KING 17-NOV-81 Nineteen Eighty-One
TURNER 08-SEP-81 Nineteen Eighty-One
ADAMS 12-JAN-83 Nineteen Eighty-Three
JAMES 03-DEC-81 Nineteen Eighty-One
FORD 03-DEC-81 Nineteen Eighty-One
MILLER 23-JAN-82 Nineteen Eighty-Two

14 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE TO_CHAR(HIREDATE,YEAR)



SMITH 17-DEC-80 Nineteen Eighty
ALLEN 20-FEB-81 Nineteen Eighty-One
WARD 22-FEB-81 Nineteen Eighty-One
JONES 02-APR-81 Nineteen Eighty-One
MARTIN 28-SEP-81 Nineteen Eighty-One
BLAKE 01-MAY-81 Nineteen Eighty-One
CLARK 09-JUN-81 Nineteen Eighty-One
SCOTT 09-DEC-82 Nineteen Eighty-Two
KING 17-NOV-81 Nineteen Eighty-One
TURNER 08-SEP-81 Nineteen Eighty-One
ADAMS 12-JAN-83 Nineteen Eighty-Three
JAMES 03-DEC-81 Nineteen Eighty-One
FORD 03-DEC-81 Nineteen Eighty-One
MILLER 23-JAN-82 Nineteen Eighty-Two
14 rows selected.

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,W) from dual


SQL> /

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,Q) from dual


SQL> /

SQL> ed
Wrote file afiedt.buf

1 Select Empno,Ename,Hiredate,TO_CHAR(Hiredate,Q)
2* from emp
SQL> /

EMPNO ENAME HIREDATE T


-
7369 SMITH 17-DEC-80 4
7499 ALLEN 20-FEB-81 1
7521 WARD 22-FEB-81 1
7566 JONES 02-APR-81 2
7654 MARTIN 28-SEP-81 3
7698 BLAKE 01-MAY-81 2
7782 CLARK 09-JUN-81 2
7788 SCOTT 09-DEC-82 4
7839 KING 17-NOV-81 4
7844 TURNER 08-SEP-81 3
7876 ADAMS 12-JAN-83 1
7900 JAMES 03-DEC-81 4
7902 FORD 03-DEC-81 4
7934 MILLER 23-JAN-82 1

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 Select Empno,Ename,Hiredate,TO_CHAR(Hiredate,Q)
2 from emp
3* where TO_CHAR(Hiredate,Q)=4
4 /

EMPNO ENAME HIREDATE T


-
7369 SMITH 17-DEC-80 4
7788 SCOTT 09-DEC-82 4
7839 KING 17-NOV-81 4
7900 JAMES 03-DEC-81 4
7902 FORD 03-DEC-81 4

SQL> clear screen


SQL> /

EMPNO ENAME HIREDATE T


-
7369 SMITH 17-DEC-80 4
7788 SCOTT 09-DEC-82 4
7839 KING 17-NOV-81 4
7900 JAMES 03-DEC-81 4
7902 FORD 03-DEC-81 4

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where to_char(hiredate,DAY)=SUNDAY
4 /

no rows selected

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where to_char(hiredate,D)=1
SQL> /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where rtrim(to_char(hiredate,DAY))=SUNDAY
4 /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> clear screen


SQL> /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> ed
Wrote file afiedt.buf
1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where trim(to_char(hiredate,DAY))=SUNDAY
SQL> /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where replace(to_char(hiredate,DAY), )=SUNDAY
SQL> /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where to_char(hiredate,DAY)=rpad(SUNDAY,9)
4 /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> clear screen


SQL> /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,to_char(hiredate,DAY)
2 from emp
3* where to_char(hiredate,FMDAY)=SUNDAY
SQL> /

ENAME HIREDATE TO_CHAR(H



WARD 22-FEB-81 SUNDAY

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,j) from daul


SQL> /
select to_char(sysdate,j) from daul
*
ERROR at line 1:
ORA-12152: TNS:unable to send break message
ERROR:
ORA-03114: not connected to ORACLE
SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,j) from daul


SQL> conn scott/tiger@orcl
ERROR:
ORA-28002: the password will expire within 163 days
Connected.
SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,j) from dual


SQL> /

TO_CHAR
-
2457963

SQL> ed
Wrote file afiedt.buf

1* select to_char(sysdate,j) from dual


2

Leave a Comment on okr_11am_jul28


okr_11am_jul27

ed
Wrote file afiedt.buf

1* Select SQRT(25) From Dual


SQL> /

SQRT(25)
-
5

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select trunc(15/10) from dual


SQL> /

TRUNC(15/10)

SQL> ed
Wrote file afiedt.buf

1* select trunc(15/2) from dual


SQL> /
TRUNC(15/2)

SQL> ed
Wrote file afiedt.buf

1* select trunc(15/2) from dual


2
SQL>
SQL> clear screen
SQL> ed
Wrote file afiedt.buf

1* Select ABS(-100) From Dual


SQL> /

ABS(-100)
-
100

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* Select ABS(-100) From Dual


2
SQL> ed
Wrote file afiedt.buf

1 Select Sal, Comm, Sal-Comm, ABS(Sal-Comm)


2* FROM Emp
3 /

SAL COMM SAL-COMM ABS(SAL-COMM)


- - - -
800
1600 300 1300 1300
1250 500 750 750
2975
1250 1400 -150 150
2850
2450
3000
5000
1500 0 1500 1500
1100
950
3000
1300

14 rows selected.

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* Select SIGN(-10), SIGN(10), SIGN(0) From Dual


SQL> /

SIGN(-10) SIGN(10) SIGN(0)


- - -
-1 1 0

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 Select Sal, Comm, SIGN(Sal-Comm), ABS(Sal-Comm)


2 FROM Emp
3* Where SIGN(Sal-Comm)=-1
SQL> /

SAL COMM SIGN(SAL-COMM) ABS(SAL-COMM)


- - -
1250 1400 -1 150

SQL> clear screen


SQL> select sysdate from dua;
select sysdate from dua
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL> ed
Wrote file afiedt.buf

1* select sysdate from dual


SQL> /

SYSDATE

27-JUL-17

SQL> clear screen


SQL> /

SYSDATE

27-JUL-17

SQL> ed
Wrote file afiedt.buf

1* select sysdate from dual


2 /

SYSDATE

27-JUL-17

SQL> clear screen


SQL> /

SYSDATE

27-JUL-17
SQL> clear screen
SQL> ed
Wrote file afiedt.buf

1* select 20-dec-2017'-31-dec-2010' from dual


SQL> /
select 20-dec-2017'-31-dec-2010' from dual
*
ERROR at line 1:
ORA-01722: invalid number
SQL> ed
Wrote file afiedt.buf

1* select to_date(20-dec-2017')-to_date(31-dec-2010') from dual


2 /

TO_DATE(20-DEC-2017')-TO_DATE(31-DEC-2010')

2546

SQL> ed
Wrote file afiedt.buf

1* select sysdate-hiredate from emp


SQL> /

SYSDATE-HIREDATE
-
13371.49
13306.49
13304.49
13265.49
13086.49
13236.49
13197.49
12649.49
13036.49
13106.49
12615.49
13020.49
13020.49
12969.49

14 rows selected.

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,sysdate-hiredate
2* from emp
3 /

ENAME HIREDATE SYSDATE-HIREDATE


-
SMITH 17-DEC-80 13371.4904
ALLEN 20-FEB-81 13306.4904
WARD 22-FEB-81 13304.4904
JONES 02-APR-81 13265.4904
MARTIN 28-SEP-81 13086.4904
BLAKE 01-MAY-81 13236.4904
CLARK 09-JUN-81 13197.4904
SCOTT 09-DEC-82 12649.4904
KING 17-NOV-81 13036.4904
TURNER 08-SEP-81 13106.4904
ADAMS 12-JAN-83 12615.4904
JAMES 03-DEC-81 13020.4904
FORD 03-DEC-81 13020.4904
MILLER 23-JAN-82 12969.4904

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,sysdate-hiredate Exp in Days


2* from emp
SQL> /

ENAME HIREDATE Exp in Days



SMITH 17-DEC-80 13371.4909
ALLEN 20-FEB-81 13306.4909
WARD 22-FEB-81 13304.4909
JONES 02-APR-81 13265.4909
MARTIN 28-SEP-81 13086.4909
BLAKE 01-MAY-81 13236.4909
CLARK 09-JUN-81 13197.4909
SCOTT 09-DEC-82 12649.4909
KING 17-NOV-81 13036.4909
TURNER 08-SEP-81 13106.4909
ADAMS 12-JAN-83 12615.4909
JAMES 03-DEC-81 13020.4909
FORD 03-DEC-81 13020.4909
MILLER 23-JAN-82 12969.4909

14 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE Exp in Days



SMITH 17-DEC-80 13371.4909
ALLEN 20-FEB-81 13306.4909
WARD 22-FEB-81 13304.4909
JONES 02-APR-81 13265.4909
MARTIN 28-SEP-81 13086.4909
BLAKE 01-MAY-81 13236.4909
CLARK 09-JUN-81 13197.4909
SCOTT 09-DEC-82 12649.4909
KING 17-NOV-81 13036.4909
TURNER 08-SEP-81 13106.4909
ADAMS 12-JAN-83 12615.4909
JAMES 03-DEC-81 13020.4909
FORD 03-DEC-81 13020.4909
MILLER 23-JAN-82 12969.4909
14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,(sysdate-hiredate)/365 Exp in Days


2* from emp
SQL> /

ENAME HIREDATE Exp in Days



SMITH 17-DEC-80 36.6342226
ALLEN 20-FEB-81 36.4561404
WARD 22-FEB-81 36.450661
JONES 02-APR-81 36.3438116
MARTIN 28-SEP-81 35.8534007
BLAKE 01-MAY-81 36.2643596
CLARK 09-JUN-81 36.1575103
SCOTT 09-DEC-82 34.6561404
KING 17-NOV-81 35.7164144
TURNER 08-SEP-81 35.9081952
ADAMS 12-JAN-83 34.5629897
JAMES 03-DEC-81 35.6725788
FORD 03-DEC-81 35.6725788
MILLER 23-JAN-82 35.5328527

14 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE Exp in Days



SMITH 17-DEC-80 36.6342226
ALLEN 20-FEB-81 36.4561404
WARD 22-FEB-81 36.450661
JONES 02-APR-81 36.3438117
MARTIN 28-SEP-81 35.8534007
BLAKE 01-MAY-81 36.2643596
CLARK 09-JUN-81 36.1575103
SCOTT 09-DEC-82 34.6561404
KING 17-NOV-81 35.7164144
TURNER 08-SEP-81 35.9081952
ADAMS 12-JAN-83 34.5629898
JAMES 03-DEC-81 35.6725788
FORD 03-DEC-81 35.6725788
MILLER 23-JAN-82 35.5328528

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,round((sysdate-hiredate)/365) Exp in Days


2* from emp
SQL> /

ENAME HIREDATE Exp in Days



SMITH 17-DEC-80 37
ALLEN 20-FEB-81 36
WARD 22-FEB-81 36
JONES 02-APR-81 36
MARTIN 28-SEP-81 36
BLAKE 01-MAY-81 36
CLARK 09-JUN-81 36
SCOTT 09-DEC-82 35
KING 17-NOV-81 36
TURNER 08-SEP-81 36
ADAMS 12-JAN-83 35
JAMES 03-DEC-81 36
FORD 03-DEC-81 36
MILLER 23-JAN-82 36

14 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE Exp in Days



SMITH 17-DEC-80 37
ALLEN 20-FEB-81 36
WARD 22-FEB-81 36
JONES 02-APR-81 36
MARTIN 28-SEP-81 36
BLAKE 01-MAY-81 36
CLARK 09-JUN-81 36
SCOTT 09-DEC-82 35
KING 17-NOV-81 36
TURNER 08-SEP-81 36
ADAMS 12-JAN-83 35
JAMES 03-DEC-81 36
FORD 03-DEC-81 36
MILLER 23-JAN-82 36

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,round((sysdate-hiredate)/365) Exp in Days


2* from emp
SQL>
SQL>
SQL> e
SP2-0042: unknown command e rest of line ignored.
SQL> ed
Wrote file afiedt.buf

1* select sysdate+10 from dual


SQL> /

SYSDATE+1

06-AUG-17

SQL> ed
Wrote file afiedt.buf

1* select sysdate-10 from dual


SQL> /

SYSDATE-1

17-JUL-17

SQL> ed
Wrote file afiedt.buf

1* select sysdate*10 from dual


SQL> /
select sysdate*10 from dual
*
ERROR at line 1:
ORA-00932: inconsistent datatypes: expected NUMBER got DATE
SQL> clear screen
SQL> ed
Wrote file afiedt.buf

1* select sysdate+48/24 from dual


2 /

SYSDATE+4

29-JUL-17

SQL> ed
Wrote file afiedt.buf

1* select add_month(sysdate,1) from dual


SQL> /
select add_month(sysdate,1) from dual
*
ERROR at line 1:
ORA-00904: ADD_MONTH: invalid identifier
SQL> ed
Wrote file afiedt.buf

1* select add_months(sysdate,1) from dual


SQL> /

ADD_MONTH

27-AUG-17

SQL> ed
Wrote file afiedt.buf

1* select add_months(sysdate,-1) from dual


SQL> /

ADD_MONTH

27-JUN-17

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 select months_between(12-jan-2015',12-feb-2010')
2* from dual
SQL> /

MONTHS_BETWEEN(12-JAN-2015',12-FEB-2010')
-
59

SQL> ed
Wrote file afiedt.buf

1 select months_between(12-jan-2010',12-feb-2015')
2* from dual
SQL> /

MONTHS_BETWEEN(12-JAN-2010',12-FEB-2015')
-
-61

SQL> ed
Wrote file afiedt.buf

1 select months_between(12-jan-2015',10-feb-2010')
2* from dual
SQL> /

MONTHS_BETWEEN(12-JAN-2015',10-FEB-2010')
-
59.0645161

SQL> clear screen


SQL> /

MONTHS_BETWEEN(12-JAN-2015',10-FEB-2010')
-
59.0645161

SQL> ed
Wrote file afiedt.buf

1 select months_between(12-jan-2015',10-feb-2010')
2* from dual
3
SQL>
SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,
2 months_between(sysdate,hiredate) Exp in Months
3* from emp
SQL> /

ENAME HIREDATE Exp in Months


-
SMITH 17-DEC-80 439.338631
ALLEN 20-FEB-81 437.241856
WARD 22-FEB-81 437.17734
JONES 02-APR-81 435.822501
MARTIN 28-SEP-81 429.983792
BLAKE 01-MAY-81 434.85476
CLARK 09-JUN-81 433.596695
SCOTT 09-DEC-82 415.596695
KING 17-NOV-81 428.338631
TURNER 08-SEP-81 430.628953
ADAMS 12-JAN-83 414.499921
JAMES 03-DEC-81 427.790243
FORD 03-DEC-81 427.790243
MILLER 23-JAN-82 426.145082

14 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE Exp in Months


-
SMITH 17-DEC-80 439.338631
ALLEN 20-FEB-81 437.241857
WARD 22-FEB-81 437.177341
JONES 02-APR-81 435.822502
MARTIN 28-SEP-81 429.983793
BLAKE 01-MAY-81 434.85476
CLARK 09-JUN-81 433.596696
SCOTT 09-DEC-82 415.596696
KING 17-NOV-81 428.338631
TURNER 08-SEP-81 430.628954
ADAMS 12-JAN-83 414.499922
JAMES 03-DEC-81 427.790244
FORD 03-DEC-81 427.790244
MILLER 23-JAN-82 426.145083

14 rows selected.

SQL> ed\

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,
2 round(months_between(sysdate,hiredate)/12) Exp in Months
3* from emp
4 /

ENAME HIREDATE Exp in Months


-
SMITH 17-DEC-80 37
ALLEN 20-FEB-81 36
WARD 22-FEB-81 36
JONES 02-APR-81 36
MARTIN 28-SEP-81 36
BLAKE 01-MAY-81 36
CLARK 09-JUN-81 36
SCOTT 09-DEC-82 35
KING 17-NOV-81 36
TURNER 08-SEP-81 36
ADAMS 12-JAN-83 35
JAMES 03-DEC-81 36
FORD 03-DEC-81 36
MILLER 23-JAN-82 36

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,
2 months_between(sysdate,hiredate)/12) Exp in Months
3 from emp
4* where months_between(sysdate,hiredate)>430
SQL> /
months_between(sysdate,hiredate)/12) Exp in Months
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
SQL> ed
Wrote file afiedt.buf

1 select ename,hiredate,
2 months_between(sysdate,hiredate) Exp in Months
3 from emp
4* where months_between(sysdate,hiredate)>430
SQL> \/
SP2-0042: unknown command \/ rest of line ignored.
SQL> /

ENAME HIREDATE Exp in Months


-
SMITH 17-DEC-80 439.338667
ALLEN 20-FEB-81 437.241893
WARD 22-FEB-81 437.177377
JONES 02-APR-81 435.822538
BLAKE 01-MAY-81 434.854797
CLARK 09-JUN-81 433.596732
TURNER 08-SEP-81 430.62899

7 rows selected.

SQL> clear screen


SQL> /

ENAME HIREDATE Exp in Months


-
SMITH 17-DEC-80 439.338668
ALLEN 20-FEB-81 437.241894
WARD 22-FEB-81 437.177378
JONES 02-APR-81 435.822539
BLAKE 01-MAY-81 434.854797
CLARK 09-JUN-81 433.596732
TURNER 08-SEP-81 430.62899

7 rows selected.

SQL> ed
Wrote file afiedt.buf
1 Select Next_day(Sysdate,SUN)
2* From Dual
SQL> /

NEXT_DAY(

30-JUL-17

SQL> clear screen


SQL> /

NEXT_DAY(

30-JUL-17

SQL> ed
Wrote file afiedt.buf

1 Select ename,hiredate,Next_day(hiredate,SUN)
2* From emp
3 /

ENAME HIREDATE NEXT_DAY(



SMITH 17-DEC-80 21-DEC-80
ALLEN 20-FEB-81 22-FEB-81
WARD 22-FEB-81 01-MAR-81
JONES 02-APR-81 05-APR-81
MARTIN 28-SEP-81 04-OCT-81
BLAKE 01-MAY-81 03-MAY-81
CLARK 09-JUN-81 14-JUN-81
SCOTT 09-DEC-82 12-DEC-82
KING 17-NOV-81 22-NOV-81
TURNER 08-SEP-81 13-SEP-81
ADAMS 12-JAN-83 16-JAN-83
JAMES 03-DEC-81 06-DEC-81
FORD 03-DEC-81 06-DEC-81
MILLER 23-JAN-82 24-JAN-82

14 rows selected.

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1 Select ename,hiredate,Next_day(hiredate,SUN)
2* From emp
SQL>
SQL> ed
Wrote file afiedt.buf

1 Select ename,hiredate,Next_day(hiredate,SAT)
2* From emp
SQL> /

ENAME HIREDATE NEXT_DAY(



SMITH 17-DEC-80 20-DEC-80
ALLEN 20-FEB-81 21-FEB-81
WARD 22-FEB-81 28-FEB-81
JONES 02-APR-81 04-APR-81
MARTIN 28-SEP-81 03-OCT-81
BLAKE 01-MAY-81 02-MAY-81
CLARK 09-JUN-81 13-JUN-81
SCOTT 09-DEC-82 11-DEC-82
KING 17-NOV-81 21-NOV-81
TURNER 08-SEP-81 12-SEP-81
ADAMS 12-JAN-83 15-JAN-83
JAMES 03-DEC-81 05-DEC-81
FORD 03-DEC-81 05-DEC-81
MILLER 23-JAN-82 30-JAN-82

14 rows selected.

SQL> ed
Wrote file afiedt.buf

1 Select Next_day(07-mar-1995',SAT)
2* From dual
SQL> /

NEXT_DAY(

11-MAR-95

SQL> ed
Wrote file afiedt.buf

1 Select Next_day(07-mar-1995',THU)
2* From dual
SQL> /

NEXT_DAY(

09-MAR-95

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select last_day(sysdate)-sysdate Days left from dual


SQL> /

Days left
-
4

SQL> ed
Wrote file afiedt.buf

1* select last_day(12-feb-2017') from dual


2 /

LAST_DAY(

28-FEB-17
SQL> ed
Wrote file afiedt.buf

1* select last_day(sysdate) from dual


2 /

LAST_DAY(

31-JUL-17

SQL> clear screen


SQL> /

LAST_DAY(

31-JUL-17

SQL> ed
Wrote file afiedt.buf

1* select add_months(last_day(sysdate),-1) from dual


2 /

ADD_MONTH

30-JUN-17

SQL> ed
Wrote file afiedt.buf

1* select add_months(last_day(sysdate),-1)+1 from dual


SQL> /

ADD_MONTH

01-JUL-17

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select add_months(last_day(sysdate),-1)+1 from dual


SQL>
SQL> ed
Wrote file afiedt.buf

1* select add_months(last_day(14-feb-17'),-1)+1 from dual


2 /

ADD_MONTH

01-FEB-17

SQL> clear screen


SQL> ed
Wrote file afiedt.buf

1* select round(sysdate,day) from dual


SQL> /
ROUND(SYS

30-JUL-17

SQL> /

ROUND(SYS

30-JUL-17

SQL> /

ROUND(SYS

23-JUL-17

SQL> ed
Wrote file afiedt.buf

1* select round(sysdate,month) from dual


SQL> /

ROUND(SYS

01-AUG-17

SQL> /

ROUND(SYS

01-JUL-17

SQL> ed
Wrote file afiedt.buf

1* select round(sysdate,year) from dual


SQL> /

ROUND(SYS

01-JAN-18

SQL> /

ROUND(SYS

01-JAN-17

SQL> ed
Wrote file afiedt.buf

1* select trunc(sysdate,day) from dual


SQL> /

TRUNC(SYS

24-DEC-17
SQL> ed
Wrote file afiedt.buf

1* select trunc(sysdate,month) from dual


SQL> /

TRUNC(SYS

01-DEC-17

SQL> ed
Wrote file afiedt.buf

1* select trunc(sysdate,year) from dual


SQL> /

TRUNC(SYS

01-JAN-17

SQL>

Leave a Com

You might also like