Welcome to our comprehensive guide on SQL Database-Specific Functions! 🎉 In this tutorial, we'll explore various built-in functions that are indispensable for working with databases efficiently. Let's dive in!
Database-Specific Functions are predefined functions that are used to manipulate, extract, and analyze data in a database. They help us perform complex operations easily and provide more flexibility while querying data.
These functions make it simpler to perform operations like calculating averages, finding maximum or minimum values, handling dates, and converting data types. They help us write more efficient and readable SQL queries.
Let's start with some fundamental String Functions.
Combines two or more strings.
Example:
SELECT CONCAT('Hello', ' ', 'World');
-- Result: Hello WorldReturns the length of a string.
Example:
SELECT LENGTH('Hello');
-- Result: 5Converts all the characters in a string to lowercase or uppercase, respectively.
Example:
SELECT LOWER('Hello'), UPPER('hello');
-- Result: hello, HELLOReturns the specified number of characters from the left or right side of a string.
Example:
SELECT LEFT('Hello', 3), RIGHT('Hello', 3);
-- Result: Hell, loReturns the absolute value of a number.
Example:
SELECT ABS(-5);
-- Result: 5Returns the square root of a number.
Example:
SELECT SQRT(16);
-- Result: 4Returns the smallest and largest integers greater than or equal to the given number, respectively.
Example:
SELECT CEILING(3.14), FLOOR(3.14);
-- Result: 4, 3Returns the current date.
Example:
SELECT CURDATE();
-- Result: Your current dateFormats a date according to the specified format.
Example:
SELECT DATE_FORMAT(CURDATE(), '%d-%m-%Y');
-- Result: Your current date in DD-MM-YYYY formatQuiz: What function is used to convert all the characters in a string to lowercase?
A: CONCAT() B: LOWER() C: UPPER()
Correct: B Explanation: The LOWER() function converts all the characters in a string to lowercase.
Stay tuned for more SQL functions and their practical applications! 🎉💻