MYSQL 更新查询以删除空格

MYSQL update query to remove spaces(MYSQL 更新查询以删除空格)
本文介绍了MYSQL 更新查询以删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

账户表:

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

推荐答案

如果你需要RTRIM()特定客户的所有账户,你可以使用JOIN 你的 UPDATE 语句如下:

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';

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

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);

这篇关于MYSQL 更新查询以删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)