SlideShare a Scribd company logo
STRUCTURED QUERY
LANGUAGE
FUNCTIONS IN MYSQL
FUNCTIONS IN MYSQL
There are two types of functions in MySQL:
Single Row Functions : Single row functions operate on a single value to
return a single value. They return only one result per row. They are further
categorized into:
Numeric functions
String functions Date
Time functions
Multiple Row Functions: Multiple row functions operate on a set of rows to
return a single value. Examples include SUM(), AVG() and COUNT().
TABLE: ITEM
Consider the table ITEM:
Itemno Name Price Quantity DOP
A001 Bread 20.25 10 2015-05-21
A002 Butter 50.75 6 2015-06-12
A003 Biscuits 10.32 20 2015-12-23
A004 Eggs 70.75 10 2015-09-18
A005 Chocolate 100.35 20 2015-10-19
NUMERIC FUNCIONS
Numeric functions perform operations on numeric values and return numeric values. There are
three numeric functions which are available:
POWER(X,Y) OR POW(X,Y): It returns the value of X raised to the power of Y.
COMMAND OUTPUT EXPLANATION
SELECT POW(2,3) ; 8 2 X 2 X 2 =8
SELECT POW(2, -2); 0.25 1/22 = ¼ = 0.25
SELECT POW(-2,2); 4 -2 X -2 = 4
SELECT POW (-2,3); -8 -2 X -2 X -2 = -8
SELECT ITEMNO,
POW(PRICE,2) FROM ITEM;
ROUND FUNCTION
 ROUND(X,D) function is used to round the value of argument X upto D decimal places.
 If number of decimal places is not specified or is zero, the number rounds to the nearest integer OR 0
decimal places.
 If negative value is specified for precision, it counts off that value left from the decimal point. If positive
value is specified for precision, it counts off that value right from the decimal point.
COMMAND RESULT EXPLNATION
SELECT ROUND(-4.45); -4 No. after decimal is less than 5
SELECT ROUND(-4.67); -5 No. after decimal is more than 5
SELECT ROUND(4.45); 4 No. after decimal is less than 5
SELECT ROUND(4.678,1); 4.7 No. at second place after decimal is more than 5
SELECT ROUND(4.678,0); 5 No. after decimal is more than 5
SELECT ROUND(56.345, -1); 60
SELECT ITEMNO, ROUND(PRICE) FROM
ITEM;
TRUNCATE FUNCTION
 TRUNCATE(X,D) or TRUNC(X,D) returns the number X, truncated to D decimal places.
 If D is 0, the result has no decimal point or fractional part.
 If D is negative, it causes D digits left of the decimal point of the value X to become zero.
