Firebird 2.1 Language Reference Update
Firebird 2.1 Language Reference Update
Firebird 2.1 Language Reference Update
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
See also: BIT_LENGTH(), CHARACTER_LENGTH<br />
Available in: DSQL, PSQL<br />
Added in: <strong>2.1</strong><br />
Internal functions<br />
OVERLAY()<br />
Description: Replaces part of a string with another string. By default, the number of characters removed from the<br />
host string equals the length of the replacement string. With the optional fourth argument, the user can specify<br />
a different number of characters to be removed.<br />
Result type: VARCHAR or BLOB<br />
Syntax:<br />
Examples:<br />
OVERLAY (string PLACING replacement FROM pos [FOR length])<br />
• This function supports BLOBs of any length. Due to a bug, BLOBs containing multi-byte characters<br />
– and sometimes even single-byte non-ASCII characters – will cause a “Cannot transliterate<br />
character between character sets” error. This bug does not occur in <strong>Firebird</strong> 2.5.<br />
• If string or replacement is a BLOB, the result is a BLOB. Otherwise, the result is a<br />
VARCHAR(n) with n the sum of the lengths of string and replacement.<br />
• As usual in SQL string functions, pos is 1-based.<br />
• If pos is beyond the end of string, replacement is placed directly after string.<br />
• If the number of characters from pos to the end of string is smaller than the length of replacement<br />
(or than the length argument, if present), string is truncated at pos and replacement<br />
placed after it.<br />
• The effect of a “FOR 0” clause is that replacement is simply inserted into string.<br />
• If any argument is NULL, the result is NULL.<br />
• If pos or length is not a whole number, bankers' rounding (round-to-even) is applied, i.e. 0.5<br />
becomes 0, 1.5 becomes 2, 2.5 becomes 2, 3.5 becomes 4, etc.<br />
overlay ('Goodbye' placing 'Hello' from 2) -- returns 'GHelloe'<br />
overlay ('Goodbye' placing 'Hello' from 5) -- returns 'GoodHello'<br />
overlay ('Goodbye' placing 'Hello' from 8) -- returns 'GoodbyeHello'<br />
overlay ('Goodbye' placing 'Hello' from 20) -- returns 'GoodbyeHello'<br />
overlay ('Goodbye' placing 'Hello' from 2 for 0) -- r. 'GHellooodbye'<br />
overlay ('Goodbye' placing 'Hello' from 2 for 3) -- r. 'GHellobye'<br />
overlay ('Goodbye' placing 'Hello' from 2 for 6) -- r. 'GHello'<br />
overlay ('Goodbye' placing 'Hello' from 2 for 9) -- r. 'GHello'<br />
overlay ('Goodbye' placing '' from 4) -- returns 'Goodbye'<br />
148