开发者

Replace multiple things at once in MySQL?

Is it possible to replace multiple things at once in MySQL?开发者_如何学运维

It feels kinda clumsy doing this

REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( myField, 'å', 'a' ) , 'Å', 'A' ) , 'Ø', 'O' ) , 'ø', 'o' ) , 'æ', 'a' ) , 'Æ', 'A' )


Short answer, no. There's really no need to elaborate :)


You can create your own user defined function to do this, but it's probably something I would put in a layer other than the database.

The database is optimised for the stuff it needs to do, data extraction/sorting/grouping and so on.

While it can do some manipulation of data within a column, that's not really its primary purpose (leave that to the presentation or other layers).

If you must do it within the DBMS, consider doing it with a separate column holding the modified data, and having that maintained with an insert/update trigger. This will at least ensure the cost is incurred only when the data changes, rather than every time you look at it. In other words, it will amortise the cost across all selects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