Pages

Sunday, August 25, 2013

Substring in Oracle SQL

The basic syntax for Sub-String in oracle sql is
"SUBSTR(string/column/field,start_position,length)"
and this function is available in all versions from Oracle DB 8i till Oracle DB 12 C (Oracle 12c)

If start_position is 0, then the SUBSTR function treats start_position as 1 (ie: the first position in the string).
If start_position is a positive number, then the SUBSTR function starts from the beginning of the string.
If start_position is a negative number, then the SUBSTR function starts from the end of the string and counts backwards.
If length is a negative number, then the SUBSTR function will return a NULL value.

Examples:
SUBSTR('This is a test', 6, 2)  return 'is'
SUBSTR('This is a test', 6)  return 'is a test'
SUBSTR('IntelBusi', 1, 5)  return 'Intel'
SUBSTR('IntelBusi', -4, 4)  return 'Busi'
SUBSTR('IntelBusi', -4, 3)  return 'Bus'




No comments:

Post a Comment