简体   繁体   中英

how to change all records of a specific field in mysql

I have a table topMovies containing 100,000 records. Table fields are Id, name, movieId and year. Data in movieId field are stored like (/title/tt0111161/, ...), also in the field "year", data are inside parentheses for example (2008) instead of 2008.

Could someone kindly help me how I can change them to tt0111161 and 2008? (I mean deleting other characters like /title/ for movieId and () for year?

Thanks a lot,

Try this

UPDATE topMovies
SET movieId = REPLACE(REPLACE(movieId,'/title/',''),'/',''),
year = REPLACE(REPLACE(year,'(',''), ')','')

It worked this way for me:

UPDATE topMovies
SET movieId = RIGHT(movieId, LENGTH(movieId) - 7)

It subtracted left 7 characters that is /title/, and the rest was what I needed (movieId). the same way for deleting parenthesis in year column worked fine, just in order to delete the right parenthesis, I used LEFT(year, LENGHT(year) -1).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM