Hello, readers. In today’s article, we will be focusing on SQL Server TRIM() function in detail.

您好,读者们。 在今天的文章中,我们将重点关注SQL Server TRIM()函数



SQL Server TRIM()函数的工作 (Working of SQL Server TRIM() function)

In every programming language or query language, a set of functions are specified to manipulate and deal with the data input values.

在每种编程语言或查询语言中,都指定了一组函数来操纵和处理数据输入值。

On similar lines, SQL Server has in-built functions to deal with the String data values.

类似地,SQL Server具有内置函数来处理String数据值。

SQL Server TRIM() function helps eliminate the leading and trailing spaces from the data values contained in a table of the database.

SQL Server TRIM()函数有助于从数据库表中包含的数据值中消除前导和尾随空格

The TRIM() function not only eliminates the white spaces but also deletes a particular character from the leading and trailing part of the string values.

TRIM()函数不仅消除了空格,而且还从字符串值的开头和结尾部分删除了特定字符。

Now let us understand the syntax of TRIM() function in the upcoming section.

现在,让我们在接下来的部分中了解TRIM()函数的语法。



SQL Server TRIM()函数的语法 (Syntax of SQL Server TRIM() function)

SQL Server TRIM() function accepts the data to be trimmed and the character value( in case we want to trim certain characters from the string data).

SQL Server TRIM() function接受要修剪的数据和字符值(以防我们要从字符串数据中修剪某些字符)。


SELECT TRIM('characters' FROM 'data-value');
  • characters (OPTIONAL): Set of characters are passed which we want to eliminate from the starting and ending point of the string data values.characters (OPTIONAL) :传递的字符集我们要从字符串数据值的起点和终点消除。

Having understood the structure of TRIM() function, let us understand the implementation of the same through some examples.

了解了TRIM() function的结构之后,让我们通过一些示例来了解其实现。



TRIM()函数的示例 (Examples of TRIM() function)

In the below example, we intend to trim the character ‘$’ from the input data value.

在下面的示例中,我们打算从输入数据值中修剪字符“ $”。


SELECT TRIM('$ ' FROM '   $PythonJournalDev$   ') AS Output;

As clearly seen below, the TRIM() function has completely eliminated ‘$’ from the leading and trailing part of the string.

如下所示,TRIM()函数已从字符串的开头和结尾部分完全消除了“ $”。

Output:

输出:


PythonJournalDev

TRIM() function detects and eliminates all the leading and trailing white-spaces too as seen below.

TRIM()函数也可以检测并消除所有前导和尾随空格,如下所示。


SELECT TRIM('   $PythonJournalDev$   ') AS Output;

In the above example, the character ‘$’ does not get eliminated as we have not passed the character to the parameter list. Here, the TRIM() function eliminates the spaces here.

在上面的示例中,字符“ $”没有被消除,因为我们没有将字符传递给参数列表。 在这里,TRIM()函数消除了此处的空格。

Output:

输出:


$PythonJournalDev$

In this example, we have created a table and inserted values into it. Further, we have used TRIM() function to trim the white spaces from all the data values of the passed column.

在此示例中,我们创建了一个表并将值插入其中。 此外,我们使用了TRIM()函数从传递的列的所有数据值中修剪空白。


CREATE TABLE Info (id INT PRIMARY KEY,City VARCHAR (255) NOT NULL
); INSERT INTO Info (id,City
)
VALUES(1,'  Pune  '),(2,'       Satara  '),(3,' California       ');
UPDATE Info
SET  City = TRIM(City);Select * from Info;

Output:

输出:


id  City
1   Pune
2   Satara
3   California


结论 (Conclusion)

That’s all for this topic. Please feel free to comment below in case you come across any doubt.

这就是本主题的全部内容。 如果您有任何疑问,请随时在下面发表评论。

For more such posts related to SQL Server, please do visit SQL Server JournalDev.

有关与SQL Server相关的更多此类帖子,请访问SQL Server JournalDev 。



参考资料 (References)

  • SQL Server TRIM() — DocumentationSQL Server TRIM()—文档

翻译自: https://www.journaldev.com/41172/sql-server-trim-function

