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 Index in MySQL with example
- Self join in mysql employee manager example
- SQLSTATE[01000]: Warning: 1265 Data truncated for column 'visibility' at row 1
- Check constraint in MySQL
- How to show database tables in mysql using command line
- Change existing MySQL table column id to autoincrement
- Difference between SQL and NoSQL databases
- Get create table Query from existing table in phpMyAdmin
- MySQL create procedure example
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- Create column after a column in existing table using query in MySQL
- How to check the MySQL version
- How to Rename column name in MySql ?
- How to get yesterday's date in MySQL ?
- Database connection using mySQLi with object-oriented
- Get data in random order with limit from table using mysql
- Insert multiple rows in a single MySQL query
- How to get the list of all constraints in MySQL database
- How to create function in MySQL ?
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- SQL query to delete all rows older than 30 days
- Clear the terminal screen in MySQL within the Windows powershell
- How to check column exists or not in table using MySQL
- Drop foreign id column (user_id) in MySQL
- Get comma separated ids from table using MySQL