复合键,比较
Composite key, in comparison
我在 table.
上形成了一个唯一的复合键的三个字段
我想传入 3 个不同的数组,其中索引匹配。
custIds= [0,1,2]
custLetters = [A,B,C]
products = ["Cheese","lemons","Aubergine"]
是否有一个 sql 语句将 return 所有三行(假设它们存在),
由于 "false positives" :
,仅通过 in
组合将不起作用
select * from mytable
where custId in (custIds)
and custLetters in (custLetters)
and product in (products);
数据库 oracle,但通过 hibernate hql,所以如果可能的话首选 ansi ?
你可以将你的数组组合成一个数组,然后:
custIds= [0,1,2]
custLetters = [A,B,C]
products = ["Cheese","lemons","Aubergine"]
Key=["0ACheese","1Blemons","2CAubergine"]
select * from mytable
where custId+custLetters+product in (Key);
OT:您的 SQL 查询可能有误。应该是:
select * from mytable
where (custId, custLetters, product)
in ( (0, 'A', 'Cheese'),
(1, 'B', 'lemons'),
(2, 'C', 'Aubergine'));
我不知道Hibernate 是否可以生成这样的查询。但是 in
只是连词和析取的语法糖。
我在 table.
上形成了一个唯一的复合键的三个字段我想传入 3 个不同的数组,其中索引匹配。
custIds= [0,1,2]
custLetters = [A,B,C]
products = ["Cheese","lemons","Aubergine"]
是否有一个 sql 语句将 return 所有三行(假设它们存在), 由于 "false positives" :
,仅通过in
组合将不起作用
select * from mytable
where custId in (custIds)
and custLetters in (custLetters)
and product in (products);
数据库 oracle,但通过 hibernate hql,所以如果可能的话首选 ansi ?
你可以将你的数组组合成一个数组,然后:
custIds= [0,1,2]
custLetters = [A,B,C]
products = ["Cheese","lemons","Aubergine"]
Key=["0ACheese","1Blemons","2CAubergine"]
select * from mytable
where custId+custLetters+product in (Key);
OT:您的 SQL 查询可能有误。应该是:
select * from mytable
where (custId, custLetters, product)
in ( (0, 'A', 'Cheese'),
(1, 'B', 'lemons'),
(2, 'C', 'Aubergine'));
我不知道Hibernate 是否可以生成这样的查询。但是 in
只是连词和析取的语法糖。