什么是SQL Server TRIM()函数?相关推荐

  1. oracle sql常用的函数,界别Oracle和SQL Server常用函数

    区分Oracle和SQL Server常用函数 一.数学函数 1.绝对值 S:select abs(-1) value O:select abs(-1) value from dual 2.取整(大) ...

  2. SQL指令— TRIM函数

    SQL指令- TRIM函数 SQL 中的 TRIM 函数是用来移除掉一个字串中的字头或字尾.最常见的用途是移除字首或字尾的空白.这个函数在不同的资料库中有不同的名称: MySQL: TRIM(), R ...

  3. SQL Server用户自定义函数

    用户自定义函数不能用于执行一系列改变数据库状态的操作,但它可以像系统 函 数一样在查询或存储过程等的程序段中使用,也可以像存储过程一样通过 EXECUTE 命令来执行.在 SQL Server 中根据 ...

  4. SQL Server CONVERT() 函数,Date 函数

    From: http://www.w3school.com.cn/sql/func_convert.asp 定义和用法 CONVERT() 函数是把日期转换为新数据类型的通用函数. CONVERT() ...

  5. SQL Server日期函数集合

    SQL Server日期函数集合--1:获取系统日期和时间值函数 --getdate() SELECT GETDATE() AS 'today' --getutcdate() SELECT GETUT ...

  6. sql server 自定义函数的使用

    sql server 自定义函数的使用 自定义函数 用户定义自定义函数像内置函数一样返回标量值,也可以将结果集用表格变量返回 用户自定义函数的类型: 标量函数:返回一个标量值 表格值函数{内联表格值函 ...

  7. sql server charindex函数和patindex函数详解(转)

    charindex和patindex函数常常用来在一段字符中搜索字符或字符串.假如被搜索的字符中包含有要搜索的字符,那么这两个函数返回一个非零的整数,这个整数是要搜索的字符在被搜索的字符中的开始位数. ...

  8. Sql Server REPLACE函数的使用;SQL中 patindex函数的用法

    Sql Server REPLACE函数的使用 REPLACE 用第三个表达式替换第一个字符串表达式中出现的所有第二个给定字符串表达式. 语法 REPLACE ( ''string_replace1' ...

  9. Sql server 日期函数和日期转换

    时间函数 SQL Server Date 函数 下面的表格列出了 SQL Server 中最重要的内建日期函数: 函数 描述 GETDATE() 返回当前日期和时间 DATEPART(Type,dat ...

最新文章

  1. 如何评价CVPR 2021的论文接收结果?
  2. 自制一个 简易jQuery 的 API
  3. windows环境里React-Native运行失败,找不到Nullable的原因分析
  4. 使用ASP.NET Core 3.x 构建 RESTful API - 1. 开始
  5. Highchart series一次只显示一条
  6. 关于在asp.net中播放MP4格式的视频(好吧,只兼容支持html5的浏览器,ie8及以下的都歇菜了)...
  7. vue 源码学习(一) 目录结构和构建过程简介 1
  8. 晨哥真有料丨太快得到是不是就不珍惜了?这锅,男生真的不背!
  9. PyCharm 与 Git/GitHub 关联 / 取消关联
  10. java地铁最短_南京地铁最短路径以及最少换乘算法C++不用类
  11. 数模电路基础知识 —— 5. 常见电路符号说明(三极管)
  12. intellij no executable code found at line
  13. 仿真软件 JaamSim介绍
  14. i7 1165g7和i7 9750h 哪个好
  15. 异常被 ”吃“ 掉导致事务无法回滚
  16. B/S架构与C/S架构
  17. 使用.NET推送企业微信群聊消息
  18. 奥运金牌金镶玉到底值多少钱
  19. MYSQL学习笔记(自用)第九章
  20. robot selenium+python 对火狐浏览器进行网页自动化测试 报错历程

热门文章

  1. 今天执行grep命令差点把服务器搞崩
  2. 网上图书商城项目学习笔记-034订单管理
  3. Exchange2003/2010共存模式环境迁移
  4. 一步一步学Silverlight 2系列(2):基本控件_转载
  5. 笔者认为,中国的互联网行业需要真正的CEO
  6. [转载] python判断字符串中包含某个字符串_干货分享| Python中最常用的字符串方法
  7. [转载] Python算法
  8. [转载] Pytorch入门实战-----逻辑回归识别手写数据集
  9. [转载] python 超高精度除法_Python十进制-除法,舍入,精度
  10. LODOP打印当前日期时间的方法