
Get full name of a person in SQL using function
To get the full name of a person in SQL, you typically need to concatenate the first name and last name (or any other name components) using the CONCAT function in MySQL user defined function.
Here's an user defined function in MySQL to get the fullname of user using their first name and last name.
Open terminal and Login to mysql server using mysql -u root -p
command and choose the database and execute the below SQL statement.
change the delimiter
delimiter //
Create function getFullName
create function getFullName(firstName varchar(255), lastName varchar(255))
returns varchar(255)
deterministic
begin
declare fullName varchar(255);
set fullName = CONCAT('Hello ', firstName , ' ', lastName );
return fullName;
end //
chanage the delimiter
delimiter ;
Call the function
select getFullName('samarjeet', 'kumar') ;
Output
mysql> select getFullName('samarjeet', 'kumar') // +-----------------------------------+ | getFullName('samarjeet', 'kumar') | +-----------------------------------+ | Hello samarjeet kumar | +-----------------------------------+ 1 row in set (0.00 sec)
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Sql
- Create column after a column in existing table using query in MySQL
- SQL query to delete records older than 6 months
- Difference between SQL and NoSQL databases
- Clear the terminal screen in MySQL within the Windows powershell
- How to get a list of MySQL views?
- MySQL create procedure example
- Self join in mysql employee manager example
- How to check the MySQL version
- Create Index in MySQL with example
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- How to Rename column name in MySql ?
- How to create view in MySQL database
- How to show database tables in mysql using command line
- How to create a new table from existing table in SQL
- Check constraint in MySQL
- Insert multiple rows in a single MySQL query
- Get number of connections being used by a specific user in MySQL
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- How to get yesterday's date in MySQL ?
- How to get the list of all constraints in MySQL database
- Drop foreign id column (user_id) in MySQL
- Create Employee table in MySQL
- Get create table Query from existing table in phpMyAdmin
- How to check column exists or not in table using MySQL