STUFF Function [String]

Deletes a number of characters from one string and replaces them with another string.

Syntax

STUFFstring-expression1, start, length, string-expression2 )

Parameters

Parameter

Description

string-expression1

The string to be modified by the STUFF function.

start

The character position at which to begin deleting characters. The first character in the string is position 1.

length

The number of characters to delete.

string-expression2

The string to be inserted. To delete a portion of a string using the STUFF function, use a replacement string of NULL

Returns

LONG NVARCHAR

Example

The following statement returns the value “chocolate pie”:

SELECT STUFF( 'chocolate cake', 11, 4, 'pie' )
FROM iq_dummy

Usage

To delete a portion of a string using STUFF, use a replacement string of NULL. To insert a string using STUFF, use a length of zero.

The STUFF function will return a NULL result in the following situations:

  • Any of the first three parameters is a NULL value.

  • Either the start or length parameter is a negative value.

  • The start parameter is greater than the length of string-expression1.

Standards and Compatibility

  • SQL—Vendor extension to ISO/ANSI SQL grammar.

  • Sybase—Compatible with Adaptive Server Enterprise.