Get full name of a person in SQL using function

Created at 22-Feb-2024 , By samar

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) 
   declare fullName varchar(255);
   set fullName = CONCAT('Hello ', firstName , ' ', lastName );
   return fullName;
end //

chanage the delimiter

delimiter ;

Call the function

select getFullName('samarjeet', 'kumar') ;


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.

Buy Me A Coffee

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.