Fix sample INSTR function to return 0 if third arg is 0.

Albe Laurenz, per a report by Greg Smith that our sample function
doesn't quite match Oracle's behavior.
This commit is contained in:
Robert Haas 2012-07-04 17:19:23 -04:00
parent 72dd6291f2
commit 0fc32c00d7
1 changed files with 6 additions and 2 deletions

View File

@ -5115,7 +5115,7 @@ BEGIN
ELSE ELSE
RETURN pos + beg_index - 1; RETURN pos + beg_index - 1;
END IF; END IF;
ELSE ELSIF beg_index < 0 THEN
ss_length := char_length(string_to_search); ss_length := char_length(string_to_search);
length := char_length(string); length := char_length(string);
beg := length + beg_index - ss_length + 2; beg := length + beg_index - ss_length + 2;
@ -5131,6 +5131,8 @@ BEGIN
beg := beg - 1; beg := beg - 1;
END LOOP; END LOOP;
RETURN 0;
ELSE
RETURN 0; RETURN 0;
END IF; END IF;
END; END;
@ -5170,7 +5172,7 @@ BEGIN
ELSE ELSE
RETURN beg; RETURN beg;
END IF; END IF;
ELSE ELSIF beg_index < 0 THEN
ss_length := char_length(string_to_search); ss_length := char_length(string_to_search);
length := char_length(string); length := char_length(string);
beg := length + beg_index - ss_length + 2; beg := length + beg_index - ss_length + 2;
@ -5190,6 +5192,8 @@ BEGIN
beg := beg - 1; beg := beg - 1;
END LOOP; END LOOP;
RETURN 0;
ELSE
RETURN 0; RETURN 0;
END IF; END IF;
END; END;