简体   繁体   中英

SQL truncate length of a string

我在postgreSQL中有一个表程序员(id,name),我想返回所有程序员的名字,如果一个名字超过12个字符,我想把它截断为12个字符,任何想法我怎么能这样做?

Try this

select substring(name from 1 for 12) from your_table

Referred https://www.postgresql.org/docs/9.1/static/functions-string.html

Or the comment mentioned by @Prdp is a better alternative I think. Check the cost for both and use the one suits you.

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