RIGHT() function fetches a number of characters from a string, starting from right. How many characters will be fetched ? It is determined by second parameter i.e length.
It will return NULL, if any of the argument is NULL.
If length parameter has more than the number of characters in string, then string will be returned.
[table caption=”” width=”100%” colwidth=”15%|30%|55%” colalign=”left|left|left”]
Name, Required /Optional, Description
string, Required, it is a valid input string.
length, Required, it specifies the length of characters to be fetched.
[/table]
[table caption=”” width=”100%” colwidth=”20%|80%” colalign=”left|left”]
Return, Description
String, returns the leftmost length characters from the string.
NULL, if any argument is NULL.
[/table]
[table caption=”” width=”100%” colwidth=”25%|75%” colalign=”left|left”]
Version, MySQL 4.0
[/table]
It will return NULL, if any of the argument is NULL. Lets see the below example when length, second argument is NULL.
mysql> SELECT RIGHT('tutorialmines',NULL); +-----------------------------+ | RIGHT('tutorialmines',NULL) | +-----------------------------+ | NULL | +-----------------------------+ 1 row in set (0.03 sec)
Lets see the below example, when string, first argument is NULL.
mysql> SELECT RIGHT(NULL,5); +---------------+ | RIGHT(NULL,5) | +---------------+ | NULL | +---------------+ 1 row in set (0.05 sec)
Lets see the below example. I will select 8 characters from the right of string.
mysql> SELECT RIGHT('tutorialmines',8); +--------------------------+ | RIGHT('tutorialmines',8) | +--------------------------+ | ialmines | +--------------------------+ 1 row in set (0.00 sec)
Lets see the below example. Full string is returned in it.
mysql> SELECT RIGHT('tutorialmines',28); +---------------------------+ | RIGHT('tutorialmines',28) | +---------------------------+ | tutorialmines | +---------------------------+ 1 row in set (0.00 sec))
Lets see the below example of how it works within a database query:
mysql> Select Name as original, RIGHT(Name,3) as Changed FROM tbl_employee LIMIT 5; +------------+---------+ | original | Changed | +------------+---------+ | Jyoti Rani | ani | | Polla | lla | | Arnav | nav | | Jeevesh | esh | | Tom | Tom | +------------+---------+ 5 rows in set (0.01 sec)
See all MySQL String functions MySQL 8 String Functions.
When it comes to children, there’s one universal truth: the right toy can spark imagination, build skills, and make memories…
In today’s digital age, where screens and gadgets dominate our children’s lives, there’s something heartwarming about a well-loved plush toy…
In a world dominated by screens and fast-paced routines, it’s easy to forget the simple magic of a toy in…
In the heart of Delhi’s vibrant streets lies a world where imagination meets innovation — the magical universe of toys.…
When was the last time a toy truly amazed you—not just as a product, but as a thoughtful tool for…
In the digital age, the way we experience childhood has changed, but the essence remains the same—imagination, exploration, and joy.…