sql - Oracle 从值包含下划线的表中选择
问题描述
我有一个查询,我需要从值以 M_ 开头的表中进行选择。问题是下划线是oracle中的通配符。因此,在描述字段中获取以下数据:
M1
M_1
M2
M_2
当我运行以下查询时,将返回所有字段:
select description from table where description like 'M_%'
我尝试使用以下不返回结果的查询进行转义:
select description from table where description like 'M\_%'
我正在寻找的结果只是以 M_ 开头的描述,因此预期的结果是:
M_1
M_2
提前感谢您的帮助
解决方案
您需要明确指定转义字符:
select description from table where description like 'M\_%' escape '\'
这意味着您可以使用替代字符代替反斜杠。例如:
select description from table where description like 'M$_%' escape '$'
推荐阅读
- java - 将 Java pojo 转换为 json 字符串
- sql - 根据值列表向 SQL 表添加行
- codeigniter - 在检索 IPN 响应时使用 Codeigniter 的 PayPal IPN 问题
- javascript - 根据子数组映射父数组
- c - 为什么 strstr 不能从环形缓冲区中找到子字符串?
- python - Python:计算所有具有相同学科的学生的平均成绩
- linux - sh 的启动用户脚本(在 alpine 上)
- r - ggplot2:删除和替换轴
- android - 如何在 Here map Android 上的多边形中创建孔?
- r - 将嵌套循环的结果添加到 R 中的数据框行中