RIGHT Function in SQLThe RIGHT string function retrieves the characters to the given index value from the right side of the original string in the Structured Query Language. Syntax of RIGHT String FunctionSyntax1: This syntax uses the RIGHT function with the column name of the SQL table: In the syntax, we have to specify the name of that column on which we want to perform the RIGHT string function. Syntax3: This syntax uses the RIGHT function with the string: Examples of RIGHT String functionExample 1: The following SELECT query shows the four characters from the right side of the specified word: Output:
Example 2: The following SELECT query shows the right 20 characters from the given string: Output:
Example 3: The following SELECT query shows the right 16 characters from the given sentence: Output:
Example 4: The following SELECT query shows the 5 characters from the right of the given string: Output: 45### Example 5: The following SELECT query shows the 100 characters from the right of the specified string: Output:
Example 6: This example uses the RIGHT function with the table in Structured Query Language. To understand the RIGHT function with SQL, we have to create the SQL table first using CREATE statement. The syntax for creating the new table in the SQL database is as follows: The following CREATE statement creates the Worker_Info table: The below INSERT queries insert the records of college Faculties in the Worker_Info table: The following SELECT statement displays the inserted records of the above Worker_Info table:
Query 1: The following SELECT query uses the RIGHT function with the Worker_First_Name column of the above Worker_Info table: This SQL statement shows the last three characters of the First name of each worker. Output:
Query 2: The following SELECT query uses the RIGHT function with the Worker_Last_Name column of the above Worker_Info table: This SQL statement shows the last three characters of the Last name of each worker. Output:
Query 3: The following SELECT query uses the RIGHT function with the Worker_Address column of the above Worker_Info table: This SQL statement shows the four characters from the right of the address of each worker. Output:
Query 4: The following SELECT query uses the RIGHT function with the Worker_City column of the above Worker_Info table: This SQL statement shows the last character of the city of each worker. Output:
Next TopicSTRCMP Function in SQL |