sql - Oracle -SQL- 使用 where 条件根据长列表选择值
问题描述
我有一长串(超过 2000 个)电话号码,我想选择电话号码在列表中的值。谁能告诉我如何使用 sql 有效地做到这一点?谢谢!
我知道的方法是:
select name, date from table where phone in ('8001234567','8011234567',....)
此方法列出 where 条件下的所有电话号码。有没有其他方法,比如我可以在某个文件中创建一个列表,然后从文件中选择?
谢谢你。
解决方案
如果这只是一次性查询并且您不需要维护此列表,则可以使用 CTE 执行此操作:
with phone_list as (
select '1234567890' as phone from dual union all
select '2345678901' as phone from dual union all
...
select '9999999999' as phone from dual
)
select name, date
from table t
inner join phone_list pl on pl.phone = t.phone
推荐阅读
- kubernetes - Terraform Kubernetes 部署与 pod 就绪门
- python-3.x - 如何从 sqlalchemy ORM 获取原始 sql 插入/更新
- macos - IOLockWakeup 和 IOLockSleep
- android - Xamarin - httpClient.GetAsync 适用于 IOS 但不适用于 Android
- gitlab-ci - 树莓派上的主机密钥验证失败
- c++ - C ++“const”关键字有什么意义?
- actions-on-google - 不使用 gactions CLI 更新 actions.json
- java - 在运行时更改 Java Swing 主题会导致 JTable 错误
- javascript - 我怎样才能只使用 ID 对用户进行 dm 操作?
- php - 如何记录“找不到路线”