What is difference between SUBSTR and INSTR?

SUBSTR returns a specified portion of a string eg SUBSTR('BCDEF',4) output BCDE
INSTR provides character position in which a pattern is found in a string. eg INSTR('ABC-DC-F','-',2) output 7 (2nd occurence of '-')

Showing Answers 1 - 18 of 18 Answers

thumatinagaraju

  • Nov 2nd, 2006
 

hisubstr i s used to select pirticular word frm stringsuppose select substr('nagaraju',1,3) from dual ;returns nag means 1 is start position of word and 3 is end ,,,ok instr returns only position of first occureence of a specified characterselect instr('nagaraju','a') from dual ;returns 2 only ;;ok i hope usatisfied with my answers

  Was this answer useful?  Yes

Rohan Deshpande

  • Jan 29th, 2007
 

SUBSTR: it extracts the string of determined length.whereras (i.e. it returns character for specified position)INSTR:it returns the number of named string.(i.e. it returns number )

  Was this answer useful?  Yes

i.v.praveen

  • Apr 5th, 2007
 

SUBSTR returns a character where as INSTR returns number

  Was this answer useful?  Yes

syam sundar

  • Aug 18th, 2007
 

substr:
sub(string,n,m): It returns the characters from nth position, m
characters long
Ex:-substr(abcdefgh,3,3) it returns cde

instr:

instr(string,n,m):It returns the position of the nth character of the mth
occurrence.
Ex:-instr(abcadea,1,3) it returns 7

hi Buddy,
  

Substr only give the sub part of the string
Substr(String,'start postion','length')
Substr('ABCDEFAG',3,7); /*out put is =cdefag */

Instr to give only possion  of letter in use in a string
Instr(String,'letter',possition  of letter in use)
Instr('ABCDEFAB','a',1,2)/* out put is= 1

  Was this answer useful?  Yes

Nicsmart

  • Mar 31st, 2010
 

SUBSTR
------
The substr functions allows you to extract a substring from a string.
The syntax for the substr function is:

substr( string, start_position, [ length ] )

string is the source string.  start_position is the position for extraction. The first position in the string is always 1. length is optional. It is the number of characters to extract. If this parameter is omitted, substr will return the entire string.

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

For example:

substr('This is a test', 6, 2) would return 'is'
substr('This is a test', 6) would return 'is a test'
substr('TechOnTheNet', 1, 4) would return 'Tech'
substr('TechOnTheNet', -3, 3) would return 'Net'
substr('TechOnTheNet', -6, 3) would return 'The'
substr('TechOnTheNet', -8, 2) would return 'On'

INSTR
-----
The instr function returns the location of a substring in a string.  The syntax for the instr Oracle function is:

instr( string1, string2 [, start_position [, nth_appearance ] ] )

string1 is the string to search. string2 is the substring to search for in string1. start_position is the position in string1 where the search will start. This argument is optional. If omitted, it defaults to 1. The first position in the string is 1. If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1.  nth_appearance is the nth appearance of string2. This is optional. If omitted, it defaults to 1.

Note:
If string2 is not found in string1, then the instr Oracle function will return 0.

For example:

instr('Tech on the net', 'e') would return 2; the first occurrence of 'e'
instr('Tech on the net', 'e', 1, 1) would return 2; the first occurrence of 'e'
instr('Tech on the net', 'e', 1, 2) would return 11; the second occurrence of 'e'
instr('Tech on the net', 'e', 1, 3) would return 14; the third occurrence of 'e'
instr('Tech on the net', 'e', -3, 2) would return 2

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions