Oracle SUBSTR equivalents for MID, LEFT and RIGHT

Posted on 2012/01/18

1


Oracle doesn’t have some of the handy short-hand functions that Microsoft has embedded into it’s VB programming languages and into SQL Server but, of course, provides a similar way to return the same result.

The key, is Oracle’s SUBSTR() function!

In Microsoft’s SQL Server, and in VB, you have the following:

MID(YourStringHere, StartFrom, NumCharsToGrab)
MID(“birthday”,1,5) = “birth”
MID(“birthday”,5,2) = “hd”

LEFT(YourStringHere,NumCharsToGrab)
LEFT(“birthday”,5) = “birth”
LEFT(“birthday”,1) = “b”

RIGHT(YourStringHere,NumCharsToGrab)
RIGHT(“birthday”,3) = “day”
RIGHT(“birthday”,1) = “y”

Oracle’s SUBSTR function works much the same as the MID function:

SUBSTR(YourStringHere,StartFrom,NumCharsToGrab)
SUBSTR(“birthday”,1,2) = “bi”
SUBSTR(“birthday”,-2,2) = “ay”    the -2 indicates started from the end of the word

 

Tagged: , , ,