Thursday, October 18, 2007

Single Row Function In SQL SERVER

Objectives
After completing this lesson, you should be able to do the following:
• Describe various types of functions available in SQL
• Use character, number, and date functions in SELECT statements
• Describe the use of conversion functions.


SQL Functions


Two Types of SQL Functions



Single-Row Functions

Single row functions:
• Manipulate data items
• Accept arguments and return one value
• Act on each row returned
• Return one result per row
• May modify the data type
• Can be nested
• Accept arguments which can be a column or an expression.

Character Functions

Case Manipulation Functions
These functions convert case for character strings.

Using Case Manipulation Functions
Display the employee number, name, and department number for employee Higgins:

Character-Manipulation Functions
These functions manipulate character strings:


Using the Character-Manipulation
Functions


Number Functions

• ROUND: Rounds value to specified decimal
• TRUNC: Truncates value to specified decimal
• MOD: Returns remainder of division


Using the ROUND Function
DUAL is a dummy table you can use to view results from functions and calculations.

Using the TRUNC Function

Using the MOD Function

Calculate the remainder of a salary after it is divided by 5000 for all employees whose job title is sales representative.


Working with Dates

• Oracle database stores dates in an internal numeric format: century, year, month, day, hours,
minutes, seconds.
• The default date display format is DD-MON-RR.
– Allows you to store 21st century dates in the 20th century by specifying only the last two digits of the year.
– Allowa you to store 20th century dates in the 21st century in the same way.

SYSDATE is a function that returns:
• Date
• Time

Arithmetic with Dates
• Add or subtract a number to or from a date for a resultant date value.
• Subtract two dates to find the number of days between those dates.
• Add hours to a date by dividing the number of hours by 24.

Using Arithmetic Operators with Dates

Date Functions


1 comment:

Unknown said...

excellent piece of information, I had come to know about your website from my friend kishori, pune,i have read atleast 7 posts of yours by now, and let me tell you, your site gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a lot once again, Regards, Single Row Function in sql