组合键,比较 [英] Composite key, in comparison

查看:103
本文介绍了组合键,比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三个字段,它们在一个表上构成一个唯一的复合键.

I have three fields that form a unique composite key on a table.

我想传递索引匹配的3个不同的数组.

I want to pass in 3 different arrays, where the index matches.

custIds= [0,1,2]
custLetters = [A,B,C]
products = ["Cheese","lemons","Aubergine"]

是否有一条sql语句将返回所有三行(假设它们存在), 仅通过in进行合并将由于误报"而无法使用:

is there one sql statement that will return all three rows (assuming they exists), just combining via in won't work to due to "false positives" :

select * from mytable 
where custId in (custIds)
 and custLetters in (custLetters)
and product in (products);

数据库oracle,但通过休眠hql,因此尽可能使用ansi吗?

database oracle, but via hibernate hql, so ansi preferred if possible ?

推荐答案

OT:您的SQL查询可能是错误的.应该是:

OT: your SQL query is probably wrong. It should be:

select * from mytable 
where (custId, custLetters, product) 
in ( (0, 'A', 'Cheese'),
 (1, 'B', 'lemons'),
 (2, 'C', 'Aubergine'));

我不使用Hibernate是否可以生成这样的查询.但是in只是用于结合词和析取词的语法糖.

I'm not use whether Hibernate can generate such a query. But in is just a syntax sugar for conjuctions and disjunctions.

这篇关于组合键,比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