COMMAND OUTPUT
SELECT TRUNC(5.678,0); 5
SELECT TRUNC(3.768,1); 3.7
SELECT TRUNC(-9.87,1); -9.8
SELECT TRUNC(345, -2); 300
SELECT ITEMNO,TRUNC(PRICE,1)
ITEM;
STRING(CHARACTER) FUNCTION
String functions operate on character type data. They return either character or numeric
values.
LENGTH(str): Returns the length of the string str.
COMMAND OUTPUT
SELECT LENGTH(“COMPUTER”); 8
SELECT LENGTH(“ I AM LEARNING”); 13
SELECT ITEMNO, LENGTH(NAME) FROM
ITEM;
CONCAT FUNCTION
CONCAT(str1, str2,...) : Returns the string that results from concatenating the arguments.
COMMAND OUTPUT
SELECT CONCAT(“My”,
“SQL”, “CLASS”);
MySQLCLASS
SELECT CONCAT(“My”,
“SQL”,NULL, “CLASS”);
NULL
SELECT CONCAT(ITEMNO,
NAME), PRICE FROM ITEM;
CONCAT(Itemno, Name)
A001Bread
A002Butter
A003Biscuits
A004Eggs
A005Chocolate
INSTR FUNCTION
INSTR(str, substr) : Returns the position of the first occurrence of substring substr in
string str
COMMAND RESUL
T
EXPLANATION
SELECT INSTR(“My SQL”,
“SQL);
4 First match found
at 4th position
SELECT INSTR(“My SQL”,
“SQR”);
0 No match found
SELECT INSTR(NAME,
“BREAD”) FROM ITEM;
INSTR(NAME,”BREAD
”)
1
0
0
0
0
LOWER FUNCTION
LOWER(str) or LCASE(str): Returns the string str in lowercase.
COMMAND RESULT
SELECT
LOWER(“INFORMATICS”)
informatics
SELECT LOWER(NAME)
FROM EMP;
LOWER(Name)
bread
butter
biscuits
eggs
chocolate
UPPER FUNCTION
UPPER(str) or UCASE(str): Returns the string str in lowercase.
COMMAND RESULT
SELECT
UPPER(“INforMAtiCS”);
INFORMATICS
SELECT UPPER(NAME)
FROM EMP;
UPPER(Name)
BREAD
BUTTER
BISCUITS
EGGS
CHOCOLATE
LEFT FUNCTION
LEFT(str, N) : Returns the N characters from the left side of the string str.
COMMAND RESULT
SELECT LEFT(“My SQL”, 2); My
SELECT LEFT(NAME, 3) FROM ITEM;
LEFT(Name, 3)
Bre
But
Bis
Egg
Cho
RIGHT FUNCTION
RIGHT(str, N) : Returns the N characters from the right side of the string str.
COMMAND RESULT
SELECT RIGHT(“My SQL”, 3); SQL
SELECT RIGHT(NAME, 3) FROM ITEM;
RIGHT(Name)
ead
ter
its
ggs
ate
LTRIM FUNCTION
LTRIM(str) : Returns the leading spaces ie from the left side of the string str.
COMMAND RESULT
SELECT LTRIM(“
INFORMATICS”);
INFORMATICS
SELECT LTRIM(NAME)
FROM EMP;
LTRIM(Name)
Bread
Butter
Biscuits
Eggs
Chocolate
RTRIM FUNCTION
RTRIM(str) : Removes the trailing spaces ie from the right side of the string str.
COMMAND RESULT
SELECT RTRIM(“INFORMATICS
”);
INFORMATICS
SELECT RTRIM(NAME) FROM
EMP;
RTRIM(Name)
Bread
Butter
Biscuits
Eggs
Chocolate
TRIM FUNCTION
TRIM(str) : Removes both leading and trailing spaces from the string str .
COMMAND OUTPUT
SELECT TRIM(“ INFORMATICS
PRACTICES ”);
INFORMATICS
SELECT TRIM(NAME) FROM EMP;
TRIM(Name)
Bread
Butter
Biscuits
Eggs
Chocolate
SUBSTRING/SUBSTR/MID FUNCTION
SUBSTRING(str, M,N) or MID(str, M,N): Returns the specified number of characters from
the middle of the string. There are 3 arguments.
 The first argument is the source string.
 The second argument is the position of first character to be displayed.
 The third argument is the number of characters to be displayed.
If the third argument is missing, then starting from the position specified, the rest of the
string is returned.
If the second argument is negative, then the beginning of the substring is M characters
from the end of the string.
SUBSTRING/SUBSTR/MID FUNCTION Contd…
COMMAND OUTPUT
SELECT SUBSTR(“WORLD OF COMPUTERS”, 4 ); or
SELECT SUBSTR(“WORLD OF COMPUTERS” FROM 4 );
LD OF COMPUTERS
SELECT SUBSTR(“WORLD OF COMPUTERS” , 3, 4 ); LD O
SELECT SUBSTR(“WORLD OF COMPUTERS”, -4 ); TERS
SELECT SUBSTR(“WORLD OF COMPUTERS”, -6,3 ); PUT
SELECT SUBSTR(“WORLD OF COMPUTERS” FROM -4
FOR 2 );
TE
SELECT SUBSTR(NAME,2,3) FROM ITEM;
SUBSTR(Nam
e,2,3)
rea
utt
isc
ggs
hoc
ASCII FUNCTION
ASCII(str): Returns the ASCII value of the leftmost character of the string str.
 Returns 0 if str is an empty string.
 Returns NULL if str is NULL.
COMMAND RESUL
T
EXPLANATION
SELECT ASCII(‘2’); 50 ASCII value of ‘0’ is 48, ‘1’ is 49 , ‘2’ is 50 and so on
SELECT ASCII(‘CG’); 67 ASCII value of ‘A’ is 65, ‘B’ is 66, ‘C’ is 67 and so on
SELECT ASCII(‘are’); 97 ASCII value of ‘a’ is 97, ‘b’ is 98 and so on
DATE AND TIME FUNCTION
COMMAND EXPLANATION EXAMPLE RESULT
CURDATE() Returns the current date in YYYY-
MM-DD format
SELECT CURDATE(); 2015-10-14
NOW() Returns the current date and time in
'YYYY-MM-DD HH:MM:SS'
SELECT NOW(); 2015-10-14 20:10:30
SYSDATE() Returns the current date and time in
'YYYY-MM-DD HH:MM:SS
SELECT SYSDATE(); 2015-10-14 20:10:30
DATE(exp) Extracts the date part of a date or
date time expression
SELECT DATE(‘2015-10-14
20:10:30’);
2015-10-14
MONTH(date) Returns the numeric month from the
date passed, in the range 0 to 12
SELECT MONTH(‘2015-10-
14’);
SELECT MONTH(DOP)
FROM ITEM;
10
DATE AND TIME FUNCTION Contd……
COMMAND EXPLANATION EXAMPLE RESULT
YEAR(date) Returns the year for date passed in
the range 0 to 9999
SELECT YEAR (‘2015-10-14’);
SELECT YEAR(DAP) FROM ITEM;
2015
DAYNAME(da
te)
returns the name of the weekday for
the date passed
SELECT DAYNAME(2015-10-14);
SELECT DAYNAME(DAP) FROM ITEM;
MONDAY
DAYOFMONT
H(date)
Returns the day of the month in the
range 0 to 31.
SELECT DAYOFMONTH(2015-10-14);
SELECT DAYOFMONTH(DAP) FROM
ITEM;
DAYOFWEEK(
date)
Returns the day of week in number
1 for Sunday, 2 for Monday and so
SELECT DAYOFWEEK(2015-10-14);
SELECT DAYOFWEEK(DAP) FROM
ITEM;
DAYOFYEAR(
ate)
Return the day of the year for the
given date in numeric format in the
range 1 to 366.
SELECT DAYOFYEAR(2015-10-14);
SELECT DAYOFYEAR(DAP) FROM ITEM;
SYSDATE() vs NOW()
SYSDATE() returns the time at which the function executes.
While NOW() which returns a constant time that indicates the
time at which the statement began to execute.

More Related Content

What's hot

Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
DataminingTools Inc
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
Krizia Capacio
 
Built-in Functions in SQL | Numeric Functions
Built-in Functions in SQL | Numeric FunctionsBuilt-in Functions in SQL | Numeric Functions
Built-in Functions in SQL | Numeric Functions
Raj vardhan
 
Sql insert statement
Sql insert statementSql insert statement
Sql insert statementVivek Singh
 
To excel or not?
To excel or not?To excel or not?
To excel or not?
Filippo Selden
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
mukesh24pandey
 
Sql functions
Sql functionsSql functions
Sql functions
G C Reddy Technologies
 
Alter table command
Alter table commandAlter table command
Alter table command
ravikhandelwal41
 
Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
Chhom Karath
 
Numeric functions in SQL | Oracle
Numeric functions in SQL | OracleNumeric functions in SQL | Oracle
Numeric functions in SQL | Oracle
Vimal Raj
 

What's hot (20)

Les09
Les09Les09
Les09
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Clauses
ClausesClauses
Clauses
 
Les11
Les11Les11
Les11
 
Select To Order By
Select  To  Order BySelect  To  Order By
Select To Order By
 
Les02
Les02Les02
Les02
 
Les01 Writing Basic Sql Statements
Les01 Writing Basic Sql StatementsLes01 Writing Basic Sql Statements
Les01 Writing Basic Sql Statements
 
