sql - 如何从列中选择特定字符串?
问题描述
我有一列包含一些像这样的值
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
解决方案
使用可以使用regexp_replace()
:
select regexp_replace(product_code, '^([^ ]+) ', '\1')
或者regexp_substr()
:
select regexp_substr(product_code, '^[^ ]+')
推荐阅读
- flutter - 在颤动中单击时仅在 ListTile 中的一项上显示尾随图标
- highcharts - Highcharts:当数据存储在 Google 电子表格中时,如何使 startRow 和 endRow 再次工作?
- python - 我可以(安全地)覆盖服务器端 wsgi.py 中的 Django 设置吗?
- jenkins - 配置 LDAP 时的 Jenkins CLI
- oop - 我们应该在拦截设计模式实现中使用 NullValueFilter 吗?
- react-native - 每次都没有加载远程 JSON 文件 - React Native
- sas - 如何根据变量的最大值打印 SAS 记录
- django - 如何将一个表列复制到 Django 中的另一个表列?
- firebase - 通过 REST API 更新 Firebase Auth 用户声明
- ruby-on-rails - devise-jwt 使用的“拒绝列表”表是否无限保留所有过期的令牌?