1. ¼ýÀÚ ÇÔ¼ö(Number Function)
ABS(n)
ABSÇÔ¼ö´Â Àý´ë°ªÀ» °è»êÇÏ´Â ÇÔ¼öÀÔ´Ï´Ù.
SQL>SELECT ABS(-10) Absolute FROM dual ;
Absolute
--------
10
CEIL(n)
CEILÇÔ¼ö´Â ÁÖ¾îÁø °ªº¸´Ù´Â Å©Áö¸¸ °¡Àå ±ÙÁ¢ÇÏ´Â ÃÖ¼Ò°ªÀ» ±¸ÇÏ´Â ÇÔ¼öÀÔ´Ï´Ù.
SQL>SELECT CEIL(10.1) TEST FROM dual ;
TEST
-------
11
SQL>SELECT CEIL(-10.1) TEST FROM dual ;
TEST
-------
-10
EXP(n)
EXPÇÔ¼ö´Â ÁÖ¾îÁø °ªÀÇ eÀÇ ½Â¼ö¸¦ ³ªÅ¸³À´Ï´Ù.
e´Â 2.171828183..ÀÔ´Ï´Ù.
FLOOR(n)
FLOORÇÔ¼ö´Â ÁÖ¾îÁø °ªº¸´Ù À۰ųª °°Àº ÃÖ´ë Á¤¼ö°ªÀ» ±¸ÇÏ´Â ÇÔ¼öÀÔ´Ï´Ù.
CEIL ÇÔ¼ö¿Í ºñ±³ÇØ º¸¼¼¿ä.
SQL>SELECT FLOOR(10.1) TEST FROM dual ;
TEST
-------
10
SQL>SELECT FLOOR(-10.1) TEST FROM dual ;
TEST
-------
-11
LN(n)
LNÇÔ¼ö´Â ÁÖ¾îÁø °ªÀÇ ÀÚ¿¬·Î±× °ªÀ» ¹ÝȯÇÕ´Ï´Ù.
MOD(m, n)
MODÇÔ¼ö´Â mÀ» nÀ¸·Î ³ª´©¾î ³²Àº °ªÀ» ¹ÝȯÇÑ´Ù. nÀÌ 0ÀÏ °æ¿ì mÀ» ¹ÝȯÇÕ´Ï´Ù.
SQL>SELECT MOD(9, 4) TEST FROM dual ;
TEST
-------
1
POWER(m, n)
POWERÇÔ¼ö´Â mÀÇ n½Â °ªÀ» °è»êÇÕ´Ï´Ù.
SQL>SELECT POWER(4, 2) TEST FROM dual ;
TEST
-------
16
ROUND(n, [m])
ROUNDÇÔ¼ö´Â n°ªÀÇ ¹Ý¿Ã¸²À» ÇÏ´Â ÇÔ¼ö·Î mÀº ¼Ò¼ýÁ¡ ¾Æ·¡ ÀÚ¸´¼ö¸¦ ³ªÅ¸³À´Ï´Ù.
SQL>SELECT ROUND(192.123, 1) TEST FROM dual ;
TEST
-------
192.1
SQL>SELECT ROUND(192.123, -1) TEST FROM dual ;
TEST
-------
190
SIGN(n)
SIGNÇÔ¼ö´Â n<0ÀÏ °æ¿ì -1DFM N=0ÀÏ °æ¿ì 0À» N>0ÀÏ °æ¿ì 1À» ¹ÝȯÇÕ´Ï´Ù.
SQRT(n)
SQRTÇÔ¼ö´Â n°ªÀÇ ·çÆ®°ªÀ» °è»êÇÑ´Ù. nÀº ¾ç¼ö¿©¾ß ÇÕ´Ï´Ù.
TRUNC(n, m)
TRUNCÇÔ¼ö´Â n°ªÀ» m ¼Ò¼ýÁ¡ ÀÚ¸®·Î ¹Ý³»¸²ÇÑ °ªÀ» ¹ÝȯÇÕ´Ï´Ù.
SQL>SELECT TRUNC(7.5597, 2) TEST FROM dual ;
TEST
-------
7.55
SQL>SELECT TRUNC (5254.26, -2 ) TEST FROM dual ;
TEST
-------
5200
2. ¹®ÀÚ ÇÔ¼ö
CONCAT(char1, char2)
CONCAT ÇÔ¼ö´Â ConcatenationÀÇ ¾àÀÚ·Î µÎ ¹®ÀÚ¸¦ °áÇÕÇÏ´Â ¿ªÇÒÀ» ÇÕ´Ï´Ù. "||" ¿¬»êÀÚ¿Í °°Àº ¿ªÇÒÀ» ÇÕ´Ï´Ù.
SQL>SELECT CONCAT('Oracle', ' Korea') NAME FROM dual ;
NAME
-------------
Oracle Korea
INITCAP(char)
ÁÖ¾îÁø ¹®ÀÚ¿ÀÇ Ã¹ ¹ø° ¹®ÀÚ¸¦ ´ë¹®ÀÚ·Î º¯È¯½ÃÄÑ ÁÝ´Ï´Ù.
SQL>SELECT INITCAP('kim jung sick') NAME FROM dual ;
NAME
-------------
Kim jung sick
LOWER(char)
¹®ÀÚ¿À» ¼Ò¹®ÀÚ·Î º¯È¯ ½ÃÄÑ ÁÝ´Ï´Ù.
UPPER(char)
¹®ÀÚ¿À» ´ë¹®ÀÚ·Î º¯È¯ ½ÃÄÑ ÁÝ´Ï´Ù.
SQL>SELECT LOWER('KIM JUNG SICK') NAME FROM dual ;
NAME
-------------
kim jung sick
SQL>SELECT UPPER('kim jung sick') NAME FROM dual ;
NAME
--------------
KIM JUNG SICK
LPAD(char1, n [,char2])
¿ÞÂÊ¿¡ ¹®ÀÚ¿À» ³¢¾î ³õ´Â ¿ªÇÒÀ» ÇÕ´Ï´Ù. nÀº ¹ÝȯµÇ´Â ¹®ÀÚ¿ÀÇ Àüü ±æÀ̸¦ ³ªÅ¸³»¸ç, char1ÀÇ ¹®ÀÚ¿ÀÌ nº¸´Ù Ŭ °æ¿ì char1À» n°³ ¹®ÀÚ¿ ¸¸Å ¹ÝȯÇÕ´Ï´Ù.
SQL>SELECT LPAD('JUNG-SICK', 10, '*') NAME FROM dual ;
NAME
------------
*JUNG-SICK
RPAD(char1, n [,char2])
LPAD¿Í ¹Ý´ë·Î ¿À¸¥ÂÊ¿¡ ¹®ÀÚ¿À» ³¢¾î ³õ´Â ¿ªÇÒÀ» ÇÕ´Ï´Ù.
SQL>SELECT RPAD('JUNG-SICK', 10, '*') NAME FROM dual ;
NAME
------------
JUNG-SICK*
SUBSTR(char, m ,[n])
SUBSTRÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© m ¹ø° ÀÚ¸®ºÎÅÍ ±æÀÌ°¡ n°³ÀÎ ¹®ÀÚ¿À» ¹ÝȯÇÑ ÇÕ´Ï´Ù. mÀÌ À½¼öÀÏ °æ¿ì¿¡´Â µÚ¿¡¼ M¹ø° ¹®ÀÚºÎÅÍ ¹Ý´ë ¹æÇâÀ¸·Î n°³ÀÇ ¹®ÀÚ¸¦ ¹ÝȯÇÕ´Ï´Ù.
SQL>SELECT SUBSTR('JUNG-SICK', 3, 3) NAME FROM dual ;
NAME
-----------
NG-
-- µÚ¿¡¼ºÎÅÍ ÀÚ¸¦
SQL>SELECT SUBSTR('JUNG-SICK', -3, 3) NAME FROM dual ;
NAME
-----------
ICK
LENGTH(char1)
¹®ÀÚ¿ÀÇ ±æÀ̸¦ ¸®ÅÏ ÇÕ´Ï´Ù.
SQL>SELECT LENGTH('JUNG-SICK') TEST FROM dual ;
TEST
----------
9
REPLACE(char1, str1, str2)
REPLACE´Â ¹®ÀÚ¿ÀÇ Æ¯Á¤ ¹®ÀÚ¸¦ ´Ù¸¥ ¹®ÀÚ·Î º¯È¯ ÇÕ´Ï´Ù.
SQL> SELECT REPLACE('JACK and JUE','J','BL') "Changes" FROM DUAL;
Changes
--------------
BLACK and BLUE
SQL> SELECT REPLACE('JACK and JUE','JA','BL') "Changes" FROM DUAL
Changes
------------
BLCK and JUE
-- ´ë¼Ò¹®ÀÚ¸¦ ±¸ºÐÇÑ´Ù´Â °ÍÀ» ¾Ë¼ö ÀÖ½À´Ï´Ù.
SQL>SELECT REPLACE('JACK and JUE','j','BL') "Changes" FROM DUAL
Changes
------------
JACK and JUE
INSTR
¹®ÀÚ¿ÀÌ Æ÷ÇԵǾî ÀÖ´ÂÁö¸¦ Á¶»çÇÏ¿© ¹®ÀÚ¿ÀÇ À§Ä¡¸¦ ¹ÝȯÇÕ´Ï´Ù. ÁöÁ¤ÇÑ ¹®ÀÚ¿ÀÌ ¹ß°ßµÇÁö ¾ÊÀ¸¸é 0ÀÌ ¹Ýȯ µË´Ï´Ù.
-- ÁöÁ¤ÇÑ ¹®ÀÚ OK°¡ ¹ß°ßµÇÁö ¾Ê¾Æ¼ 0ÀÌ ¹Ýȯ µË´Ï´Ù.
SQL>SELECT INSTR('CORPORATE FLOOR','OK') "Instring" FROM DUAL
Instring
----------
0
-- ORÀÌ ÀÖ´Â À§Ä¡ 2¸¦ ¹Ýȯ ÇÕ´Ï´Ù. ¿ÞÂʺÎÅÍ ºñ±³¸¦ ÇÑ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù.
SQL>SELECT INSTR('CORPORATE FLOOR','OR') "Instring" FROM DUAL
Instring
----------
2
-- ¿ÞÂÊ¿¡¼ 3¹ø°ºÎÅÍ ½ÃÀÛÀ» Çؼ ºñ±³¸¦ ÇÕ´Ï´Ù. 2¹ø° ORÀÇ À§Ä¡°¡ ¹Ýȯ µË´Ï´Ù.
SQL>SELECT INSTR('CORPORATE FLOOR','OR', 3) "Instring" FROM DUAL
Instring
----------
5
-- ¿ÞÂÊ¿¡¼ 3¹ø°ºÎÅÍ ½ÃÀÛÀ» Çؼ ºñ±³¸¦ Çϴµ¥ ORÀÌ µÎ ¹ø° °Ë»öµÇ´Â ÁöÁ¡ÀÇ À§Ä¡¸¦ ¹Ýȯ ÇÕ´Ï´Ù.
SQL> SELECT INSTR('CORPORATE FLOOR','OR', 3, 2) "Instring" FROM DUAL;
Instring
----------
14
TRIM
ƯÁ¤ÇÑ ¹®ÀÚ¸¦ Á¦°Å ÇÕ´Ï´Ù.
Á¦°ÅÇÒ ¹®ÀÚ¸¦ ÀÔ·ÂÇÏÁö ¾ÊÀ¸¸é ±âº»ÀûÀ¸·Î °ø¹éÀÌ Á¦°Å µË´Ï´Ù.
¸®ÅÏ°ªÀÇ µ¥ÀÌÅÍŸÀÔÀº VARCHAR2 ÀÔ´Ï´Ù.
-- 0À» Á¦°Å ÇÕ´Ï´Ù.
SQL>SELECT TRIM(0 FROM 0009872348900) "TRIM Example" FROM DUAL;
TRIM Example
------------
98723489
-- ¾î¶² ¹®ÀÚµµ ÀÔ·ÂÇÏÁö ¾ÊÀ¸¸é ±âº»ÀûÀ¸·Î °ø¹éÀÌ Á¦°Å µË´Ï´Ù.
-- TRIMÀ» »ç¿ëÇÑ À§¿¡ ¿¹Á¦¿Í »ç¿ëÇÏÁö ¾ÊÀº ¾Æ·¡ ¿¹Á¦ÀÇ °á°ú °ªÀÌ ´Ù¸£°Ô ³ª¿À´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù.
SQL>SELECT NVL(TRIM (' '),'°ø¹é') "TRIM Example" FROM DUAL
TRIM Example
------------
°ø¹é
SQL>SELECT NVL(' ','°ø¹é') "TRIM Example" FROM DUAL
TRIM Example
------------
LTRIM
SQL>SELECT LTRIM('xyxXxyLAST WORD','xy') "LTRIM example" FROM DUAL;
LTRIM example
------------
XxyLAST WORD
RTRIM
SQL>SELECT RTRIM('BROWNINGyxXxy','xy') "RTRIM example" FROM DUAL;
RTRIM examp
-----------
BROWNINGyxX
3. ³¯Â¥ °ü·ÃÇÔ¼ö
LAST_DAY(d)
LAST_DAYÇÔ¼ö´Â ´ÞÀÇ ¸¶Áö¸· ³¯ÀÇ ³¯Â¥¸¦ ¹ÝȯÇÕ´Ï´Ù
SQL>SELECT SYSDATE TODAY, LAST_DAY(SYSDATE) LASTDAY FROM dual ;
TODAY LASTDAY
-----------------------------
05-JUN-2000 30-JUN-2000
ADD_MONTHS(a, b)
ADD_MONTHS ÇÔ¼ö´Â aÀÇ ³¯Â¥¿¡ bÀÇ ´ÞÀ» ´õÇÑ °ªÀ» ¹Ýȯ ÇÕ´Ï´Ù.
SQL>SELECT TO_CAHR(ADD_MONTHS(SYSDATE,3),'RRRR/MM/DD' LASTDAY) "date"
FROM dual ;
date
------------
2000/09/05
MONTH_BETWEEN(a1, a2)
MONTH_BETWEENÀº a1°ú a2 »çÀÌÀÇ ´ÞÀÇ ¼ö¸¦ NUMBERÇü ŸÀÔÀ¸·Î ¹Ýȯ ÇÕ´Ï´Ù.
SQL>SELECT MONTHS_BETWEEN(TO_DATE('2000/06/05') , TO_DATE('2000/09/23')) "Date" FROM dual ;
Date
----------------
-3.880635
ROUND(d[,F])
ROUND ÇÔ¼ö´Â F¿¡ ÁöÁ¤µÈ ´ÜÀ§·Î ¹Ý¿Ã¸² ÇÕ´Ï´Ù, F°¡ ¿¬µµ¶ó¸é ¿¬µµ ´ÜÀ§·Î ¹Ý¿Ã¸² ÇÕ´Ï´Ù.
SQL>SELECT ROUND(TO_DATE('1998/09/11'), 'YEAR') FROM dual ;
ROUND(TO_
--------------
99-01-01
SQL>SELECT ROUND(TO_DATE('1998/04/11'), 'MONTH') FROM dual ;
ROUND(TO_
---------------
98-04-01
SQL>SELECT ROUND(TO_DATE('1998/04/11'), 'DAY') FROM dual ;
ROUND(TO_
---------------
98-04-11
³¯Â¥¿¡ ´ëÇÑ »ê¼ú ¿¬»ê
¿¬ »ê °á°úÄ¡ »ç ¿ë ¸ñ Àû
³¯Â¥ + ¼ýÀÚ ³¯Â¥ ƯÁ¤ÇÑ ³¯·ÎºÎÅÍ ¸çÄ¥ ÈÄÀÇ ³¯Â¥ °è»ê
³¯Â¥ - ¼ýÀÚ ³¯Â¥ ƯÁ¤ÇÑ ³¯·ÎºÎÅÍ ¸çÄ¥ ÀüÀÇ ³¯Â¥ °è»ê
³¯Â¥ - ³¯Â¥ ¼ýÀÚ µÎ ³¯Â¥ »çÀÌÀÇ Â÷À̸¦ ¼ýÀÚ·Î °è»ê
4. º¯È¯ ÇÔ¼ö
TO_CHAR
TO_CHARÇÔ¼ö´Â DATEÇü, NUMBERÇüÀ» VARCHAR2ÇüÀ¸·Î ¹Ù²¨ ÁÝ´Ï´Ù.
SQL>SELECT TO_CHAR(SYSDATE, 'MONTH') CHARTEST FROM dual ;
CHARTEST
--------------
JUNE
SQL>SELECT TO_CHAR(SYSDATE) CHARTEST FROM dual ;
CHARTEST
--------------
00/06/10
TO_DATE
TO_DATEÇÔ¼ö´Â CHAR, VARCHAR2ÇüÀ» DATE ŸÀÔÀ¸·Î º¯È¯ÇÕ´Ï´Ù.
SQL>SELECT TO_DATE('2000/06/16','RRRR/MM/DD') FROM dual ;
TO_DATE
------------
2000/06/16
TO_NUMBER
TO_NUMBERÇÔ¼ö´Â CHAR, VARCHAR2ÀÇ µ¥ÀÌÅÍ Å¸ÀÔÀ» ¼ýÀÚÇü½ÄÀ¸·Î º¯È¯ÇÕ´Ï´Ù.
SQL>SELECT TO_NUMBER('1210616') FROM dual ;
TO_NUMBER
--------------
1210616
5. ±âŸÇÔ¼ö
NVL
NVL ÇÔ¼ö´Â NULL°ªÀ» ´Ù¸¥ °ªÀ¸·Î ¹Ù²Ü ¶§ ¾²ÀÔ´Ï´Ù.
¸ðµç µ¥ÀÌÅÍ Å¸ÀÔ¿¡ Àû¿ë °¡´ÉÇÕ´Ï´Ù.
ÀüȯµÇ´Â °ªÀÇ µ¥ÀÌÅÍ Å¸ÀÔÀ» ÀÏÄ¡½ÃÄÑ¾ß ÇÕ´Ï´Ù.
SQL>SELECT empno, NVL(comm, 0) FROM emp WHERE deptno = 30;
EMPNO NVL(COMM,0)
---------- -----------
7499 300
7521 500
7654 1400
7698 0
7844 0
7900 0
DECODE
DECODE ÇÔ¼ö´Â µ¥ÀÌÅÍ µéÀ» ´Ù¸¥ °ªÀ¸·Î ¹Ù²Ù¾î ÁÝ´Ï´Ù.
Çü½Ä DECODE(VALUE, IF1, THEN1, IF2, THEN2...)
VALUE °ªÀÌ IF1ÀÏ°æ¿ì¿¡ THEN1°ªÀ¸·Î ¹Ù²Ù¾î ÁÖ°í VALUE°ªÀÌ IF2ÀÏ°æ¿ì¿¡´Â THEN2°ªÀ¸·Î ¹Ù²Ù¾î ÁÝ´Ï´Ù.
SQL> SELECT deptno,
DECODE(deptno, 10 , 'ACCOUNTING' ,
20 , 'RESEARCH' ,
30 , 'SALES' ,
40 , 'OPERATIONS')
FROM emp ;
DEPTNO DECODE(DEP
---------- ----------
20 RESEARCH
30 SALES
30 SALES
20 RESEARCH
30 SALES
30 SALES
10 ACCOUNTING
20 RESEARCH
DUMP
DUMP´Â ¹ÙÀÌÆ® Å©±â¿Í ÇØ´ç µ¥ÀÌÅÍ Å¸ÀÔ Äڵ带 ¹ÝȯÇÕ´Ï´Ù..
SQL>SELECT ename, DUMP(ename, 16) "16Áø¼ö"
FROM emp
WHERE ename = 'ALLEN'
ename 16Áø¼ö
------ ------------------------------
ALLEN Typ=1 Len=5: 41,4c,4c,45,4e
GREATEST
GREATESTÇÔ¼ö´Â °Ë»ö°ª Áß¿¡¼ °¡Àå Å« °ªÀ» ¹Ýȯ ÇÕ´Ï´Ù.
SQL>SELECT GREATEST(10, 100, 5, -7) FROM DUAL;
GREATEST(10,100,5,-7)
---------------------
100
LEAST
LEASTÇÔ¼ö´Â GREATESTÇÔ¼ö¿Í ¹Ý´ë·Î °¡Àå ÀÛÀº °ªÀ» ¹ÝȯÇÕ´Ï´Ù.
SQL>SELECT LEAST(10, 100, 5, -7) FROM DUAL;
LEAST(10,100,5,-7)
------------------
-7
UID
ÇöÀç »ç¿ëÀÚÀÇ À¯ÀÏÇÑ ID¹øÈ£¸¦ ¸®ÅÏÇÕ´Ï´Ù.
USER
ÇöÀç ¿À¶óŬÀ» »ç¿ëÇÏ´Â »ç¿ëÀÚ¸¦ VARCHAR2Çü½ÄÀ¸·Î ¸®ÅÏÇÕ´Ï´Ù.
SQL> SELECT USER, UID FROM DUAL;
USER UID
------------- ------
SCOTT 32
USERENV
USERENV ÇÔ¼ö´Â ÇöÀç ¼¼¼ÇÀÇ È¯°æ Á¤º¸¸¦ ¹ÝȯÇÕ´Ï´Ù.
- ENTRYID : »ç¿ë °¡´ÉÇÑ Auditing entry Identifier¸¦ ¹ÝȯÇÕ´Ï´Ù.
- LABEL : ÇöÀç ¼¼¼ÇÀÇ LabelÀ» ¹ÝȯÇÕ´Ï´Ù.
- LANGUAGE : ÇöÀç ¼¼¼Ç¿¡¼ »ç¿ëÁßÀÎ ¾ð¾î¿Í Å׸®Å丮 °ªÀ» ¹ÝȯÇÕ´Ï´Ù.
- SESSIONID : Auditing(°¨»ç) Session ID¸¦ ¹Ýȯ ÇÕ´Ï´Ù.
- TERMINAL : ÇöÀç ¼¼¼Ç Å͹̳ÎÀÇ OS ID¸¦ ¹Ýȯ ÇÕ´Ï´Ù.
SQL> SELECT USERENV('LANGUAGE') FROM DUAL;
USERENV('LANGUAGE')
------------------------
KOREAN_KOREA.KO16KSC5601
VSIZE
ÇØ´ç ¹®ÀÚÀÇ BYTE¼ö¸¦ ¹Ýȯ ÇÕ´Ï´Ù. ÇØ´ç ¹®ÀÚ°¡ NULLÀ̸é NULL°ªÀÌ ¹Ýȯ µË´Ï´Ù.
SQL> SELECT VSIZE(ename), ename
FROM emp
WHERE deptno = 30;
VSIZE(ENAME) ENAME
------------ ----------
5 ALLEN
4 WARD
6 MARTIN
5 BLAKE
|
|