Вы находитесь на странице: 1из 57

SQL> CL SCR

SQL> SELECT * FROM EMP


2 WHERE ENAME='KING';

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7839 KING PRESIDENT 17-NOV-81 5000
10

SQL> select * from emp


2 where ename='king';

no rows selected

SQL> ed
Wrote file afiedt.buf

1 select * from emp


2* where ename=upper('king')
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7839 KING PRESIDENT 17-NOV-81 5000
10

SQL> ed
Wrote file afiedt.buf

1 select * from emp


2* where lower(ename)='king'
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7839 KING PRESIDENT 17-NOV-81 5000
10

SQL> ed
Wrote file afiedt.buf

1 select * from emp


2* where initcap(ename)=initcap('king')
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7839 KING PRESIDENT 17-NOV-81 5000
10
SQL> cl scr
SQL> SELECT UPPER('anas ahmed'), lower(user), INITCAP('RAUF AHMED'),user,USER FROM
DUAL;

UPPER('ANA LOWER(USER) INITCAP('R USER

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


------------------------------
USER

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

ANAS AHMED scott Rauf Ahmed SCOTT

SCOTT

SQL> ED
Wrote file afiedt.buf

1* SELECT UPPER('anas ahmed') C1, lower(user)C2, INITCAP('RAUF


AHMED')C3,user,USER FROM DUAL
SQL> /

C1 C2 C3 USER

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


------------------------------
USER

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

ANAS AHMED scott Rauf Ahmed SCOTT

SCOTT

SQL> COL USER FORMAT A5


SQL> CL SCR
SQL> L
1* SELECT UPPER('anas ahmed') C1, lower(user)C2, INITCAP('RAUF
AHMED')C3,user,USER FROM DUAL
SQL> /

C1 C2 C3 USER USER

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

ANAS AHMED scott Rauf Ahmed SCOTT SCOTT

SQL> CL SCR
SQL> SELECT ENAME||' WORK AS '||JOB INFO FROM EMP;
INFO

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

SMITH WORK AS CLERK

ALLEN WORK AS SALESMAN

WARD WORK AS SALESMAN

JONES WORK AS MANAGER

MARTIN WORK AS SALESMAN

BLAKE WORK AS MANAGER

CLARK WORK AS MANAGER

SCOTT WORK AS ANALYST

KING WORK AS PRESIDENT

TURNER WORK AS SALESMAN

ADAMS WORK AS CLERK

JAMES WORK AS CLERK

FORD WORK AS ANALYST

MILLER WORK AS CLERK

JOHNTHON WORK AS DBA

15 rows selected.

SQL> CL SCR
SQL> -- CONCAT(COL1/EXP1, COL2/EXP2)
SQL> SELECT ENAME||JOB INFO, CONCAT(ENAME,JOB) FROM EMP;

INFO CONCAT(ENAME,JOB)

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

SMITHCLERK SMITHCLERK

ALLENSALESMAN ALLENSALESMAN

WARDSALESMAN WARDSALESMAN

JONESMANAGER JONESMANAGER

MARTINSALESMAN MARTINSALESMAN

BLAKEMANAGER BLAKEMANAGER

CLARKMANAGER CLARKMANAGER
SCOTTANALYST SCOTTANALYST

KINGPRESIDENT KINGPRESIDENT

TURNERSALESMAN TURNERSALESMAN

ADAMSCLERK ADAMSCLERK

JAMESCLERK JAMESCLERK

FORDANALYST FORDANALYST

MILLERCLERK MILLERCLERK

JOHNTHONDBA JOHNTHONDBA

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME||','||JOB INFO, CONCAT(ENAME,',',JOB) FROM EMP


SQL> /
SELECT ENAME||','||JOB INFO, CONCAT(ENAME,',',JOB) FROM EMP
*
ERROR at line 1:
ORA-00909: invalid number of arguments

SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME||','||JOB INFO, CONCAT(ENAME,JOB) FROM EMP


SQL> /

INFO CONCAT(ENAME,JOB)

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

SMITH,CLERK SMITHCLERK

ALLEN,SALESMAN ALLENSALESMAN

WARD,SALESMAN WARDSALESMAN

JONES,MANAGER JONESMANAGER

MARTIN,SALESMAN MARTINSALESMAN

BLAKE,MANAGER BLAKEMANAGER

CLARK,MANAGER CLARKMANAGER

SCOTT,ANALYST SCOTTANALYST

KING,PRESIDENT KINGPRESIDENT
TURNER,SALESMAN TURNERSALESMAN

ADAMS,CLERK ADAMSCLERK

JAMES,CLERK JAMESCLERK

FORD,ANALYST FORDANALYST

MILLER,CLERK MILLERCLERK

JOHNTHON,DBA JOHNTHONDBA

15 rows selected.

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME||','||JOB INFO, CONCAT(ENAME,CONCAT(',',JOB)) FROM EMP


SQL> /

INFO CONCAT(ENAME,CONCAT(

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

SMITH,CLERK SMITH,CLERK

ALLEN,SALESMAN ALLEN,SALESMAN

WARD,SALESMAN WARD,SALESMAN

JONES,MANAGER JONES,MANAGER

MARTIN,SALESMAN MARTIN,SALESMAN

BLAKE,MANAGER BLAKE,MANAGER

CLARK,MANAGER CLARK,MANAGER

SCOTT,ANALYST SCOTT,ANALYST

KING,PRESIDENT KING,PRESIDENT

TURNER,SALESMAN TURNER,SALESMAN

ADAMS,CLERK ADAMS,CLERK

JAMES,CLERK JAMES,CLERK

FORD,ANALYST FORD,ANALYST

MILLER,CLERK MILLER,CLERK

JOHNTHON,DBA JOHNTHON,DBA
15 rows selected.

SQL> CL SCR
SQL> /*
DOC> USE THE CONCAT FUNCTION TO GENERATE FOLLOWING RESULT.
DOC> RESTRICTION :- DON'T USED || SIGN AT ANY PLACE OF STATEMENT
DOC>KING WORKS AS PRESIDENT IN DEPARTMENT 10 SINCE 17-NOV-81 AND EARN 5000 BUT
WANT THRICE 15000
DOC>
DOC>HINT :- SOLVED THIS STATEMENT FROM RIGHT SIDE
DOC>*/
SQL> CL SCR
SQL> SELECT * FROM EMP
2 WHERE ENAME LIKE '____';

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7839 KING PRESIDENT 17-NOV-81 5000
10
7902 FORD ANALYST 7566 03-DEC-81 3000
20

SQL> ED
Wrote file afiedt.buf

1 SELECT * FROM EMP


2* WHERE LENGTH(ENAME)=4
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7521 WARD SALESMAN 7698 22-FEB-81 1250 500
30
7839 KING PRESIDENT 17-NOV-81 5000
10
7902 FORD ANALYST 7566 03-DEC-81 3000
20

SQL> ED
Wrote file afiedt.buf

1 SELECT * FROM EMP


2* WHERE LENGTH(ENAME)>4
SQL> /

EMPNO ENAME JOB MGR HIREDATE SAL COMM


DEPTNO
---------- ---------- --------- ---------- --------- ---------- ----------
----------
7369 SMITH CLERK 7902 17-DEC-80 800
20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300
30
7566 JONES MANAGER 7839 02-APR-81 2975
20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400
30
7698 BLAKE MANAGER 7839 01-MAY-81 2850
30
7782 CLARK MANAGER 7839 09-JUN-81 2450
10
7788 SCOTT ANALYST 7566 19-APR-87 3000
20
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0
30
7876 ADAMS CLERK 7788 23-MAY-87 1100
20
7900 JAMES CLERK 7698 03-DEC-81 950
30
7934 MILLER CLERK 7782 23-JAN-82 1300
10
7935 JOHNTHON DBA 7839 01-JAN-99 4500
10

12 rows selected.

SQL> CL SCR
SQL> SELECT ENAME, LENGTH(ENAME), JOB, LENGTH(JOB), EMPNO, LENGTH(EMPNO),
2 HIREDATE, LENGTH(HIREDATE) FROM EMP;

ENAME LENGTH(ENAME) JOB LENGTH(JOB) EMPNO LENGTH(EMPNO) HIREDATE


LENGTH(HIREDATE)
---------- ------------- --------- ----------- ---------- ------------- ---------
----------------
SMITH 5 CLERK 5 7369 4 17-DEC-80
9
ALLEN 5 SALESMAN 8 7499 4 20-FEB-81
9
WARD 4 SALESMAN 8 7521 4 22-FEB-81
9
JONES 5 MANAGER 7 7566 4 02-APR-81
9
MARTIN 6 SALESMAN 8 7654 4 28-SEP-81
9
BLAKE 5 MANAGER 7 7698 4 01-MAY-81
9
CLARK 5 MANAGER 7 7782 4 09-JUN-81
9
SCOTT 5 ANALYST 7 7788 4 19-APR-87
9
KING 4 PRESIDENT 9 7839 4 17-NOV-81
9
TURNER 6 SALESMAN 8 7844 4 08-SEP-81
9
ADAMS 5 CLERK 5 7876 4 23-MAY-87
9
JAMES 5 CLERK 5 7900 4 03-DEC-81
9
FORD 4 ANALYST 7 7902 4 03-DEC-81
9
MILLER 6 CLERK 5 7934 4 23-JAN-82
9
JOHNTHON 8 DBA 3 7935 4 01-JAN-99
9

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, LENGTH(ENAME), JOB, LENGTH(JOB), EMPNO, LENGTH(EMPNO),


2* HIREDATE, LENGTH(HIREDATE) LEN FROM EMP
SQL> /

ENAME LENGTH(ENAME) JOB LENGTH(JOB) EMPNO LENGTH(EMPNO) HIREDATE


LEN
---------- ------------- --------- ----------- ---------- ------------- ---------
----------
SMITH 5 CLERK 5 7369 4 17-DEC-80
9
ALLEN 5 SALESMAN 8 7499 4 20-FEB-81
9
WARD 4 SALESMAN 8 7521 4 22-FEB-81
9
JONES 5 MANAGER 7 7566 4 02-APR-81
9
MARTIN 6 SALESMAN 8 7654 4 28-SEP-81
9
BLAKE 5 MANAGER 7 7698 4 01-MAY-81
9
CLARK 5 MANAGER 7 7782 4 09-JUN-81
9
SCOTT 5 ANALYST 7 7788 4 19-APR-87
9
KING 4 PRESIDENT 9 7839 4 17-NOV-81
9
TURNER 6 SALESMAN 8 7844 4 08-SEP-81
9
ADAMS 5 CLERK 5 7876 4 23-MAY-87
9
JAMES 5 CLERK 5 7900 4 03-DEC-81
9
FORD 4 ANALYST 7 7902 4 03-DEC-81
9
MILLER 6 CLERK 5 7934 4 23-JAN-82
9
JOHNTHON 8 DBA 3 7935 4 01-JAN-99
9

15 rows selected.

SQL> CL SCR
SQL> L
1 SELECT ENAME, LENGTH(ENAME), JOB, LENGTH(JOB), EMPNO, LENGTH(EMPNO),
2* HIREDATE, LENGTH(HIREDATE) LEN FROM EMP
SQL> /

ENAME LENGTH(ENAME) JOB LENGTH(JOB) EMPNO LENGTH(EMPNO) HIREDATE


LEN
---------- ------------- --------- ----------- ---------- ------------- ---------
----------
SMITH 5 CLERK 5 7369 4 17-DEC-80
9
ALLEN 5 SALESMAN 8 7499 4 20-FEB-81
9
WARD 4 SALESMAN 8 7521 4 22-FEB-81
9
JONES 5 MANAGER 7 7566 4 02-APR-81
9
MARTIN 6 SALESMAN 8 7654 4 28-SEP-81
9
BLAKE 5 MANAGER 7 7698 4 01-MAY-81
9
CLARK 5 MANAGER 7 7782 4 09-JUN-81
9
SCOTT 5 ANALYST 7 7788 4 19-APR-87
9
KING 4 PRESIDENT 9 7839 4 17-NOV-81
9
TURNER 6 SALESMAN 8 7844 4 08-SEP-81
9
ADAMS 5 CLERK 5 7876 4 23-MAY-87
9
JAMES 5 CLERK 5 7900 4 03-DEC-81
9
FORD 4 ANALYST 7 7902 4 03-DEC-81
9
MILLER 6 CLERK 5 7934 4 23-JAN-82
9
JOHNTHON 8 DBA 3 7935 4 01-JAN-99
9

15 rows selected.

SQL> DESC EMP


Name Null? Type
----------------------------------------------------- --------
------------------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

SQL> CL SCR
SQL> SELECT EMPNO, LENGTH(EMPNO), SAL, LENGTH(SAL) FROM EMP;

EMPNO LENGTH(EMPNO) SAL LENGTH(SAL)

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

7369 4 800 3
7499 4 1600 4

7521 4 1250 4

7566 4 2975 4

7654 4 1250 4

7698 4 2850 4

7782 4 2450 4

7788 4 3000 4

7839 4 5000 4

7844 4 1500 4

7876 4 1100 4

7900 4 950 3

7902 4 3000 4

7934 4 1300 4

7935 4 4500 4

15 rows selected.

SQL> CL SCR
SQL> SELECT LENGTH('KASHIF MASOOD HASHMI') FROM DUAL;

LENGTH('KASHIFMASOODHASHMI')

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

20

SQL> CL SCR
SQL> -- SUBSTR(COL/EXP, START_FROM, NO_OF_CHAR_PICK)
SQL> SELECT SUBSTR('PAKISTAN',3) FROM DUAL;

SUBSTR

------

KISTAN

SQL> ED
Wrote file afiedt.buf

1* SELECT SUBSTR('PAKISTAN',3,4) FROM DUAL


SQL> /
SUBS

----

KIST

SQL> CL SCR
SQL> SELECT ENAME, SUBSTR(ENAME,2,4) FROM EMP;

ENAME SUBS

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

SMITH MITH

ALLEN LLEN

WARD ARD

JONES ONES

MARTIN ARTI

BLAKE LAKE

CLARK LARK

SCOTT COTT

KING ING

TURNER URNE

ADAMS DAMS

JAMES AMES

FORD ORD

MILLER ILLE

JOHNTHON OHNT

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME, SUBSTR(ENAME,2,4),LENGTH(SUBSTR(ENAME,2,4)) FROM EMP


SQL> /

ENAME SUBS LENGTH(SUBSTR(ENAME,2,4))

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

SMITH MITH 4
ALLEN LLEN 4

WARD ARD 3

JONES ONES 4

MARTIN ARTI 4

BLAKE LAKE 4

CLARK LARK 4

SCOTT COTT 4

KING ING 3

TURNER URNE 4

ADAMS DAMS 4

JAMES AMES 4

FORD ORD 3

MILLER ILLE 4

JOHNTHON OHNT 4

15 rows selected.

SQL> CL SCR
SQL> SELECT 'PAKISTAN',SUBSTR('PAKISTAN',1,3) FROM DUAL;

'PAKISTA SUB

-------- ---

PAKISTAN PAK

SQL> ED
Wrote file afiedt.buf

1 SELECT 'PAKISTAN',SUBSTR('PAKISTAN',1,3),
2 SUBSTR('PAKISTAN',-3,3)
3* FROM DUAL
SQL> /

'PAKISTA SUB SUB

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

PAKISTAN PAK TAN

SQL> CL SCR
SQL> --- INSTR(COL/EXP,SEARCH_EXP,START_FROM, NO_OF_OCCURENCE)
SQL>
SQL> SELECT 'BIG BUBBLE BAR',
2 INSTR('BIG BUBBLE BAR','B',1)ST,
3 INSTR('BIG BUBBLE BAR,'B',4)ST2,
4 INSTR('BIG BUBBLE BAR','B',1,4) FOURTH FROM DUAL;
ERROR:
ORA-01756: quoted string not properly terminated

SQL> ED
Wrote file afiedt.buf

1 SELECT 'BIG BUBBLE BAR',


2 INSTR('BIG BUBBLE BAR','B',1)ST,
3 INSTR('BIG BUBBLE BAR','B',4)ST2,
4* INSTR('BIG BUBBLE BAR','B',1,4) FOURTH FROM DUAL
SQL> /

'BIGBUBBLEBAR' ST ST2 FOURTH

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

BIG BUBBLE BAR 1 5 8

SQL> ED
Wrote file afiedt.buf

1 SELECT LENGTH('BIG BUBBLE BAR'),


2 INSTR('BIG BUBBLE BAR','B',1)ST,
3 INSTR('BIG BUBBLE BAR','B',4)ST2,
4* INSTR('BIG BUBBLE BAR','B',1,4) FOURTH FROM DUAL
SQL> /

LENGTH('BIGBUBBLEBAR') ST ST2 FOURTH

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

14 1 5 8

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1 SELECT 'BIG BUBBLE BAR',


2 INSTR('BIG BUBBLE BAR','B',-1)ST,
3 INSTR('BIG BUBBLE BAR','B',-4)ST2,
4* INSTR('BIG BUBBLE BAR','B',-1,4) FOURTH FROM DUAL
SQL> /

'BIGBUBBLEBAR' ST ST2 FOURTH

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

BIG BUBBLE BAR 12 8 5


SQL> -- PICK THE CHAR FROM RIGHT TO LEFT, BUT COUNT FROM LEFT TO RIGHT
SQL> CL SCR
SQL> -- REPLACE(COL,EXP,SEARCH_WHAT,REPLACE_WITH)
SQL> SELECT ENAME, REPLACE(ENAME,'S','X') FROM EMP;

ENAME REPLACE(EN

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

SMITH XMITH

ALLEN ALLEN

WARD WARD

JONES JONEX

MARTIN MARTIN

BLAKE BLAKE

CLARK CLARK

SCOTT XCOTT

KING KING

TURNER TURNER

ADAMS ADAMX

JAMES JAMEX

FORD FORD

MILLER MILLER

JOHNTHON JOHNTHON

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME, REPLACE(ENAME,'A','X') FROM EMP


SQL> CL SCR
SQL> L
1* SELECT ENAME, REPLACE(ENAME,'A','X') FROM EMP
SQL> /

ENAME REPLACE(EN

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

SMITH SMITH
ALLEN XLLEN

WARD WXRD

JONES JONES

MARTIN MXRTIN

BLAKE BLXKE

CLARK CLXRK

SCOTT SCOTT

KING KING

TURNER TURNER

ADAMS XDXMS

JAMES JXMES

FORD FORD

MILLER MILLER

JOHNTHON JOHNTHON

15 rows selected.

SQL> CL SCR
SQL> /*
DOC> FIND THE FIRST OCCURENCE OF LETTER L IN ENAME,REPLACE WITH X
DOC> ALLEN -> AXLEN
DOC> SCOTT -> SCOTT
DOC>*/
SQL>
SQL> SELECT ENAME, INSTR(ENAME,'L',1) FROM EMP;

ENAME INSTR(ENAME,'L',1)

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

SMITH 0

ALLEN 2

WARD 0

JONES 0

MARTIN 0

BLAKE 2

CLARK 2
SCOTT 0

KING 0

TURNER 0

ADAMS 0

JAMES 0

FORD 0

MILLER 3

JOHNTHON 0

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME, SUBSTR(ENAME,1,INSTR(ENAME,'L',1)) FROM EMP


SQL> /

ENAME SUBSTR(ENA

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

SMITH

ALLEN AL

WARD

JONES

MARTIN

BLAKE BL

CLARK CL

SCOTT

KING

TURNER

ADAMS

JAMES

FORD

MILLER MIL

JOHNTHON
15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT ENAME, REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X') FROM EMP


SQL> /

ENAME REPLACE(SU

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

SMITH

ALLEN AX

WARD

JONES

MARTIN

BLAKE BX

CLARK CX

SCOTT

KING

TURNER

ADAMS

JAMES

FORD

MILLER MIX

JOHNTHON

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),


2 SUBSTR(ENAME,INSTR(ENAME,'L',1))
3* FROM EMP
4 /

ENAME REPLACE(SU SUBSTR(ENA

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


SMITH SMITH

ALLEN AX LLEN

WARD WARD

JONES JONES

MARTIN MARTIN

BLAKE BX LAKE

CLARK CX LARK

SCOTT SCOTT

KING KING

TURNER TURNER

ADAMS ADAMS

JAMES JAMES

FORD FORD

MILLER MIX LLER

JOHNTHON JOHNTHON

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),


2 SUBSTR(ENAME,INSTR(ENAME,'L',1)+1)
3* FROM EMP
SQL> /

ENAME REPLACE(SU SUBSTR(ENA

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

SMITH SMITH

ALLEN AX LEN

WARD WARD

JONES JONES

MARTIN MARTIN

BLAKE BX AKE
CLARK CX ARK

SCOTT SCOTT

KING KING

TURNER TURNER

ADAMS ADAMS

JAMES JAMES

FORD FORD

MILLER MIX LER

JOHNTHON JOHNTHON

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, COCNCAT(REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),


2 SUBSTR(ENAME,INSTR(ENAME,'L',1)+1)) ENAMS
3* FROM EMP
SQL> /
SELECT ENAME, COCNCAT(REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),
*
ERROR at line 1:
ORA-00904: "COCNCAT": invalid identifier

SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, COCNCAT(REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),


2 SUBSTR(ENAME,INSTR(ENAME,'L',1)+1))) ENAMS
3* FROM EMP
SQL> /
SUBSTR(ENAME,INSTR(ENAME,'L',1)+1))) ENAMS
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected

SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, CONCAT(REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),


2 SUBSTR(ENAME,INSTR(ENAME,'L',1)+1))) ENAMS
3* FROM EMP
SQL> /
SUBSTR(ENAME,INSTR(ENAME,'L',1)+1))) ENAMS
*
ERROR at line 2:
ORA-00923: FROM keyword not found where expected
SQL> SELECT ENAME, COCNCAT(REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),
2 SUBSTR(ENAME,INSTR(ENAME,'L',1)+1)) ENAMS
3 FROM EMP
4 .
SQL> ED
Wrote file afiedt.buf

1 SELECT ENAME, CONCAT(REPLACE(SUBSTR(ENAME,1,INSTR(ENAME,'L',1)),'L','X'),


2 SUBSTR(ENAME,INSTR(ENAME,'L',1)+1)) ENAMS
3* FROM EMP
SQL> /

ENAME ENAMS

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

SMITH SMITH

ALLEN AXLEN

WARD WARD

JONES JONES

MARTIN MARTIN

BLAKE BXAKE

CLARK CXARK

SCOTT SCOTT

KING KING

TURNER TURNER

ADAMS ADAMS

JAMES JAMES

FORD FORD

MILLER MIXLER

JOHNTHON JOHNTHON

15 rows selected.

SQL> CL SCR
SQL> SELECT SAL FROM EMP;

SAL

----------
800

1600

1250

2975

1250

2850

2450

3000

5000

1500

1100

950

3000

1300

4500

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SAL,ENAME FROM EMP


SQL> /

SAL ENAME

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

800 SMITH

1600 ALLEN

1250 WARD

2975 JONES

1250 MARTIN

2850 BLAKE

2450 CLARK

3000 SCOTT
5000 KING

1500 TURNER

1100 ADAMS

950 JAMES

3000 FORD

1300 MILLER

4500 JOHNTHON

15 rows selected.

SQL> DESC EMP


Name Null? Type
----------------------------------------------------- --------
------------------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

SQL> CL SCR
SQL> SELECT SAL, LPAD(SAL,10,'*') FROM EMP;

SAL LPAD(SAL,1

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

800 *******800

1600 ******1600

1250 ******1250

2975 ******2975

1250 ******1250

2850 ******2850

2450 ******2450

3000 ******3000

5000 ******5000

1500 ******1500
1100 ******1100

950 *******950

3000 ******3000

1300 ******1300

4500 ******4500

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1 SELECT SAL, LPAD(SAL,10,'*'),


2* ENAME, RPAD(ENAME,10,'-') FROM EMP
SQL> /

SAL LPAD(SAL,1 ENAME RPAD(ENAME

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

800 *******800 SMITH SMITH-----

1600 ******1600 ALLEN ALLEN-----

1250 ******1250 WARD WARD------

2975 ******2975 JONES JONES-----

1250 ******1250 MARTIN MARTIN----

2850 ******2850 BLAKE BLAKE-----

2450 ******2450 CLARK CLARK-----

3000 ******3000 SCOTT SCOTT-----

5000 ******5000 KING KING------

1500 ******1500 TURNER TURNER----

1100 ******1100 ADAMS ADAMS-----

950 *******950 JAMES JAMES-----

3000 ******3000 FORD FORD------

1300 ******1300 MILLER MILLER----

4500 ******4500 JOHNTHON JOHNTHON--

15 rows selected.

SQL> CL SCR
SQL> SELECT SAL, LPAD(SAL,10,'*') FROM EMP;

SAL LPAD(SAL,1

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

800 *******800

1600 ******1600

1250 ******1250

2975 ******2975

1250 ******1250

2850 ******2850

2450 ******2450

3000 ******3000

5000 ******5000

1500 ******1500

1100 ******1100

950 *******950

3000 ******3000

1300 ******1300

4500 ******4500

15 rows selected.

SQL> /*
DOC> 1.
DOC> *******800*******
DOC> ******1600******
DOC>
DOC>
DOC> 2. DISPLAY QTR SALARY WITH *, EACH * REPRESENT 1000
DOC>*/
SQL>
SQL> SELECT SAL, SAL*3 FROM EMP;

SAL SAL*3

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

800 2400

1600 4800
1250 3750

2975 8925

1250 3750

2850 8550

2450 7350

3000 9000

5000 15000

1500 4500

1100 3300

950 2850

3000 9000

1300 3900

4500 13500

15 rows selected.

SQL> CL SCR
SQL> SELECT,
2
SQL> CL SCR
SQL> SELECT 'AJMAIN', TRIM('A' FROM 'AJMAIN'),
2 'AUSTRALIA',TRIM('A' FROM 'AUSTRALIA'),
3 'INDIA', TRIM('A' FROM 'INDIA'),
4 'PAKISTAN',TRIM('A' FROM 'PAKISTAN') FROM DUAL;

'AJMAI TRIM( 'AUSTRALI TRIM('A 'INDI TRIM 'PAKISTA TRIM('A'

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

AJMAIN JMAIN AUSTRALIA USTRALI INDIA INDI PAKISTAN PAKISTAN

SQL> cl scr
SQL> ----------------------------------- NUMBER FUNCTION
-----------------------------------
SQL> -- ROUND(), TRUNC(), MOD()
SQL> SELECT ROUND(2544
2
SQL> SELECT ROUND(25.44,1), ROUND(25.45,1) FROM DUAL;

ROUND(25.44,1) ROUND(25.45,1)

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

25.4 25.5
SQL> SELECT ROUND(25.45,-1), ROUND(24.45,-1) FROM DUAL;

ROUND(25.45,-1) ROUND(24.45,-1)

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

30 20

SQL> ED
Wrote file afiedt.buf

1* SELECT ROUND(155.45,-2), ROUND(154.45,-2) FROM DUAL


SQL> /

ROUND(155.45,-2) ROUND(154.45,-2)

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

200 200

SQL> ED
Wrote file afiedt.buf

1* SELECT ROUND(155.45,-2), ROUND(144.45,-2) FROM DUAL


SQL> /

ROUND(155.45,-2) ROUND(144.45,-2)

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

200 100

SQL> CL SCR
SQL> SELECT TRUNC(25.45,1), TRUNC(25.44,1) FROM DUAL;

TRUNC(25.45,1) TRUNC(25.44,1)

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

25.4 25.4

SQL> ED
Wrote file afiedt.buf

1* SELECT TRUNC(25.45,-1), TRUNC(24.44,-1) FROM DUAL


SQL> /

TRUNC(25.45,-1) TRUNC(24.44,-1)

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

20 20
SQL> ED
Wrote file afiedt.buf

1* SELECT TRUNC(25.45,-2), TRUNC(24.44,-2) FROM DUAL


SQL> /

TRUNC(25.45,-2) TRUNC(24.44,-2)

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

0 0

SQL> ED
Wrote file afiedt.buf

1* SELECT TRUNC(-1*25.45,-1), TRUNC(24.44,-2) FROM DUAL


SQL> /

TRUNC(-1*25.45,-1) TRUNC(24.44,-2)

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

-20 0

SQL> ED
Wrote file afiedt.buf

1* SELECT TRUNC(-1*25.45,1), TRUNC(24.44,-2) FROM DUAL


SQL> /

TRUNC(-1*25.45,1) TRUNC(24.44,-2)

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

-25.4 0

SQL> CL SCR
SQL> SELECT MOD(2009,4), MOD(2008,4) FROM DUAL;

MOD(2009,4) MOD(2008,4)

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

1 0

SQL> SELECT SAL, SAL*3, MOD(SAL*3,1000) FROM EMP;

SAL SAL*3 MOD(SAL*3,1000)

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

800 2400 400


1600 4800 800

1250 3750 750

2975 8925 925

1250 3750 750

2850 8550 550

2450 7350 350

3000 9000 0

5000 15000 0

1500 4500 500

1100 3300 300

950 2850 850

3000 9000 0

1300 3900 900

4500 13500 500

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SAL, SAL*3, MOD(SAL*3,100) FROM EMP


SQL> /

SAL SAL*3 MOD(SAL*3,100)

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

800 2400 0

1600 4800 0

1250 3750 50

2975 8925 25

1250 3750 50

2850 8550 50

2450 7350 50

3000 9000 0
5000 15000 0

1500 4500 0

1100 3300 0

950 2850 50

3000 9000 0

1300 3900 0

4500 13500 0

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SAL, SAL*3, MOD(SAL*3,1000) FROM EMP


SQL> /

SAL SAL*3 MOD(SAL*3,1000)

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

800 2400 400

1600 4800 800

1250 3750 750

2975 8925 925

1250 3750 750

2850 8550 550

2450 7350 350

3000 9000 0

5000 15000 0

1500 4500 500

1100 3300 300

950 2850 850

3000 9000 0

1300 3900 900

4500 13500 500


15 rows selected.

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1* SELECT SAL, SAL*3, TRUNC((SAL*3)/1000,0) FROM EMP


SQL> /

SAL SAL*3 TRUNC((SAL*3)/1000,0)

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

800 2400 2

1600 4800 4

1250 3750 3

2975 8925 8

1250 3750 3

2850 8550 8

2450 7350 7

3000 9000 9

5000 15000 15

1500 4500 4

1100 3300 3

950 2850 2

3000 9000 9

1300 3900 3

4500 13500 13

15 rows selected.

SQL> CL SCR
SQL> SELECT SYSDATE, SYSDATE+10, SYSDATE-10 FROM DUAL;

SYSDATE SYSDATE+1 SYSDATE-1

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

26-APR-09 06-MAY-09 16-APR-09

SQL> SELECT TRUNC(SYSDATE-HIREDATE,0) FROM EMP;


TRUNC(SYSDATE-HIREDATE,0)

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

10357

10292

10290

10251

10072

10222

10183

8043

10022

10092

8009

10006

10006

9955

3768

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SYSDATE,HIREDATE,TRUNC(SYSDATE-HIREDATE,0) NO_DAYS FROM EMP


SQL> /

SYSDATE HIREDATE NO_DAYS

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

26-APR-09 17-DEC-80 10357

26-APR-09 20-FEB-81 10292

26-APR-09 22-FEB-81 10290

26-APR-09 02-APR-81 10251

26-APR-09 28-SEP-81 10072

26-APR-09 01-MAY-81 10222


26-APR-09 09-JUN-81 10183

26-APR-09 19-APR-87 8043

26-APR-09 17-NOV-81 10022

26-APR-09 08-SEP-81 10092

26-APR-09 23-MAY-87 8009

26-APR-09 03-DEC-81 10006

26-APR-09 03-DEC-81 10006

26-APR-09 23-JAN-82 9955

26-APR-09 01-JAN-99 3768

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SYSDATE,HIREDATE,TRUNC((SYSDATE-HIREDATE)/12,0) NO_MONTHS FROM EMP


SQL> /

SYSDATE HIREDATE NO_MONTHS

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

26-APR-09 17-DEC-80 863

26-APR-09 20-FEB-81 857

26-APR-09 22-FEB-81 857

26-APR-09 02-APR-81 854

26-APR-09 28-SEP-81 839

26-APR-09 01-MAY-81 851

26-APR-09 09-JUN-81 848

26-APR-09 19-APR-87 670

26-APR-09 17-NOV-81 835

26-APR-09 08-SEP-81 841

26-APR-09 23-MAY-87 667

26-APR-09 03-DEC-81 833

26-APR-09 03-DEC-81 833


26-APR-09 23-JAN-82 829

26-APR-09 01-JAN-99 314

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SYSDATE,HIREDATE,TRUNC((SYSDATE-HIREDATE)/365,0) NO_YEARS FROM EMP


SQL> /

SYSDATE HIREDATE NO_YEARS

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

26-APR-09 17-DEC-80 28

26-APR-09 20-FEB-81 28

26-APR-09 22-FEB-81 28

26-APR-09 02-APR-81 28

26-APR-09 28-SEP-81 27

26-APR-09 01-MAY-81 28

26-APR-09 09-JUN-81 27

26-APR-09 19-APR-87 22

26-APR-09 17-NOV-81 27

26-APR-09 08-SEP-81 27

26-APR-09 23-MAY-87 21

26-APR-09 03-DEC-81 27

26-APR-09 03-DEC-81 27

26-APR-09 23-JAN-82 27

26-APR-09 01-JAN-99 10

15 rows selected.

SQL> CL SCR
SQL> ALTER SESSION SET NLS_DATE_FORMAT ='DD-MON-RRRR HH24:MI.SS';

Session altered.

SQL> SELECT SYSDATE FROM DUAL;

SYSDATE
--------------------

26-APR-2009 12:06.12

SQL> SELECT SYSDATE, SYSDATE+8 FROM DUAL;

SYSDATE SYSDATE+8

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

26-APR-2009 12:06.35 04-MAY-2009 12:06.35

SQL> ED
Wrote file afiedt.buf

1* SELECT SYSDATE, SYSDATE+8/24 FROM DUAL


SQL> /

SYSDATE SYSDATE+8/24

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

26-APR-2009 12:07.18 26-APR-2009 20:07.18

SQL> ALTER SESSION SET NLS_DATE_FORMAT ='DD-MON-RRRR HH:MI.SS AM';

Session altered.

SQL> SELECT SYSDATE, SYSDATE+8/24 FROM DUAL;

SYSDATE SYSDATE+8/24

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

26-APR-2009 12:07.43 PM 26-APR-2009 08:07.43 PM

SQL> CL SWCR
SP2-0158: unknown CLEAR option "SWCR"
SQL> CL SCR
SQL> L
1* SELECT SYSDATE, SYSDATE+8/24 FROM DUAL
SQL> /

SYSDATE SYSDATE+8/24

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

26-APR-2009 12:07.49 PM 26-APR-2009 08:07.49 PM

SQL> ED
Wrote file afiedt.buf
1* SELECT SYSDATE, SYSDATE+36/24 FROM DUAL
SQL> /

SYSDATE SYSDATE+36/24

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

26-APR-2009 12:08.32 PM 28-APR-2009 12:08.32 AM

SQL> ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-RR';

Session altered.

SQL> SELECT SYSDATE, SYSDATE+8/24 FROM DUAL;

SYSDATE SYSDATE+8

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

26-APR-09 26-APR-09

SQL> SELECT SYSDATE, SYSDATE+36/24 FROM DUAL;

SYSDATE SYSDATE+3

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

26-APR-09 28-APR-09

SQL> CL SCR
SQL> -- MONTHS_BETWEEN
SQL> SELECT HIREDATE,SYSDATE, TRUNC(MONTHS_BETWEEN(SYSDATE,HIREDATE),0) FROM EMP;

HIREDATE SYSDATE TRUNC(MONTHS_BETWEEN(SYSDATE,HIREDATE),0)

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

17-DEC-80 26-APR-09 340

20-FEB-81 26-APR-09 338

22-FEB-81 26-APR-09 338

02-APR-81 26-APR-09 336

28-SEP-81 26-APR-09 330

01-MAY-81 26-APR-09 335

09-JUN-81 26-APR-09 334

19-APR-87 26-APR-09 264

17-NOV-81 26-APR-09 329


08-SEP-81 26-APR-09 331

23-MAY-87 26-APR-09 263

03-DEC-81 26-APR-09 328

03-DEC-81 26-APR-09 328

23-JAN-82 26-APR-09 327

01-JAN-99 26-APR-09 123

15 rows selected.

SQL> CL SCR
SQL> -- ROUND, TRUNC
SQL> /*
DOC> ROUND WITH DATES
DOC> MONTHS YEAR
DOC> <=15 RET CURREN_MONTH 1ST <=6 RET CURRENT YEAR 1ST
DOC> >15 RET NEXT MONTH 1ST >6 RET NEXT YEAR 1ST
DOC>*/
SQL> SELECT SYSDATE FROM DUAL;

SYSDATE

---------

26-APR-09

SQL> SELECT SYSDATE, ROUND(SYSDATE,'MONTH'), ROUND((SYSDATE-12),'MONTH') FROM


DUAL;

SYSDATE ROUND(SYS ROUND((SY

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

26-APR-09 01-MAY-09 01-APR-09

SQL> ED
Wrote file afiedt.buf

1 SELECT SYSDATE, ROUND(SYSDATE,'MONTH'), ROUND((SYSDATE-12),'MONTH'),


2 ROUND((SYSDATE-11),'MONTH')
3* FROM DUAL
SQL> /

SYSDATE ROUND(SYS ROUND((SY ROUND((SY

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

26-APR-09 01-MAY-09 01-APR-09 01-APR-09

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1 SELECT SYSDATE, ROUND(SYSDATE,'MONTH'), ROUND((SYSDATE-12),'MONTH'),


2 ROUND((SYSDATE-11),'MONTH')
3* FROM DUAL
SQL> CL SCR
SQL> -- ADD_MONTHS()
SQL> SELECT SYSDATE, ADD_MONTHS(SYSDATE,6), ADD_MONTHS(SYSDATE,-6) FROM DUAL;

SYSDATE ADD_MONTH ADD_MONTH

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

26-APR-09 26-OCT-09 26-OCT-08

SQL> SELECT SYSDATE, ROUND(SYSDATE,'YEAR'), ROUND(ADD_MONTHS(SYSDATE,2),'YEAR'),


2 ROUND(ADD_MONTHS(SYSDATE,6)) FROM DUAL;

SYSDATE ROUND(SYS ROUND(ADD ROUND(ADD

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

26-APR-09 01-JAN-09 01-JAN-09 27-OCT-09

SQL> ED
Wrote file afiedt.buf

1 SELECT SYSDATE, ROUND(SYSDATE,'YEAR'), ROUND(ADD_MONTHS(SYSDATE,2),'YEAR'),


2* ROUND(ADD_MONTHS(SYSDATE,6),'YEAR') FROM DUAL
SQL> /

SYSDATE ROUND(SYS ROUND(ADD ROUND(ADD

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

26-APR-09 01-JAN-09 01-JAN-09 01-JAN-10

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1 SELECT SYSDATE, TRUNC(SYSDATE,'YEAR'), TRUNC(ADD_MONTHS(SYSDATE,2),'YEAR'),


2* TRUNC(ADD_MONTHS(SYSDATE,6),'YEAR') FROM DUAL
SQL> /

SYSDATE TRUNC(SYS TRUNC(ADD TRUNC(ADD

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

26-APR-09 01-JAN-09 01-JAN-09 01-JAN-09

SQL> ED
Wrote file afiedt.buf
1 SELECT SYSDATE, TRUNC(SYSDATE,'MONTH'), TRUNC(SYSDATE,-12,'MONTH'),
2* TRUNC(SYSDATE-11,'MONTH') FROM DUAL
SQL> /
SELECT SYSDATE, TRUNC(SYSDATE,'MONTH'), TRUNC(SYSDATE,-12,'MONTH'),
*
ERROR at line 1:
ORA-00939: too many arguments for function

SQL> ED
Wrote file afiedt.buf

1 SELECT SYSDATE, TRUNC(SYSDATE,'MONTH'), TRUNC(SYSDATE-12,'MONTH'),


2* TRUNC(SYSDATE-11,'MONTH') FROM DUAL
SQL> /

SYSDATE TRUNC(SYS TRUNC(SYS TRUNC(SYS

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

26-APR-09 01-APR-09 01-APR-09 01-APR-09

SQL> CL SCR
SQL> SELECT LAST_DAY(SYSDATE) FROM DUAL;

LAST_DAY(

---------

30-APR-09

SQL> ED
Wrote file afiedt.buf

1* SELECT TRUNC(SYSDATE,'MONTH'),LAST_DAY(SYSDATE) FROM DUAL


SQL> /

TRUNC(SYS LAST_DAY(

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

01-APR-09 30-APR-09

SQL> CL SCR\
SP2-0158: unknown CLEAR option "\"
SQL> SELECT 1000*1000 FROM DUAL;

1000*1000

----------

1000000
SQL> ED
Wrote file afiedt.buf

1* SELECT 1000*1000 NO_OF_THOUSANDS FROM DUAL


SQL> /

NO_OF_THOUSANDS

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

1000000

SQL> ED
Wrote file afiedt.buf

1* SELECT 1000*'1000' NO_OF_THOUSANDS FROM DUAL


SQL> /

NO_OF_THOUSANDS

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

1000000

SQL> CL SCR
SQL> CREATE TABLE CONVERSION
2 AS
3 SELECT ENAME, TO_CHAR(SAL) SAL, TO_CHAR(HIREDATE,'DD-MON-RRRR')HIREDATE FROM
EMP;

Table created.

SQL> DESC EMP


Name Null? Type
----------------------------------------------------- --------
------------------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2)

SQL> DESC CONVERSION


Name Null? Type
----------------------------------------------------- --------
------------------------------------
ENAME VARCHAR2(10)
SAL VARCHAR2(40)
HIREDATE VARCHAR2(11)

SQL> CL SCR
SQL> SELECT SAL FROM EMP;
SAL

----------

800

1600

1250

2975

1250

2850

2450

3000

5000

1500

1100

950

3000

1300

4500

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SAL FROM CONVERSION


SQL> /

SAL

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

800

1600

1250

2975

1250

2850
2450

3000

5000

1500

1100

950

3000

1300

4500

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_NUMBER(SAL) FROM CONVERSION


SQL> /

TO_NUMBER(SAL)

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

800

1600

1250

2975

1250

2850

2450

3000

5000

1500

1100

950

3000
1300

4500

15 rows selected.

SQL> CL SCR
SQL> SELECT HIREDATE FROM EMP;

HIREDATE

---------

17-DEC-80

20-FEB-81

22-FEB-81

02-APR-81

28-SEP-81

01-MAY-81

09-JUN-81

19-APR-87

17-NOV-81

08-SEP-81

23-MAY-87

03-DEC-81

03-DEC-81

23-JAN-82

01-JAN-99

15 rows selected.

SQL> SELECT HIREDATE FROM CONVERSION;

HIREDATE

-----------

17-DEC-1980

20-FEB-1981

22-FEB-1981
02-APR-1981

28-SEP-1981

01-MAY-1981

09-JUN-1981

19-APR-1987

17-NOV-1981

08-SEP-1981

23-MAY-1987

03-DEC-1981

03-DEC-1981

23-JAN-1982

01-JAN-1999

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_DATE(HIREDATE,'DD-MON-RR') FROM CONVERSION


SQL> /

TO_DATE(H

---------

17-DEC-80

20-FEB-81

22-FEB-81

02-APR-81

28-SEP-81

01-MAY-81

09-JUN-81

19-APR-87

17-NOV-81

08-SEP-81
23-MAY-87

03-DEC-81

03-DEC-81

23-JAN-82

01-JAN-99

15 rows selected.

SQL> CL SCR
SQL> SELECT TO_CHAR(SYSDATE,'D DD DDD')DAYS,
2 TO_CHAR(SYSDATE,'MM MON MONTH')MONTHS,
3 TO_CHAR(SYSDATE,'Y YY YYY YYYY YEAR SYEAR')YEARS FROM DUAL;

DAYS MONTHS

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

YEARS

----------------------------------------------------------------------------------
------------------
1 26 116 04 APR APRIL

9 09 009 2009 TWO THOUSAND NINE TWO THOUSAND NINE

SQL> CL SCR
SQL> SELECT TO_CHAR(SYSDATE,'DD.MM.RRRR BC A.D') FROM DUAL;
SELECT TO_CHAR(SYSDATE,'DD.MM.RRRR BC A.D') FROM DUAL
*
ERROR at line 1:
ORA-01821: date format not recognized

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(SYSDATE,'DD.MM.RRRR') FROM DUAL


SQL> /

TO_CHAR(SY

----------

26.04.2009

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(SYSDATE,'DD.MM.RRRR BC AD B.C. A.D.') FROM DUAL


SQL> /

TO_CHAR(SYSDATE,'DD.MM.RRR

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

26.04.2009 AD AD A.D. A.D.

SQL> CL SCR
SQL> SELECT TO_CHAR(SYSDATE,'DD.RM.RRRR') FROM DUAL;

TO_CHAR(SYSD

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

26.IV .2009

SQL> SELECT TO_CHAR(SYSDATE,'DD.MONTH.YEAR') FROM DUAL;

TO_CHAR(SYSDATE,'DD.MONTH.YEAR')

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

26.APRIL .TWO THOUSAND NINE

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(SYSDATE,'DD.MONTH.YEAR DAY DY W WW') FROM DUAL


SQL> /

TO_CHAR(SYSDATE,'DD.MONTH.YEARDAYDYWWW')

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

26.APRIL .TWO THOUSAND NINE SUNDAY SUN 4 17

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(SYSDATE,'FMDD.MONTH.YEAR DAY DY W WW') FROM DUAL


SQL> /

TO_CHAR(SYSDATE,'FMDD.MONTH.YEARDAYDYWWW')

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

26.APRIL.TWO THOUSAND NINE SUNDAY SUN 4 17

SQL> CL SCR
SQL> L
1* SELECT TO_CHAR(SYSDATE,'FMDD.MONTH.YEAR DAY DY W WW') FROM DUAL
SQL> /
TO_CHAR(SYSDATE,'FMDD.MONTH.YEARDAYDYWWW')

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

26.APRIL.TWO THOUSAND NINE SUNDAY SUN 4 17

SQL> SELECT TO_CHAR(SYSDATE,'DD.MONTH.YEAR DAY DY W WW') FROM DUAL;

TO_CHAR(SYSDATE,'DD.MONTH.YEARDAYDYWWW')

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

26.APRIL .TWO THOUSAND NINE SUNDAY SUN 4 17

SQL> SELECT TO_CHAR(SYSDATE,'FMDD.MONTH.YEAR DAY DY W WW') FROM DUAL;

TO_CHAR(SYSDATE,'FMDD.MONTH.YEARDAYDYWWW')

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

26.APRIL.TWO THOUSAND NINE SUNDAY SUN 4 17

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(HIREDATE,'FMDDTH.MONTH.YEAR DAY DY') FROM EMP


SQL> /

TO_CHAR(HIREDATE,'FMDDTH.MONTH.YEARDAYDY')

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

17TH.DECEMBER.NINETEEN EIGHTY WEDNESDAY WED

20TH.FEBRUARY.NINETEEN EIGHTY-ONE FRIDAY FRI

22ND.FEBRUARY.NINETEEN EIGHTY-ONE SUNDAY SUN

2ND.APRIL.NINETEEN EIGHTY-ONE THURSDAY THU

28TH.SEPTEMBER.NINETEEN EIGHTY-ONE MONDAY MON

1ST.MAY.NINETEEN EIGHTY-ONE FRIDAY FRI

9TH.JUNE.NINETEEN EIGHTY-ONE TUESDAY TUE

19TH.APRIL.NINETEEN EIGHTY-SEVEN SUNDAY SUN

17TH.NOVEMBER.NINETEEN EIGHTY-ONE TUESDAY TUE

8TH.SEPTEMBER.NINETEEN EIGHTY-ONE TUESDAY TUE

23RD.MAY.NINETEEN EIGHTY-SEVEN SATURDAY SAT


3RD.DECEMBER.NINETEEN EIGHTY-ONE THURSDAY THU

3RD.DECEMBER.NINETEEN EIGHTY-ONE THURSDAY THU

23RD.JANUARY.NINETEEN EIGHTY-TWO SATURDAY SAT

1ST.JANUARY.NINETEEN NINETY-NINE FRIDAY FRI

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(HIREDATE,'DDTH.MONTH.YEAR DAY DY') FROM EMP


SQL> /

TO_CHAR(HIREDATE,'DDTH.MONTH.YEARDAYDY')

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

17TH.DECEMBER .NINETEEN EIGHTY WEDNESDAY WED

20TH.FEBRUARY .NINETEEN EIGHTY-ONE FRIDAY FRI

22ND.FEBRUARY .NINETEEN EIGHTY-ONE SUNDAY SUN

02ND.APRIL .NINETEEN EIGHTY-ONE THURSDAY THU

28TH.SEPTEMBER.NINETEEN EIGHTY-ONE MONDAY MON

01ST.MAY .NINETEEN EIGHTY-ONE FRIDAY FRI

09TH.JUNE .NINETEEN EIGHTY-ONE TUESDAY TUE

19TH.APRIL .NINETEEN EIGHTY-SEVEN SUNDAY SUN

17TH.NOVEMBER .NINETEEN EIGHTY-ONE TUESDAY TUE

08TH.SEPTEMBER.NINETEEN EIGHTY-ONE TUESDAY TUE

23RD.MAY .NINETEEN EIGHTY-SEVEN SATURDAY SAT

03RD.DECEMBER .NINETEEN EIGHTY-ONE THURSDAY THU

03RD.DECEMBER .NINETEEN EIGHTY-ONE THURSDAY THU

23RD.JANUARY .NINETEEN EIGHTY-TWO SATURDAY SAT

01ST.JANUARY .NINETEEN NINETY-NINE FRIDAY FRI

15 rows selected.

SQL> SELECT TO_CHAR(HIREDATE,'FMDDTH.MONTH.YEAR DAY DY') FROM EMP;

TO_CHAR(HIREDATE,'FMDDTH.MONTH.YEARDAYDY')
-----------------------------------------------------------------------

17TH.DECEMBER.NINETEEN EIGHTY WEDNESDAY WED

20TH.FEBRUARY.NINETEEN EIGHTY-ONE FRIDAY FRI

22ND.FEBRUARY.NINETEEN EIGHTY-ONE SUNDAY SUN

2ND.APRIL.NINETEEN EIGHTY-ONE THURSDAY THU

28TH.SEPTEMBER.NINETEEN EIGHTY-ONE MONDAY MON

1ST.MAY.NINETEEN EIGHTY-ONE FRIDAY FRI

9TH.JUNE.NINETEEN EIGHTY-ONE TUESDAY TUE

19TH.APRIL.NINETEEN EIGHTY-SEVEN SUNDAY SUN

17TH.NOVEMBER.NINETEEN EIGHTY-ONE TUESDAY TUE

8TH.SEPTEMBER.NINETEEN EIGHTY-ONE TUESDAY TUE

23RD.MAY.NINETEEN EIGHTY-SEVEN SATURDAY SAT

3RD.DECEMBER.NINETEEN EIGHTY-ONE THURSDAY THU

3RD.DECEMBER.NINETEEN EIGHTY-ONE THURSDAY THU

23RD.JANUARY.NINETEEN EIGHTY-TWO SATURDAY SAT

1ST.JANUARY.NINETEEN NINETY-NINE FRIDAY FRI

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(HIREDATE,'DDTH.MONTH.DAY.YEAR DY') FROM EMP


SQL> CL SCR
SQL> L
1* SELECT TO_CHAR(HIREDATE,'DDTH.MONTH.DAY.YEAR DY') FROM EMP
SQL> /

TO_CHAR(HIREDATE,'DDTH.MONTH.DAY.YEARDY')

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

17TH.DECEMBER .WEDNESDAY.NINETEEN EIGHTY WED

20TH.FEBRUARY .FRIDAY .NINETEEN EIGHTY-ONE FRI

22ND.FEBRUARY .SUNDAY .NINETEEN EIGHTY-ONE SUN

02ND.APRIL .THURSDAY .NINETEEN EIGHTY-ONE THU

28TH.SEPTEMBER.MONDAY .NINETEEN EIGHTY-ONE MON


01ST.MAY .FRIDAY .NINETEEN EIGHTY-ONE FRI

09TH.JUNE .TUESDAY .NINETEEN EIGHTY-ONE TUE

19TH.APRIL .SUNDAY .NINETEEN EIGHTY-SEVEN SUN

17TH.NOVEMBER .TUESDAY .NINETEEN EIGHTY-ONE TUE

08TH.SEPTEMBER.TUESDAY .NINETEEN EIGHTY-ONE TUE

23RD.MAY .SATURDAY .NINETEEN EIGHTY-SEVEN SAT

03RD.DECEMBER .THURSDAY .NINETEEN EIGHTY-ONE THU

03RD.DECEMBER .THURSDAY .NINETEEN EIGHTY-ONE THU

23RD.JANUARY .SATURDAY .NINETEEN EIGHTY-TWO SAT

01ST.JANUARY .FRIDAY .NINETEEN NINETY-NINE FRI

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(HIREDATE,'FMDDTH.MONTH.DAY.YEAR DY') FROM EMP


SQL> /

TO_CHAR(HIREDATE,'FMDDTH.MONTH.DAY.YEARDY')

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

17TH.DECEMBER.WEDNESDAY.NINETEEN EIGHTY WED

20TH.FEBRUARY.FRIDAY.NINETEEN EIGHTY-ONE FRI

22ND.FEBRUARY.SUNDAY.NINETEEN EIGHTY-ONE SUN

2ND.APRIL.THURSDAY.NINETEEN EIGHTY-ONE THU

28TH.SEPTEMBER.MONDAY.NINETEEN EIGHTY-ONE MON

1ST.MAY.FRIDAY.NINETEEN EIGHTY-ONE FRI

9TH.JUNE.TUESDAY.NINETEEN EIGHTY-ONE TUE

19TH.APRIL.SUNDAY.NINETEEN EIGHTY-SEVEN SUN

17TH.NOVEMBER.TUESDAY.NINETEEN EIGHTY-ONE TUE

8TH.SEPTEMBER.TUESDAY.NINETEEN EIGHTY-ONE TUE

23RD.MAY.SATURDAY.NINETEEN EIGHTY-SEVEN SAT

3RD.DECEMBER.THURSDAY.NINETEEN EIGHTY-ONE THU


3RD.DECEMBER.THURSDAY.NINETEEN EIGHTY-ONE THU

23RD.JANUARY.SATURDAY.NINETEEN EIGHTY-TWO SAT

1ST.JANUARY.FRIDAY.NINETEEN NINETY-NINE FRI

15 rows selected.

SQL> CL SCR
SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(HIREDATE,'FMDDSPTH.MONTH.DAY.YEAR DY') FROM EMP


SQL> /

TO_CHAR(HIREDATE,'FMDDSPTH.MONTH.DAY.YEARDY')

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

SEVENTEENTH.DECEMBER.WEDNESDAY.NINETEEN EIGHTY WED

TWENTIETH.FEBRUARY.FRIDAY.NINETEEN EIGHTY-ONE FRI

TWENTY-SECOND.FEBRUARY.SUNDAY.NINETEEN EIGHTY-ONE SUN

SECOND.APRIL.THURSDAY.NINETEEN EIGHTY-ONE THU

TWENTY-EIGHTH.SEPTEMBER.MONDAY.NINETEEN EIGHTY-ONE MON

FIRST.MAY.FRIDAY.NINETEEN EIGHTY-ONE FRI

NINTH.JUNE.TUESDAY.NINETEEN EIGHTY-ONE TUE

NINETEENTH.APRIL.SUNDAY.NINETEEN EIGHTY-SEVEN SUN

SEVENTEENTH.NOVEMBER.TUESDAY.NINETEEN EIGHTY-ONE TUE

EIGHTH.SEPTEMBER.TUESDAY.NINETEEN EIGHTY-ONE TUE

TWENTY-THIRD.MAY.SATURDAY.NINETEEN EIGHTY-SEVEN SAT

THIRD.DECEMBER.THURSDAY.NINETEEN EIGHTY-ONE THU

THIRD.DECEMBER.THURSDAY.NINETEEN EIGHTY-ONE THU

TWENTY-THIRD.JANUARY.SATURDAY.NINETEEN EIGHTY-TWO SAT

FIRST.JANUARY.FRIDAY.NINETEEN NINETY-NINE FRI

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT INITCAP(TO_CHAR(HIREDATE,'FMDDSPTH.MONTH.DAY.YEAR DY')) FROM EMP


SQL> /
INITCAP(TO_CHAR(HIREDATE,'FMDDSPTH.MONTH.DAY.YEARDY'))

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

Seventeenth.December.Wednesday.Nineteen Eighty Wed

Twentieth.February.Friday.Nineteen Eighty-One Fri

Twenty-Second.February.Sunday.Nineteen Eighty-One Sun

Second.April.Thursday.Nineteen Eighty-One Thu

Twenty-Eighth.September.Monday.Nineteen Eighty-One Mon

First.May.Friday.Nineteen Eighty-One Fri

Ninth.June.Tuesday.Nineteen Eighty-One Tue

Nineteenth.April.Sunday.Nineteen Eighty-Seven Sun

Seventeenth.November.Tuesday.Nineteen Eighty-One Tue

Eighth.September.Tuesday.Nineteen Eighty-One Tue

Twenty-Third.May.Saturday.Nineteen Eighty-Seven Sat

Third.December.Thursday.Nineteen Eighty-One Thu

Third.December.Thursday.Nineteen Eighty-One Thu

Twenty-Third.January.Saturday.Nineteen Eighty-Two Sat

First.January.Friday.Nineteen Ninety-Nine Fri

15 rows selected.

SQL> CL SCR
SQL> SELECT SAL FROM EMP;

SAL

----------

800

1600

1250

2975

1250

2850

2450
3000

5000

1500

1100

950

3000

1300

4500

15 rows selected.

SQL> SELECT SAL, TO_DATE(SAL,'J') FROM EMP;

SAL TO_DATE(S

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

800 11-MAR-10

1600 19-MAY-08

1250 04-JUN-09

2975 23-FEB-04

1250 04-JUN-09

2850 21-OCT-05

2450 16-SEP-06

3000 19-MAR-04

5000 09-SEP-99

1500 09-FEB-08

1100 05-JAN-09

950 08-AUG-10

3000 19-MAR-04

1300 24-JUL-09

4500 27-APR-00

15 rows selected.
SQL> CL SCR
SQL> L
1* SELECT SAL, TO_DATE(SAL,'J') FROM EMP
SQL> ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-YYYY B.C.';

Session altered.

SQL> SELECT SAL, TO_DATE(SAL,'J') FROM EMP;

SAL TO_DATE(SAL,'J')

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

800 11-MAR-4710 B.C.

1600 19-MAY-4708 B.C.

1250 04-JUN-4709 B.C.

2975 23-FEB-4704 B.C.

1250 04-JUN-4709 B.C.

2850 21-OCT-4705 B.C.

2450 16-SEP-4706 B.C.

3000 19-MAR-4704 B.C.

5000 09-SEP-4699 B.C.

1500 09-FEB-4708 B.C.

1100 05-JAN-4709 B.C.

950 08-AUG-4710 B.C.

3000 19-MAR-4704 B.C.

1300 24-JUL-4709 B.C.

4500 27-APR-4700 B.C.

15 rows selected.

SQL> CL SCR
SQL> SELECT TO_CHAR(SYSDATE,'J') FROM DUAL;

TO_CHAR

-------

2454948

SQL> ED
Wrote file afiedt.buf

1* SELECT TO_CHAR(SYSDATE,'JSP') FROM DUAL


SQL> /

TO_CHAR(SYSDATE,'JSP')

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

TWO MILLION FOUR HUNDRED FIFTY-FOUR THOUSAND NINE HUNDRED FORTY-EIGHT

SQL> ALTER SESSION SET NLS_DATE_FORMAT='DD-MON-RR';

Session altered.

SQL> CL SCR
SQL> SELECT SAL FROM EMP;

SAL

----------

800

1600

1250

2975

1250

2850

2450

3000

5000

1500

1100

950

3000

1300

4500

15 rows selected.

SQL> ED
Wrote file afiedt.buf
1* SELECT SAL, TO_DATE(SAL,'J') FROM EMP
SQL> /

SAL TO_DATE(S

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

800 11-MAR-10

1600 19-MAY-08

1250 04-JUN-09

2975 23-FEB-04

1250 04-JUN-09

2850 21-OCT-05

2450 16-SEP-06

3000 19-MAR-04

5000 09-SEP-99

1500 09-FEB-08

1100 05-JAN-09

950 08-AUG-10

3000 19-MAR-04

1300 24-JUL-09

4500 27-APR-00

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SAL, TO_CHAR(TO_DATE(SAL,'J'),'J') FROM EMP


SQL> /

SAL TO_CHAR

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

800 0000800

1600 0001600

1250 0001250

2975 0002975
1250 0001250

2850 0002850

2450 0002450

3000 0003000

5000 0005000

1500 0001500

1100 0001100

950 0000950

3000 0003000

1300 0001300

4500 0004500

15 rows selected.

SQL> ED
Wrote file afiedt.buf

1* SELECT SAL, TO_CHAR(TO_DATE(SAL,'J'),'JSP') FROM EMP


SQL> /

SAL TO_CHAR(TO_DATE(SAL,'J'),'JSP')

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

800 EIGHT HUNDRED

1600 ONE THOUSAND SIX HUNDRED

1250 ONE THOUSAND TWO HUNDRED FIFTY

2975 TWO THOUSAND NINE HUNDRED SEVENTY-FIVE

1250 ONE THOUSAND TWO HUNDRED FIFTY

2850 TWO THOUSAND EIGHT HUNDRED FIFTY

2450 TWO THOUSAND FOUR HUNDRED FIFTY

3000 THREE THOUSAND

5000 FIVE THOUSAND

1500 ONE THOUSAND FIVE HUNDRED

1100 ONE THOUSAND ONE HUNDRED


950 NINE HUNDRED FIFTY

3000 THREE THOUSAND

1300 ONE THOUSAND THREE HUNDRED

4500 FOUR THOUSAND FIVE HUNDRED

15 rows selected.

SQL> CL SCR
SQL> SELECT TO_CHAR(SYSDATE,'HH:MI.SS SSSS AM P.M.'),
2 TO_CHAR(SYSDATE,'HH24:MI.SS') FROM DUAL;

TO_CHAR(SYSDATE,'HH:M TO_CHAR(

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

12:55.44 4444 PM P.M. 12:55.44

SQL> SPOOL OFF