Skip to Main Content

SQL & PL/SQL

Equivalents To SQL Server's STUFF() Function

Ray WinkelmanJul 28 2016 — edited Jul 28 2016

Hey Guys!

Let's have some fun with strings today.

So, I've got some T-SQL code I'm translating into PL-SQL, and I've been encountering some uses of SQL Server's STUFF() function. Microsoft's documentation on the STUFF() function states:

The STUFF function inserts a string into another string. It deletes a specified length of characters in the first string at the start position and then inserts the second string into the first string at the start position.

The header of the STUFF() function accepts the following arguments:

STUFF ( character_expression , start , length , replaceWith_expression )


So, considering the following code as our example, how can we manipulate a string in PL-SQL with as few calls to system functions as possible? Let's aim for the most performant solution - as always.

select stuff(

(

    select '123456789'

    from   table_name for clob path('')

), 1, 4, ''

) as example

from dual;

And, GO!

This post has been answered by Paulzip on Jul 28 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2016
Added on Jul 28 2016
22 comments
13,493 views