REVERSE String Function in SQLThe REVERSE string function in SQL returns the string in the reverse order. It shows the last character of the string at the first position and the first character at the last position in the output of the query. Syntax of REVERSE String FunctionSyntax1: This syntax uses the REVERSE function with the column name of the SQL table: In the syntax, we have to specify the name of that column on which the REVERSE function is to be run. Syntax2: This syntax uses the REVERSE function with the string: Examples of REVERSE String functionExample 1: The following SELECT query reverses the given string: Output: 'TNIOPTAVAJ ' Example 2: The following SELECT query shows the given string in the reverse order: Output: 'AIDNI FO LATIPAC EHT SI IHLED WEN' Example 3: The following SELECT query shows the numeric string in the reverse way: Output: 524792244875 Example 4: This example uses the REVERSE function with the table in Structured Query Language. First, we have to create the new SQL table, which helps to understand the REVERSE string function. The syntax for creating the new table in the SQL database is as follows: The following CREATE statement creates the Employee_Grade table: The below INSERT queries insert the records of Employees with Grades and Remarks in the Employee_Grade table: The following SELECT statement displays the inserted records of the above Employee_Grade table:
Query 1: The following SELECT query uses the REVERSE function with the First_Name column of the above Employee_Grade table: This statement shows all the values of the first name in reverse order. Output:
Query 2: The following SELECT query uses the REVERSE function with the Last_Name column of the above Employee_Grade table: This statement shows all the values of the last name in reverse order. Output:
Query 3: The following SELECT query uses the REVERSE function with the First_City and New_City columns of the above Employee_Grade table: This SQL statement shows all the cities of First_City and New_City in the reverse order. Output:
Next TopicHow to Use ALL in SQL |