oracle

Friday, 21 April 2017

SQL: Substr() Function

Substr() function is used to substring the charater or letter.

Syntax:

Substr(source_string, Initial possition, length_of_string);

This consists on three things. First is source string.
Source string is the basic string, its data type is varchar, or somtime number.

2nd thing is the Initial possition. From where substr() function start substring the letter or source string.

3rd is the length of substring character.

Example:
Select substr('M Talha Zubair'3,5) from dual;

Result:
Talha


Scanrio 1:
If start possition is > source_string

then it return null  value.

Scanrio 2:
If Length of String > source_string

Then it result from start possition to last of source_string.

Scanrio 3:
If the function contain, any arithimatical operation, then its first evaluate it and then Give result from the answer of arithematical operation.

Example:

Select substr(50000-7,2,4) from dual;       // result of arithematic operation is 49993
result:
993

Example:

Select substr(sysdate,4,3) from dual;
Reslut:
Apr

No comments:

Post a Comment