MSSQL 中 Stuff 的应用

本文介绍MSSQL中的Stuff函数使用方法,包括删除指定长度的字符并插入新的字符集,提供具体语法和参数说明,并通过实例演示如何操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

MSSQL 中 Stuff 的应用

select stuff(stuff(convert(char(8),getdate(),112),5,0,N'Year'),11,0,N'Month')+'Day'
SELECT STUFF(STUFF(CONVERT(char(8),getdate(),112),5,0,N'年'),8,0,N'月')+N'日'


---Result---
--------------------
2008Year11Month06Day

(1 row(s) affected)


-----------
2008年11月06日

(1 row(s) affected)


STUFF
Deletes a specified length of characters and inserts another set of characters at a specified starting point.

Syntax
STUFF ( character_expression , start , length , character_expression )

Arguments
character_expression

Is an expression of character data. character_expression can be a constant, variable, or column of either character or binary data.

start

Is an integer value that specifies the location to begin deletion and insertion. If start or length is negative, a null string is returned. If start is longer than the first character_expression, a null string is returned.

length

Is an integer that specifies the number of characters to delete. If length is longer than the first character_expression, deletion occurs up to the last character in the last character_expression.

Return Types
Returns character data if character_expression is one of the supported character data types. Returns binary data if character_expression is one of the supported binary data types.

Remarks
String functions can be nested.

Examples
This example returns a character string created by deleting three characters from the first string (abcdef) starting at position 2 (at b) and inserting the second string at the deletion point.

SELECT STUFF('abcdef', 2, 3, 'ijklmn')
GO

Here is the result set:

---------
aijklmnef

(1 row(s) affected)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值