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
- Get data in random order with limit from table using mysql
- Difference between SQL and NoSQL databases
- Clear the terminal screen in MySQL within the Windows powershell
- 1553 Cannot drop index 'posts_user_id_foreign': needed in a foreign key constraint
- How to drop function in MySQL ?
- Drop foreign id column (user_id) in MySQL
- Create Employee table in MySQL
- Check constraint in MySQL
- Create Index in MySQL with example
- How to get a list of MySQL views?
- Get create table Query from existing table in phpMyAdmin
- Database connection using mySQLi with object-oriented
- Cannot drop index 'fk_role_id': needed in a foreign key constraint
- SQL query to delete all rows older than 30 days
- How to create view in MySQL database
- How to check column exists or not in table using MySQL
- How to retrieve data from two tables with one SQL statement
- Insert multiple rows in a single MySQL query
- How to get the list of all constraints in MySQL database
- Create column after a column in existing table using query in MySQL
- How to show database tables in mysql using command line
- ERROR 3780 (HY000): Referencing column 'order_id' and referenced column 'id' in foreign key constraint 'order_items_ibfk_1' are incompatible.
- SQL query to delete records older than 6 months
- How to create a new table from existing table in SQL
- Change existing MySQL table column id to autoincrement