MYSQL更新查询删除空格

发布于 2024-08-23 15:38:24 字数 878 浏览 3 评论 0原文

我的一位客户在我们的一个应用程序中添加了多个帐号。 尝试进行交易时,由于帐号末尾有空格,交易失败。 我如何更新他在Mysql数据库中的记录,以删除末尾有空格的帐户中的所有空格,而不会让他删除客户端并重新添加帐户?表的结构如下:

不确定如何构造查询或 mysql 的功能

帐户表:

the account table:
CUSTOMER_ID              
ACCOUNTNUMBER        
TXT                   
CURRENCY_NO            
USER_ID                  
ACTIVE_FLAG               
USER_DATE                 
ben_bic_address          
int_bic_address 

the admin table

  ADM_USER_ID           
  LOCATION_CD          
  LANG                
  USER_NAME              
  USER_LOGIN            
  USER_PASSWORD          
 GROUP_CODE            
 USER_ID              
  USER_DATE               
  ACTIVE                 
 COUNTER                
 connected              
 IP

And the customer table:

CUSTOMER_ID               
COUNTRY_NO              
USER_ID                   
CUSTOMER_NAME 
ACTIVE_FLAG

One of my clients has added a number of account numbers in one of our applications.
While trying to make a transaction the transaction fails due to the spaces at the end of the account number.
How do i update his records in the Mysql database to remove all the spaces from accounts that have them at the end, without making him delete the clients and re-adding the accounts? the structure of the table(s) is as follows:

Not sure how to structure the query or the function of the mysql

The account table:

the account table:
CUSTOMER_ID              
ACCOUNTNUMBER        
TXT                   
CURRENCY_NO            
USER_ID                  
ACTIVE_FLAG               
USER_DATE                 
ben_bic_address          
int_bic_address 

the admin table

  ADM_USER_ID           
  LOCATION_CD          
  LANG                
  USER_NAME              
  USER_LOGIN            
  USER_PASSWORD          
 GROUP_CODE            
 USER_ID              
  USER_DATE               
  ACTIVE                 
 COUNTER                
 connected              
 IP

And the customer table:

CUSTOMER_ID               
COUNTRY_NO              
USER_ID                   
CUSTOMER_NAME 
ACTIVE_FLAG

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏天碎花小短裙 2024-08-30 15:38:24

如果您需要 RTRIM() 特定客户的所有帐户,您可以将 JOIN 与 UPDATE 语句结合使用,如下所示:

UPDATE
    accounts_table
INNER JOIN
    customers_table ON (accounts_table.user_id = customers_table.user_id)
SET 
    accountnumber = RTRIM(accountnumber)
WHERE
    customers_table.customer_id = 'customer id';

如果您的 account_table 中没有很多记录,并且您想要确保所有 accountnumber 值都被修剪,您可以简单地将修剪应用于所有记录,如下所示:

UPDATE
    accounts_table
SET 
    accountnumber = TRIM(accountnumber);

If you need to RTRIM() all the accounts of a particular customer, you can use a JOIN with your UPDATE statement as follows:

UPDATE
    accounts_table
INNER JOIN
    customers_table ON (accounts_table.user_id = customers_table.user_id)
SET 
    accountnumber = RTRIM(accountnumber)
WHERE
    customers_table.customer_id = 'customer id';

If you do not have many records in accounts_table, and you want to make sure that all the accountnumber values are trimmed, you can simply apply the trim to all the records as follows:

UPDATE
    accounts_table
SET 
    accountnumber = TRIM(accountnumber);
已下线请稍等 2024-08-30 15:38:24

您将使用 TRIM 和更新。

只需使用这个就可以了。

UPDATE accountTable
SET ACCOUNTNUMBER = RTrim(ACCOUNTNUMBER)

You would use TRIM and update.

Just using this should do it.

UPDATE accountTable
SET ACCOUNTNUMBER = RTrim(ACCOUNTNUMBER)
戏蝶舞 2024-08-30 15:38:24

如果您有外键约束,那么您可能必须在进行修改时删除它们。

以下查询将更改accounts表中的记录:

update accounts set accountnumber = rtrim(accountnumber);

If you have foreign key constraints, then you may have to remove them whilst you make the modifications.

The following query will change the records in the accounts table:

update accounts set accountnumber = rtrim(accountnumber);
草莓酥 2024-08-30 15:38:24

尝试这个

TRIM() 函数从字符串中删除多余的空格。

UPDATE item_listing SET product_quantity = TRIM(product_quantity);

结果:

Product_quantity = " 50 " => 50

Try this

TRIM() Function removes extra (or) additional spaces from a string.

UPDATE item_listing SET product_quantity = TRIM(product_quantity);

Result:

Product_quantity = " 50 " => 50

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文