MySQL Functions with examples
MySQL functions are built-in tools in MySQL that help you perform tasks on your data, such as calculations, string manipulation, or date management.
They make queries easier by processing data directly in the database.
What is a Function in MySQL?
- A function is a predefined set of SQL operations that returns a value.
- Used to perform calculations, manipulate strings, handle dates, etc.
- Functions return values; they can be used in SELECT, WHERE, and ORDER BY clauses.
Types of MySQL Functions
- String Functions
- Numeric Functions
- Date and Time Functions
- Aggregate Functions
- Control Flow Functions
Not a member yet? CLICK HERE to read the full article for free!!
- String Functions: These handle text or string data
CONCAT(): Combine two or more strings
SELECT CONCAT('Hi', ' ', 'There');
2. Numeric Functions: These work with numbers.
ROUND(): Rounds a number to a specified number of decimal places.
SELECT ROUND(15.789, 2);
3. Date and Time Functions: These work with dates and times.
NOW(): Returns the current date and time
SELECT NOW();
4. Aggregate functions: These perform calculations on a group of rows.
COUNT(): Counts the number of rows.
SELECT COUNT(*) Employees;
5. Control Flow Functions: Control flow functions help you make decisions in your SQL queries, similar to if-else statements in programming.
CASE
WHEN score >= 90 THEN 'A'
WHEN score >= 80 THEN 'B'
ELSE 'C'
END
Functions are used in SQL queries, often in the SELECT statement, to process or transform data. They save time and make data handling easier.
MySQL functions are built-in operations that can be used to manipulate data, perform calculations, or return specific results.
Here are some more stories you might like
- MySQL Triggers
- Cursor in MySQL
- MySQL Procedure
- From Coding to Communication, Why Soft Skills Matter in Tech
If you like my content, give me a few claps and follow for more!
Thanks for your time!
MySQL Functions with examples was originally published in Javarevisited on Medium, where people are continuing the conversation by highlighting and responding to this story.
This post first appeared on Read More