首页 > 解决方案 > 如何从列中选择特定字符串?

问题描述

我有一列包含一些像这样的值

PRODUCT CODE
A099  - Mouse Corded Other                  
X001  - Pointing Devices Family - FP&A Only 
W049A - Video Dualcam Other                 
N029  - Joystick PC Other                   
Y089  - Video Other Other                   
P059  - Gaming Wheels - FP&A Only  

我想在之前获取字符串或代码-。这可能吗 ?

所以结果集会是这样的

A099
X001
W049A
N029
Y089
P059

标签: sqloracle-sqldeveloper

解决方案


使用可以使用regexp_replace()

select regexp_replace(product_code, '^([^ ]+) ', '\1')

或者regexp_substr()

select regexp_substr(product_code, '^[^ ]+')

推荐阅读