简体   繁体   English

修剪0和尾部/前导空格都不会产生结果-MySQL

[英]Trimming both 0 and trailing/leading spaces doesn't give results - MySQL

I have the below situation in the database where accounts could have leading 0 and white spaces. 我在数据库中可能遇到以下情况,其中帐户可能有前导0和空白。

在此处输入图片说明

If I use TRIM(TRIM(LEADING '0' FROM account_ref)) as account_ref_trimmed , I get: 如果我使用TRIM(TRIM(LEADING '0' FROM account_ref)) as account_ref_trimmedTRIM(TRIM(LEADING '0' FROM account_ref)) as account_ref_trimmed得到:

在此处输入图片说明

Question, is it correct to put trim inside the trim? 问题,将装饰放入装饰内是否正确? Secondly, why in row 5, there is still a leading 0? 其次,为什么在第5行中仍然有前导0?

Trim the spaces and then the zeroes: 修剪空格,然后修剪零:

TRIM(LEADING '0' FROM TRIM(account_ref))

When you try to trim the zeroes first, any values that have spaces at the beginning and then zeroes will only be trimmed off of spaces. 当您尝试首先修剪零时,任何在开始处有空格然后零的值都将被修剪掉。
As for your question about precedence it is indicated by the nested parentheses. 至于您关于优先级的问题,它由嵌套括号表示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM