zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Sql Server REPLACE函数

serverSQL 函数 replace
2023-09-14 09:02:14 时间

Replaces all occurrences of a specified string value with another string value.
语法:
REPLACE ( string_expression , string_pattern , string_replacement )
参数:
string_expression
Is the string expression to be searched. string_expression can be of a character or binary data type.
string_pattern
Is the substring to be found. string_pattern can be of a character or binary data type. string_pattern cannot be an empty string (), and must not exceed the maximum number of bytes that fits on a page.
string_replacement
Is the replacement string. string_replacement can be of a character or binary data type.
返回
Returns nvarchar if one of the input arguments is of the nvarchar data type; otherwise, REPLACE returns varchar.
Returns NULL if any one of the arguments is NULL.
If string_expression is not of type varchar(max) or nvarchar(max), REPLACE truncates the return value at 8,000 bytes. To return values greater than 8,000 bytes, string_expression must be explicitly cast to a large-value data type.
即用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式。

例子:

SELECT REPLACE(AAAAAXXXAAA,X,A);

结果:

 

 


SQL Server 2000 函数使用---CAST 和 CONVERT 日期格式样式,借以将 datetime 或 smalldatetime 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型);或者字符串格式样式,借以将 float、real、money 或 smallmoney 数据转换为字符数据(nchar、nvarchar、char、varchar、nchar 或 nvarchar 数据类型)。
SQL Server函数之空值处理 原文:SQL Server函数之空值处理 coalesce( expression [ ,...n ] )返回其参数中第一个非空表达式。   Select coalesce(null,null, 1 , 2 ) //结果为 1 coalesce(expression1,.
深入理解SQL Server 2005 中的 COLUMNS_UPDATED函数 原文:深入理解SQL Server 2005 中的 COLUMNS_UPDATED函数 COLUMNS_UPDATED函数能够出现在INSERT或UPDATE触发器中AS关键字后的任何位置,用来指示表或视图中有哪些列已被插入或者更新。