MYSQL更新查询以删除空格

时间:2022-05-20 21:46:09

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:

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

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

不知道如何构造查询或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

3 个解决方案

#1


20  

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

如果您需要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';

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:

如果您在accounts_table中没有很多记录,并且您希望确保修剪所有帐户编号值,则只需将修剪应用于所有记录,如下所示:

UPDATE
    accounts_table
SET 
    accountnumber = TRIM(accountnumber);

#2


3  

You would use TRIM and update.

您将使用TRIM并进行更新。

Just using this should do it.

只是使用它应该这样做。

UPDATE accountTable
SET ACCOUNTNUMBER = RTrim(ACCOUNTNUMBER)

#3


0  

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:

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

update accounts set accountnumber = rtrim(accountnumber);

#1


20  

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

如果您需要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';

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:

如果您在accounts_table中没有很多记录,并且您希望确保修剪所有帐户编号值,则只需将修剪应用于所有记录,如下所示:

UPDATE
    accounts_table
SET 
    accountnumber = TRIM(accountnumber);

#2


3  

You would use TRIM and update.

您将使用TRIM并进行更新。

Just using this should do it.

只是使用它应该这样做。

UPDATE accountTable
SET ACCOUNTNUMBER = RTrim(ACCOUNTNUMBER)

#3


0  

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:

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

update accounts set accountnumber = rtrim(accountnumber);