Built-in Functions in SQL | Numeric Functions
Built-in Functions in SQL | Numeric FunctionsBuilt-in Functions in SQL | Numeric Functions
Built-in Functions in SQL | Numeric Functions
 
Sql insert statement
Sql insert statementSql insert statement
Sql insert statement
 
To excel or not?
To excel or not?To excel or not?
To excel or not?
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Aggregate Functions,Final
Aggregate Functions,FinalAggregate Functions,Final
Aggregate Functions,Final
 
Sql functions
Sql functionsSql functions
Sql functions
 
Alter table command
Alter table commandAlter table command
Alter table command
 
Les06 Subqueries
Les06 SubqueriesLes06 Subqueries
Les06 Subqueries
 
Les05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group FunctionLes05 Aggregating Data Using Group Function
Les05 Aggregating Data Using Group Function
 
Les12 creating views
Les12 creating viewsLes12 creating views
Les12 creating views
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
Interacting with Oracle Database
Interacting with Oracle DatabaseInteracting with Oracle Database
Interacting with Oracle Database
 
Numeric functions in SQL | Oracle
Numeric functions in SQL | OracleNumeric functions in SQL | Oracle
Numeric functions in SQL | Oracle
 

Viewers also liked

Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3Shaili Choudhary
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
Vineeta Garg
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
Vineeta Garg
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. PatilDiscrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
widespreadpromotion
 
Working with Cookies in NodeJS
Working with Cookies in NodeJSWorking with Cookies in NodeJS
Working with Cookies in NodeJS
Jay Dihenkar
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
Venkata.Manish Reddy
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Data Structure
Data StructureData Structure
Data Structuresheraz1
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
Vineeta Garg
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
faran nawaz
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
faran nawaz
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
Vineeta Garg
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion
 

Viewers also liked (20)

Advanced data structures using c++ 3
Advanced data structures using c++ 3Advanced data structures using c++ 3
Advanced data structures using c++ 3
 
Classes and objects1
Classes and objects1Classes and objects1
Classes and objects1
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil13. Indexing MTrees - Data Structures using C++ by Varsha Patil
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
 
Pp
PpPp
Pp
 
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. PatilDiscrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
 
Working with Cookies in NodeJS
Working with Cookies in NodeJSWorking with Cookies in NodeJS
Working with Cookies in NodeJS
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
 
C++ data types
C++ data typesC++ data types
C++ data types
 
Data Structure
Data StructureData Structure
Data Structure
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
stacks in algorithems and data structure
stacks in algorithems and data structurestacks in algorithems and data structure
stacks in algorithems and data structure
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
 

Similar to Structured query language functions

V34 numeric function-c
V34  numeric function-cV34  numeric function-c
V34 numeric function-c
Dhirendra Chauhan
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERT
Harish Gyanani
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
Mohan Kumar.R
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10Syed Asrarali
 
Database Query Using SQL_ip.docx
Database Query Using SQL_ip.docxDatabase Query Using SQL_ip.docx
Database Query Using SQL_ip.docx
VandanaGoyal21
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
Osama Al-Mohaia
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functionsVivek Singh
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
Soumyajit Dutta
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
kirthika jeyenth
 
MYSQL Aggregate Functions
MYSQL Aggregate FunctionsMYSQL Aggregate Functions
MYSQL Aggregate Functions
Leroy Blair
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
ArjayBalberan1
 
Oracle sql ppt2
Oracle sql ppt2Oracle sql ppt2
Oracle sql ppt2
Madhavendra Dutt
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
Mahyuddin8
 
Java script
Java scriptJava script
Java script
Shagufta shaheen
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEUnit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
DrkhanchanaR
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
Sankhya_Analytics
 
Parameters
ParametersParameters
Parameters
James Brotsos
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
moduledesign
 
Foxpro (1)
Foxpro (1)Foxpro (1)
Foxpro (1)
piyushrajsinha
 
MySQL 5.7 String Functions
MySQL 5.7 String FunctionsMySQL 5.7 String Functions
MySQL 5.7 String Functions
Francesco Marino
 

Similar to Structured query language functions (20)

V34 numeric function-c
V34  numeric function-cV34  numeric function-c
V34 numeric function-c
 
Mysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERTMysql Functions with examples CBSE INDIA 11th class NCERT
Mysql Functions with examples CBSE INDIA 11th class NCERT
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
 
Intro to tsql unit 10
Intro to tsql   unit 10Intro to tsql   unit 10
Intro to tsql unit 10
 
Database Query Using SQL_ip.docx
Database Query Using SQL_ip.docxDatabase Query Using SQL_ip.docx
Database Query Using SQL_ip.docx
 
Class program and uml in c++
Class program and uml in c++Class program and uml in c++
Class program and uml in c++
 
Oracle sql functions
Oracle sql functionsOracle sql functions
Oracle sql functions
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Unit 3 arrays and_string
Unit 3 arrays and_stringUnit 3 arrays and_string
Unit 3 arrays and_string
 
MYSQL Aggregate Functions
MYSQL Aggregate FunctionsMYSQL Aggregate Functions
MYSQL Aggregate Functions
 
ADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptxADV Powepoint 3 Lec.pptx
ADV Powepoint 3 Lec.pptx
 
Oracle sql ppt2
Oracle sql ppt2Oracle sql ppt2
Oracle sql ppt2
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
 
Java script
Java scriptJava script
Java script
 
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLEUnit 3 - Function & Grouping,Joins and Set Operations in ORACLE
Unit 3 - Function & Grouping,Joins and Set Operations in ORACLE
 
Basic Analysis using Python
Basic Analysis using PythonBasic Analysis using Python
Basic Analysis using Python
 
Parameters
ParametersParameters
Parameters
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
 
Foxpro (1)
Foxpro (1)Foxpro (1)
Foxpro (1)
 
MySQL 5.7 String Functions
MySQL 5.7 String FunctionsMySQL 5.7 String Functions
MySQL 5.7 String Functions
 

Recently uploaded

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Structured query language functions

  • 2. FUNCTIONS IN MYSQL There are two types of functions in MySQL: Single Row Functions : Single row functions operate on a single value to return a single value. They return only one result per row. They are further categorized into: Numeric functions String functions Date Time functions Multiple Row Functions: Multiple row functions operate on a set of rows to return a single value. Examples include SUM(), AVG() and COUNT().
  • 3. TABLE: ITEM Consider the table ITEM: Itemno Name Price Quantity DOP A001 Bread 20.25 10 2015-05-21 A002 Butter 50.75 6 2015-06-12 A003 Biscuits 10.32 20 2015-12-23 A004 Eggs 70.75 10 2015-09-18 A005 Chocolate 100.35 20 2015-10-19
  • 4. NUMERIC FUNCIONS Numeric functions perform operations on numeric values and return numeric values. There are three numeric functions which are available: POWER(X,Y) OR POW(X,Y): It returns the value of X raised to the power of Y. COMMAND OUTPUT EXPLANATION SELECT POW(2,3) ; 8 2 X 2 X 2 =8 SELECT POW(2, -2); 0.25 1/22 = ¼ = 0.25 SELECT POW(-2,2); 4 -2 X -2 = 4 SELECT POW (-2,3); -8 -2 X -2 X -2 = -8 SELECT ITEMNO, POW(PRICE,2) FROM ITEM;
  • 5. ROUND FUNCTION  ROUND(X,D) function is used to round the value of argument X upto D decimal places.  If number of decimal places is not specified or is zero, the number rounds to the nearest integer OR 0 decimal places.  If negative value is specified for precision, it counts off that value left from the decimal point. If positive value is specified for precision, it counts off that value right from the decimal point. COMMAND RESULT EXPLNATION SELECT ROUND(-4.45); -4 No. after decimal is less than 5 SELECT ROUND(-4.67); -5 No. after decimal is more than 5 SELECT ROUND(4.45); 4 No. after decimal is less than 5 SELECT ROUND(4.678,1); 4.7 No. at second place after decimal is more than 5 SELECT ROUND(4.678,0); 5 No. after decimal is more than 5 SELECT ROUND(56.345, -1); 60 SELECT ITEMNO, ROUND(PRICE) FROM ITEM;
  • 6. TRUNCATE FUNCTION  TRUNCATE(X,D) or TRUNC(X,D) returns the number X, truncated to D decimal places.  If D is 0, the result has no decimal point or fractional part.  If D is negative, it causes D digits left of the decimal point of the value X to become zero. COMMAND OUTPUT SELECT TRUNC(5.678,0); 5 SELECT TRUNC(3.768,1); 3.7 SELECT TRUNC(-9.87,1); -9.8 SELECT TRUNC(345, -2); 300 SELECT ITEMNO,TRUNC(PRICE,1) ITEM;
  • 7. STRING(CHARACTER) FUNCTION String functions operate on character type data. They return either character or numeric values. LENGTH(str): Returns the length of the string str. COMMAND OUTPUT SELECT LENGTH(“COMPUTER”); 8 SELECT LENGTH(“ I AM LEARNING”); 13 SELECT ITEMNO, LENGTH(NAME) FROM ITEM;
  • 8. CONCAT FUNCTION CONCAT(str1, str2,...) : Returns the string that results from concatenating the arguments. COMMAND OUTPUT SELECT CONCAT(“My”, “SQL”, “CLASS”); MySQLCLASS SELECT CONCAT(“My”, “SQL”,NULL, “CLASS”); NULL SELECT CONCAT(ITEMNO, NAME), PRICE FROM ITEM; CONCAT(Itemno, Name) A001Bread A002Butter A003Biscuits A004Eggs A005Chocolate
  • 9. INSTR FUNCTION INSTR(str, substr) : Returns the position of the first occurrence of substring substr in string str COMMAND RESUL T EXPLANATION SELECT INSTR(“My SQL”, “SQL); 4 First match found at 4th position SELECT INSTR(“My SQL”, “SQR”); 0 No match found SELECT INSTR(NAME, “BREAD”) FROM ITEM; INSTR(NAME,”BREAD ”) 1 0 0 0 0
  • 10. LOWER FUNCTION LOWER(str) or LCASE(str): Returns the string str in lowercase. COMMAND RESULT SELECT LOWER(“INFORMATICS”) informatics SELECT LOWER(NAME) FROM EMP; LOWER(Name) bread butter biscuits eggs chocolate
  • 11. UPPER FUNCTION UPPER(str) or UCASE(str): Returns the string str in lowercase. COMMAND RESULT SELECT UPPER(“INforMAtiCS”); INFORMATICS SELECT UPPER(NAME) FROM EMP; UPPER(Name) BREAD BUTTER BISCUITS EGGS CHOCOLATE
  • 12. LEFT FUNCTION LEFT(str, N) : Returns the N characters from the left side of the string str. COMMAND RESULT SELECT LEFT(“My SQL”, 2); My SELECT LEFT(NAME, 3) FROM ITEM; LEFT(Name, 3) Bre But Bis Egg Cho
  • 13. RIGHT FUNCTION RIGHT(str, N) : Returns the N characters from the right side of the string str. COMMAND RESULT SELECT RIGHT(“My SQL”, 3); SQL SELECT RIGHT(NAME, 3) FROM ITEM; RIGHT(Name) ead ter its ggs ate
  • 14. LTRIM FUNCTION LTRIM(str) : Returns the leading spaces ie from the left side of the string str. COMMAND RESULT SELECT LTRIM(“ INFORMATICS”); INFORMATICS SELECT LTRIM(NAME) FROM EMP; LTRIM(Name) Bread Butter Biscuits Eggs Chocolate
  • 15. RTRIM FUNCTION RTRIM(str) : Removes the trailing spaces ie from the right side of the string str. COMMAND RESULT SELECT RTRIM(“INFORMATICS ”); INFORMATICS SELECT RTRIM(NAME) FROM EMP; RTRIM(Name) Bread Butter Biscuits Eggs Chocolate
  • 16. TRIM FUNCTION TRIM(str) : Removes both leading and trailing spaces from the string str . COMMAND OUTPUT SELECT TRIM(“ INFORMATICS PRACTICES ”); INFORMATICS SELECT TRIM(NAME) FROM EMP; TRIM(Name) Bread Butter Biscuits Eggs Chocolate
  • 17. SUBSTRING/SUBSTR/MID FUNCTION SUBSTRING(str, M,N) or MID(str, M,N): Returns the specified number of characters from the middle of the string. There are 3 arguments.  The first argument is the source string.  The second argument is the position of first character to be displayed.  The third argument is the number of characters to be displayed. If the third argument is missing, then starting from the position specified, the rest of the string is returned. If the second argument is negative, then the beginning of the substring is M characters from the end of the string.
  • 18. SUBSTRING/SUBSTR/MID FUNCTION Contd… COMMAND OUTPUT SELECT SUBSTR(“WORLD OF COMPUTERS”, 4 ); or SELECT SUBSTR(“WORLD OF COMPUTERS” FROM 4 ); LD OF COMPUTERS SELECT SUBSTR(“WORLD OF COMPUTERS” , 3, 4 ); LD O SELECT SUBSTR(“WORLD OF COMPUTERS”, -4 ); TERS SELECT SUBSTR(“WORLD OF COMPUTERS”, -6,3 ); PUT SELECT SUBSTR(“WORLD OF COMPUTERS” FROM -4 FOR 2 ); TE SELECT SUBSTR(NAME,2,3) FROM ITEM; SUBSTR(Nam e,2,3) rea utt isc ggs hoc
  • 19. ASCII FUNCTION ASCII(str): Returns the ASCII value of the leftmost character of the string str.  Returns 0 if str is an empty string.  Returns NULL if str is NULL. COMMAND RESUL T EXPLANATION SELECT ASCII(‘2’); 50 ASCII value of ‘0’ is 48, ‘1’ is 49 , ‘2’ is 50 and so on SELECT ASCII(‘CG’); 67 ASCII value of ‘A’ is 65, ‘B’ is 66, ‘C’ is 67 and so on SELECT ASCII(‘are’); 97 ASCII value of ‘a’ is 97, ‘b’ is 98 and so on
  • 20. DATE AND TIME FUNCTION COMMAND EXPLANATION EXAMPLE RESULT CURDATE() Returns the current date in YYYY- MM-DD format SELECT CURDATE(); 2015-10-14 NOW() Returns the current date and time in 'YYYY-MM-DD HH:MM:SS' SELECT NOW(); 2015-10-14 20:10:30 SYSDATE() Returns the current date and time in 'YYYY-MM-DD HH:MM:SS SELECT SYSDATE(); 2015-10-14 20:10:30 DATE(exp) Extracts the date part of a date or date time expression SELECT DATE(‘2015-10-14 20:10:30’); 2015-10-14 MONTH(date) Returns the numeric month from the date passed, in the range 0 to 12 SELECT MONTH(‘2015-10- 14’); SELECT MONTH(DOP) FROM ITEM; 10
  • 21. DATE AND TIME FUNCTION Contd…… COMMAND EXPLANATION EXAMPLE RESULT YEAR(date) Returns the year for date passed in the range 0 to 9999 SELECT YEAR (‘2015-10-14’); SELECT YEAR(DAP) FROM ITEM; 2015 DAYNAME(da te) returns the name of the weekday for the date passed SELECT DAYNAME(2015-10-14); SELECT DAYNAME(DAP) FROM ITEM; MONDAY DAYOFMONT H(date) Returns the day of the month in the range 0 to 31. SELECT DAYOFMONTH(2015-10-14); SELECT DAYOFMONTH(DAP) FROM ITEM; DAYOFWEEK( date) Returns the day of week in number 1 for Sunday, 2 for Monday and so SELECT DAYOFWEEK(2015-10-14); SELECT DAYOFWEEK(DAP) FROM ITEM; DAYOFYEAR( ate) Return the day of the year for the given date in numeric format in the range 1 to 366. SELECT DAYOFYEAR(2015-10-14); SELECT DAYOFYEAR(DAP) FROM ITEM;
  • 22. SYSDATE() vs NOW() SYSDATE() returns the time at which the function executes. While NOW() which returns a constant time that indicates the time at which the statement began to execute.