java - How to extract numbers? -
i have database that:
stockcode stockname stockstart stockfinish stockcurrentnumber __________________________________________________________ 100 water 1 10 ?
now how code looks this...
stockcode stockname stockstart stockfinish stockcurrentnumber __________________________________________________________ 100001 water 1 10 001 100002 water 1 10 002 100003 water 1 10 003 100004 water 1 10 004 100005 water 1 10 005 100006 water 1 10 006 100007 water 1 10 007 100008 water 1 10 008 100009 water 1 10 009 100010 water 1 10 010
i appreciate if help
sorry, edit, have 1 record, , want duplicated in range stockstart stockfinish
try
select concat(`stockcode`,lpad(@sno + 1,3,0)) stockcode, `stockname`, `stockstart`, `stockfinish`, @sno := lpad(@sno + 1,3,0) stockcurrentnumbe table1, (select @sno := 000) t
fiddle
edit
for update can create new table (for reference see fiddle demo) using below query , once done can rename table actual table , below example have use int()
not smallint
create table table2 (`stockcode` int(11), `stockname` varchar(5), `stockstart` int, `stockfinish` int, `stockcurrentnumber` int(11)) ; insert table2 (`stockcode`, `stockname`, `stockstart`, `stockfinish`, `stockcurrentnumber`) select concat(`stockcode`,lpad(@sno + 1,3,'0')) stockcode, `stockname`, `stockstart`, `stockfinish`, @sno := lpad(@sno + 1,3,'0') stockcurrentnumber table1, (select @sno := 000) t ;
the data in column stockcurrentnumber
of table2 have data without leading zeros because datatype integer , 001 =1 leading zeros fetch results can use lpad(stockcurrentnumber,3,'0')
more see lpad docs , query not harder 1 have used variable generate auto incremented values stockcurrentnumber
column , concat() combine values auto incremented value , stockcode
concat(
stockcode,lpad(@sno + 1,3,'0')) stockcode
,hope makes sense
Comments
Post a Comment