CustomerCode sort in the table is disordered, we have to deal with this batch of data, 1. Write a SQL statement to take CustomerCode column after a maximum of five digital structure
2. Generate new way of coding inserted into a NewCode, encoding requirements in the form of C00001, Where C is fixed, according to the CustomerCode behind five after five ascending, starting from 1
CodePudding user response:
Select t. *, 'C' | | lpad (row_number () over (order by to_number (substr (t.a aa, length (t.a aa) - (4))), '5', '0') cn The from t_aa t; Refer to this, change yourself,
CodePudding user response:
The update t_aa t The set t.a _path= (select cn The from (select 'C' | | Lpad (row_number () Over (order by To_number (substr (a.a aa, length (a.a aa) - (4))), '5', '0') as cn, Anderson, d The from TMP t_aa a) Where t.i d=TMP. Id); I built the test table, this statement line To change the corresponding field name and the name of the table,
CodePudding user response:
Needs to be updated according to the id or generated newcode directly according to the order from big to small in the can?
CodePudding user response:
First SELECT MAX (TO_NUMBER (SUBSTR (customercode, 5))) as maxnum from t