TRANSLATION
TRANSLATION in SQL is a function used to replace each character in a string that matches a character in the source set with the corresponding character in the replacement set. It returns the translated string with the replaced characters.
Example
SELECT TRANSLATE('12345', '143', 'ax') FROM DUAL;
Output
a2x5
Explanation
The TRANSLATE function in Oracle is used to replace a sequence of characters in a string with another set of characters. In the example provided, ‘143’ sequence is replaced by ‘ax’ in the string ‘12345’. The digit 1 is replaced with ‘a’, 4 is deleted as it does not have a replacement in the ‘ax’ string and 3 is replaced with ‘x’, giving the result ‘a2x5’.
Example
DECLARE @Example AS TABLE( ID INT, Code VARCHAR(10))
INSERT INTO @ExampleVALUES (1, 'C001'), (2, 'C002'), (3, 'C003')
DECLARE @Translation AS TABLE( Code VARCHAR(10), Description VARCHAR(50))
INSERT INTO @TranslationVALUES ('C001', 'Code One'), ('C002', 'Code Two'), ('C003', 'Code Three')
SELECT E.ID, T.DescriptionFROM @Example EJOIN @Translation T ON E.Code = T.Code
Output
ID |Description----------------1 |Code One2 |Code Two3 |Code Three
Explanation
In the example, two table variables @Example and @Translation were declared with sample data. The JOIN SQL command was used to match and retrieve the Code’s description from @Translation for each row in @Example. The results include the ID from @Example and the corresponding Description from @Translation.