only My site

Wednesday, December 26, 2007

Oracle - Useful functions

/Create Table using As
CREATE TABLE New_Table_Name AS SELECT * FROM Table_Name WHERE Column1 >100;

SQL> SELECT 5/2 FROM DUAL
2 /

5/2
---------
2.5

SQL> SELECT -5/2 FROM DUAL
2 /

-5/2
---------
-2.5

SQL> SELECT ABS(-5/2) FROM DUAL
2 /

ABS(-5/2)
---------
2.5

SQL> SELECT ROUND(5/2) FROM DUAL;

ROUND(5/2)
----------
3

SQL> SELECT ROUND(-5/2) FROM DUAL;

ROUND(-5/2)
-----------
-3

SQL> SELECT CEIL(5/2) FROM DUAL;

CEIL(5/2)
---------
3

SQL> SELECT FLOOR(5/2) FROM DUAL;

FLOOR(5/2)
----------
2

SQL> SELECT TO_CHAR(SYSDATE) FROM DUAL;

TO_CHAR(S
---------
18-DEC-07

SQL> SELECT TO_DATE('18-Dec-07') FROM DUAL;

TO_DATE('
---------
18-DEC-07

SQL> SELECT TO_NUMBER('143') FROM DUAL;

TO_NUMBER('143')
----------------
143

SQL> SELECT UPPER('bALA') FROM DUAL;

UPPER('BALA')
--------------------------------
BALA

SQL> SELECT LOWER('sANdyA') FROM DUAL;

LOWER('SANDYA')
--------------------------------
sandya

SQL> SELECT SUBSTR('Bala krishnan',6,5) FROM DUAL;

SUBSTR('BALAKRISHNAN',6,5)
--------------------------------
krish

SQL> SELECT SUBSTR('Bala Krishnan',6) FROM DUAL;

SUBSTR('BALAKRISHNAN',6)
--------------------------------
Krishnan

SQL> SELECT NVL(NULL,'0') FROM DUAL;

NVL(NULL,'0')
--------------------------------
0

SQL> SELECT DECODE(NULL,NULL,0,1) FROM DUAL;

DECODE(NULL,NULL,0,1)
---------------------
0

SQL> SELECT LPAD(5,10,'*') FROM DUAL;

LPAD(5,10,'*')
-----------------
*********5

SQL> SELECT RPAD(6,10,'*') FROM DUAL;

RPAD(6,10,'*')
-----------------
6*********

SQL> SELECT LEAST(1,5,2,7) , GREATEST(1,5,2,7) FROM DUAL;
O/P
----
1 7

No comments: