本文介绍了SQL查询(Pro * C)如何能够找到不存在于数据库表中的值集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C / C ++程序,在pro c(11.2+版本)中嵌入了Oracle SQL调用。我有一个值列表(int)作为数组。我想检查一个SQL查询(作为pro c代码)哪些值不在数据库表中。例如,我有值: 10,20,30,40,50 存储在数组中,我的数据库表t1的列col1有 10,20,40

I have a C/C++ program with embedded Oracle SQL calls in proc (11.2+ version). I have a list of values (int) as an array. I would like to check through a SQL query (as proc code) which values are not in a DB table. For example, say, I have values: 10, 20, 30, 40, 50 stored in an array and my DB table t1 has column col1 that has 10, 20, 40. So,

Select col1 from t1

会提供给我:

10
20
40

所以,我正在寻找排除的值,即30,50。
通过嵌入式Pro * C SQL查询?
我的列表很大,并且DB表有很多值。

So, I am looking for the excluded values, i.e. 30, 50.Can I do this through an embedded Pro*C SQL query?My list is quite large and the DB table has many values.

推荐答案

一张桌子。这是一个典型的方式,在大多数数据库中工作:

You need to set up your values in a table. Here is a typical way what will work in most databases:

with list as (
      select 10 as n union all select 20 union all select 30 union all
      select 40 union all select 50
     )
select l.*
from list l
where not exists (select 1 from t1 where col1 = l.n);

语法可能会因数据库而有所不同( from dual ,一个子查询而不是CTE),但是想法是一样的。

The syntax might vary depending on the database (from dual, a subquery instead of a CTE), but the idea is the same.

这篇关于SQL查询(Pro * C)如何能够找到不存在于数据库表中的值集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-17 01:20