title: Pl/Sql using instr to find exact match
body: <p>I am trying to find if a string exist in a word and extract it. I have uses the <code>instr()</code> function but this works as the LIKE function: if part or the whole word exists it returns it.</p>
  
  <p>Here I want to get the string 'Services' out, it works but if I change 'Services' to 'Service' it still works. I don't want that. If 'Service' is entered it should return null and not 'Services' </p>
  
  <p>Modified:</p>
  
  <p>What I am trying to do here is abbreviate certain parts of the company name.</p>
  
  <p>This is what my database table looks like :</p>
  
  <pre><code>Word     | Abb
  ---------+-----  
  Company  | com
  Limited  | ltd
  Service  | serv
  Services | servs
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>Declare 
  
      Cursor Words Is
  
      SELECT word,abb
      FROM abbWords
  
  
      processingWord VARCHAR2(50);
      abbreviatedName VARCHAR(120);
      fullName = 'A.D Company Services Limited';
  
  BEGIN
  
      FOR eachWord IN Words LOOP
  
  
        --find the position of the word in name
         wordPosition := INSTR(fullName, eachWord.word);
  
         --extracts the word form the full name that matches the database
         processingWord := Substr(fullName,instr(fullName,eachWord.word), length(eachWord.word));
  
        --only process words that exist in name
        if wordPosition &gt; 0 then
             abbreviatedName = replace(fullName, eachWord.word,eachWord.abb);
         end if;
  
      END lOOP;
  
  END;
  </code></pre>
  
  <p>So if the user enters 'Service' I don't want 'Services' to be returned.  By this I mean word position should be 0 if the word 'Service' in not found instead of returning the position for the word 'Services'</p>