我有三个字段,它们在表上形成一个唯一的复合键。
我想传入 3 个不同的数组,其中索引匹配。
custIds= [0,1,2]
custLetters = [A,B,C]
products = ["Cheese","lemons","Aubergine"]
是否有一个 sql 语句将返回所有三行(假设它们存在),
由于“误报”,仅通过 in
组合将不起作用:
select * from mytable
where custId in (custIds)
and custLetters in (custLetters)
and product in (products);
数据库 oracle,但通过 hibernate hql,所以如果可能的话首选 ansi ?
最佳答案
OT:您的 SQL 查询可能有误。应该是:
select * from mytable
where (custId, custLetters, product)
in ( (0, 'A', 'Cheese'),
(1, 'B', 'lemons'),
(2, 'C', 'Aubergine'));
我不关心 Hibernate 是否可以生成这样的查询。但是 in
只是连词和析取的语法糖。
关于java - 复合键,比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30081972/