Download presentation
Presentation is loading. Please wait.
Published byDorthy Natalie Hawkins Modified over 8 years ago
1
Single Row Functions
2
3-2 Objectives Explain the various types of functions available in SQL. Explain the various types of functions available in SQL. Identify the basic concepts of using functions. Identify the basic concepts of using functions. Include a variety of character, number, and data functions in SELECT statements. Include a variety of character, number, and data functions in SELECT statements. Explain the conversion functions and how they might be used. Explain the conversion functions and how they might be used.
3
3-3 Overview of Functions in SQL Use functions to Perform calculations on data. Perform calculations on data. Modify individual data items. Modify individual data items. Manipulate output for groups of rows. Manipulate output for groups of rows. Alter date formats for display. Alter date formats for display. Convert column datatypes. Convert column datatypes.
4
3-4 Two Types of SQL Functions Single row functions Single row functions – Character – Number – Date – Conversion Multiple row functions Multiple row functions – Group SINGLEROW MULTIROW FUNCTION
5
3-5 Single Row Functions: Syntax Single row functions Manipulate data items. Manipulate data items. Accept arguments and return one value. Accept arguments and return one value. Act on each row returned. Act on each row returned. Return one result per row. Return one result per row. Modify the datatype. Modify the datatype. Can be nested. Can be nested.Syntax function_name (column|expression, [arg1, arg2,...])
6
3-6 Character Functions LOWERConverts to lowercase LOWERConverts to lowercase UPPERConverts to uppercase UPPERConverts to uppercase INITCAPConverts to initial capitalization INITCAPConverts to initial capitalization CONCATConcatenates values CONCATConcatenates values SUBSTRReturns substring SUBSTRReturns substring LENGTHReturns number of characters LENGTHReturns number of characters
7
3-7 Example Using Character Functions Display the fist name and last name of all employees with the last name of Patel. SELECT first_name, last_name FROM s_emp WHERE last_name = 'PATEL'; no rows returned SELECT first_name, last_name FROM s_emp WHERE last_name = 'PATEL'; no rows returned SELECT first_name, last_name FROM s_emp WHERE UPPER(last_name) = 'PATEL'; FIRST_NAME LAST_NAME -------------------- -------------------- Vikram Patel Radha Patel SELECT first_name, last_name FROM s_emp WHERE UPPER(last_name) = 'PATEL'; FIRST_NAME LAST_NAME -------------------- -------------------- Vikram Patel Radha Patel
8
3-8 Number Functions ROUNDRounds value to specified decimal ROUNDRounds value to specified decimal TRUNCTruncates value to specified decimal TRUNCTruncates value to specified decimal MODReturns remainder of division MODReturns remainder of division
9
3-9 Conversion Functions: Overview TO_CHAR converts a number or date string to a character string. TO_CHAR converts a number or date string to a character string. TO_NUMBER converts a character string containing digits to a number. TO_NUMBER converts a character string containing digits to a number. TO_DATE converts a character string of a date to a date value. TO_DATE converts a character string of a date to a date value. Conversion functions can use a format model composed of many elements. Conversion functions can use a format model composed of many elements.
10
3-10 Nesting Single Row Functions Single row functions can be nested to any level. Single row functions can be nested to any level. Nested functions are evaluated from deepest level to the least deep level. Nested functions are evaluated from deepest level to the least deep level. F3(F2(F1(col,arg1),arg2),arg3) Step 1 = Result 1 Step 2 = Result 2 Step 3 = Result 3
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.