RIGHT
RIGHT(str, len)
Section titled “RIGHT(str, len)”- str: The string from which the rightmost characters will be extracted.
- len: The number of characters to extract from the end (right side) of the string.
Example
Section titled “Example”SELECT RIGHT('SQL Documentation', 5) AS 'Right Output';Output
Section titled “Output”+--------------+| Right Output |+--------------+| ation |+--------------+Explanation
Section titled “Explanation”In this example, the RIGHT() function is used to extract the specified number of characters from the end of the provided string. The string ‘SQL Documentation’ is provided, and the function is asked to return the last 5 characters - ‘ation’.
RIGHT(string text, n integer)
Section titled “RIGHT(string text, n integer)”- string text: This is the source string from which characters are to be extracted. It can be any text, character varying, or character type.
- n integer: This is the number of characters to be extracted from the end of the source string text. It should be of type integer and if n is less than 1, the result is an empty string. If n exceeds the length of string text, all of the string text is returned.
Example
Section titled “Example”SELECT RIGHT('PostgreSQL', 3);Output
Section titled “Output”"SQL"Explanation
Section titled “Explanation”The RIGHT function in PostgreSQL returns the last n characters from a string. In the provided example, it returned the last three characters from the string ‘PostgreSQL’, which are ‘SQL’.
RIGHT( character_expression , integer_expression )
Section titled “RIGHT( character_expression , integer_expression )”- character_expression: The string of characters from which the rightmost characters are returned. Can be a literal string, variable, or column of either character or binary data.
- integer_expression: A positive integer that specifies how many rightmost characters of the character_expression will be returned. If negative, an error is returned. If zero, an empty string is returned.
Example
Section titled “Example”SELECT RIGHT('SQL Server', 6) AS Result;Output
Section titled “Output”Result------ServerExplanation
Section titled “Explanation”The RIGHT function in SQL Server extracts a specified number of characters from a string, starting from the rightmost character. In this example, it returns the last 6 characters from the string ‘SQL Server’, which is ‘Server’.
RIGHT(text, number)
Section titled “RIGHT(text, number)”- text: The string from which the rightmost characters will be extracted.
- number: Specifies the number of characters to extract from the right side of the text string.
Example
Section titled “Example”SELECT RIGHT('Hello World', 5) FROM dual;Output
Section titled “Output”WorldExplanation
Section titled “Explanation”The RIGHT function is used to extract a specific number of characters from the right side of a string. In this example, 5 characters are extracted from the right side of the string ‘Hello World’. The output is ‘World’.