Functions functions can be categorized as follows

This preview shows page 28 - 34 out of 275 pages.

first and else clauses. FUNCTIONS Functions can be categorized as follows. Single row functions Group functions SINGLE ROW FUNCTIONS Single row functions can be categorized into five. These will be applied for each row and produces individual output for each row. 28
Image of page 28

Subscribe to view the full document.

Numeric functions String functions Date functions Miscellaneous functions Conversion functions NUMERIC FUNCTIONS Abs Sign Sqrt Mod Nvl Power Exp Ln Log Ceil Floor Round Trunk Bitand Greatest Least Coalesce a) ABS Absolute value is the measure of the magnitude of value. Absolute value is always a positive number. Syntax: abs ( value ) Ex: SQL> select abs(5), abs(-5), abs(0), abs(null) from dual; ABS(5) ABS(-5) ABS(0) ABS(NULL) ---------- ---------- ---------- ------------- 29
Image of page 29
5 -5 0 b) SIGN Sign gives the sign of a value. Syntax: sign ( value ) Ex: SQL> select sign(5), sign(-5), sign(0), sign(null) from dual; SIGN(5) SIGN(-5) SIGN(0) SIGN(NULL) ---------- ---------- ---------- -------------- 1 -1 0 c) SQRT This will give the square root of the given value. Syntax: sqrt ( value ) -- here value must be positive. Ex: SQL> select sqrt(4), sqrt(0), sqrt(null), sqrt(1) from dual; SQRT(4) SQRT(0) SQRT(NULL) SQRT(1) ---------- ---------- --------------- ---------- 2 0 1 d) MOD This will give the remainder. Syntax: mod ( value, divisor ) Ex: SQL> select mod(7,4), mod(1,5), mod(null,null), mod(0,0), mod(-7,4) from dual; 30
Image of page 30

Subscribe to view the full document.

MOD(7,4) MOD(1,5) MOD(NULL,NULL) MOD(0,0) MOD(-7,4) ------------ ---------- --------------------- ----------- ------------- 3 1 0 -3 e) NVL This will substitutes the specified value in the place of null values. Syntax: nvl ( null_col, replacement_value ) Ex: SQL> select * from student; -- here for 3 rd row marks value is null NO NAME MARKS --- ------- --------- 1 a 100 2 b 200 3 c SQL> select no, name, nvl(marks,300) from student; NO NAME NVL(MARKS,300) --- ------- --------------------- 1 a 100 2 b 200 3 c 300 SQL> select nvl(1,2), nvl(2,3), nvl(4,3), nvl(5,4) from dual; NVL(1,2) NVL(2,3) NVL(4,3) NVL(5,4) ---------- ---------- ---------- ---------- 1 2 4 5 SQL> select nvl(0,0), nvl(1,1), nvl(null,null), nvl(4,4) from dual; NVL(0,0) NVL(1,1) NVL(null,null) NVL(4,4) 31
Image of page 31
---------- ---------- ----------------- ---------- 0 1 4 f) POWER Power is the ability to raise a value to a given exponent. Syntax: power ( value, exponent ) Ex: SQL> select power(2,5), power(0,0), power(1,1), power(null,null), power(2,-5) from dual; POWER(2,5) POWER(0,0) POWER(1,1) POWER(NULL,NULL) POWER(2,-5) -------------- -------------- ----- --------- ----------------------- --------------- 32 1 1 .03125 g) EXP This will raise e value to the give power. Syntax: exp ( value ) Ex: SQL> select exp(1), exp(2), exp(0), exp(null), exp(-2) from dual; EXP(1) EXP(2) EXP(0) EXP(NULL) EXP(-2) -------- --------- -------- ------------- ---------- 2.71828183 7.3890561 1 .135335283 h) LN This is based on natural or base e logarithm. Syntax: ln ( value ) -- here value must be greater than zero which is positive only. Ex: 32
Image of page 32

Subscribe to view the full document.

SQL> select ln(1), ln(2), ln(null) from dual; LN(1) LN(2) LN(NULL) ------- ------- ------------ 0 .693147181 Ln and Exp are reciprocal to each other. EXP (3) = 20.0855369 LN (20.0855369) = 3 i) LOG This is based on 10 based logarithm. Syntax: log (10, value ) -- here value must be greater than zero which is positive only. Ex: SQL> select log(10,100), log(10,2), log(10,1), log(10,null) from dual; LOG(10,100) LOG(10,2) LOG(10,1) LOG(10,NULL) --------------- ----------- ------------ ----------------- 2 .301029996 0 LN (value) = LOG ( EXP (1), value) SQL> select ln(3), log(exp(1),3) from dual; LN(3) LOG(EXP(1),3) ------- ----------------- 1.09861229 1.09861229 j) CEIL This will produce a whole number that is greater than or equal to the specified value.
Image of page 33
Image of page 34
  • Spring '18

{[ snackBarMessage ]}

Get FREE access by uploading your study materials

Upload your study materials now and get free access to over 25 million documents.

Upload now for FREE access Or pay now for instant access
Christopher Reinemann
"Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

Ask a question for free

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern