General Functions in SQL

What are the general functions available in SQL?

Questions by sprajarajan   answers by sprajarajan

Showing Answers 1 - 6 of 6 Answers

Aggregate Functions:
AVG() - Returns the average value 
COUNT() - Returns the number of rows
FIRST() - Returns the first value
LAST() - Returns the last value
MAX() - Returns the largest value
MIN() - Returns the smallest value
SUM() - Returns the sum

Scalar Functions
UCASE() - Converts a field to upper case

LCASE() - Converts a field to lower case
MID() - Extract characters from a text field
LEN() - Returns the length of a text field
ROUND() - Rounds a numeric field to the number of decimals specified
NOW() - Returns the current system date and time
FORMAT() - Formats how a field is to be displayed


  Was this answer useful?  Yes

aghiad

  • Sep 10th, 2011
 

The General function are use in SQL
1-NVL (exp1,exp2)
2-NVL2 (exp1,exp2,exp3)
3-NULLIF (exp1,exp2)
4-COALESCE (exp1,exp2,exp3,......,expn)
For example:

Code
  1. SELECT last_name, salary, commission_pct,

  2. salary*NVL (commission_pct,0.10) Comm

  3. FROM employees

As you see in example above, we use NVL (dont forget that NVL takes in 2 arguments) so we put in it commission_pct,0.10
NOTE : Comm is the alias of the code NVL(commission,0.10)
Example 2 :
Code
  1. SELECT last_name, salary, commission_pct,

  2. nvl2(commission_pct,salary*commission_pct,salary)

  3. FROM employees

Example 3 :
Code
  1. SELECT first_name,length(first_name)"expr1",

  2. last_name, LENGTH(last_name) "expr2",

  3. NULLIF (LENGTH(first_name),LENGTH(last_name))result

  4. FROM employees

Example 4 :
Code
  1. SELCT first_name,manager_id

  2. ser_id,commission_pct,coalesce(manager_id,commission_pct,-1)

  3. FROM employees

I hope you got the point ^_^

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions