gpt4 book ai didi

sql - 查询输出表中不存在的值

转载 作者:行者123 更新时间:2023-12-05 08:02:39 27 4
gpt4 key购买 nike

在 Oracle 查询方面需要帮助

要求:

我在一个表中有 5 行假设 ID = 1、2、3、4、5

要求用户可以将任何值作为输入传递,如果该值不在表中,则查询应返回不存在的值。

例如:
1. 如果用户传递 9 那么 Oracle 查询应该返回输出为 9
2. 如果用户传递 1,2,10,那么 Oracle 查询应该返回 10 的输出

因为上例中的 9 和 10 不在表中。

我正在使用以下查询但没有得到结果。

SELECT ID
FROM TABLE_NAME WHERE ID NOT IN
(SELECT ID
FROM TABLE_NAME where ID NOT in (1,2,10))

最佳答案

create table z (id number);
Table created.

SQL> insert into z values (1);
1 row created.
SQL> insert into z values (2);
1 row created.
SQL> insert into z values (3);
1 row created.
SQL> insert into z values (4);
1 row created.
SQL> insert into z values (5);
1 row created.

SQL> select 10 id from dual
2 minus
3 select id from z;

ID
----------
10

关于sql - 查询输出表中不存在的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5750886/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com