简体   繁体   中英

Sub String function in Teradata

我需要从字符串'000-111-222-333'中单独提取'000-111',即Teradata中第二个'-'之前的字符串部分,而无需对位置进行硬编码,因为字符串中的字符数可能会有所不同。预先

Depending on your TD release (or installed UDFs):

SUBSTRING(x FROM 1 FOR INSTR(x,'-',1,2) - 1)

This should work in any TD release:

SUBSTRING(x FROM 1 FOR POSITION('-' IN x) + POSITION('-' IN SUBSTRING(x FROM POSITION('-' IN x) + 1)) - 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