gpt4 book ai didi

sql - Delphi null 参数在哪里

转载 作者:行者123 更新时间:2023-12-03 18:18:02 25 4
gpt4 key购买 nike

我有两个 ZQuery - master 和 details,通过 detail.DataSource 和 sql 参数链接。

主 sql:

select key1, key2 from list

详细信息sql:

select * from list where key1=:key1 and key2=:key2

问题是,当 key2 为 null 时,详细信息为空!

如何在此处获取参数以使用空链接字段?

最佳答案

SQL 使用三值逻辑。您所有的 bool 值都可以有 3 种状态:true、false 和 null(未定义)。 null 是一个假值,是一个 where 子句。您可以查找此逻辑的 thruth 表 here .

在表达式 key1=:key1 和 key2=:key2 中,如果任何列具有空值,则整个表达式的计算结果为空。

如果您的 DBMS 支持,我建议您使用 IS DISTINCT FROMIS NOT DISTINCT FROM 运算符。它们只能返回 true 或 false,即使它们的参数之一为 null。

基本上 IS NOT DISTINCT FROM 是更多 readable and standard x = y OR (x IS NULL AND y IS NULL) 的书写方式。

关于sql - Delphi null 参数在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45936375/

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