【发布时间】:2017-11-09 02:21:45
【问题描述】:
这里是 Oracle SQL 新手。
我有三列包含很多空值。我正在尝试过滤掉所有三列都具有空值的所有行。
但是,它仍然为下面的合并公式返回空值。有任何想法吗?
select name, city, attribute1, attribute2, attribute3
from table1
where coalesce(attribute1,attribute2,attribute3) is not null
我尝试使用 CONCAT 公式做同样的事情,但得到了相同的结果。当我在 CONCAT 公式中使用 nvl(attribute1,'None') 时,我能够让它工作,但我希望有更简单的方法。
编辑:我仍然没有得到正确的结果。我在下面发布完整的查询。也许我的语法还有另一个错误。
select
gjb.name "Batch",
gjl.attribute_category,
gjh.name,
gjh.created_by,
gjh.period_name,
gcc.segment1,
gcc.segment2,
gcc.segment3,
gcc.segment4,
gcc.segment5,
gcc.segment6,
gjl.attribute1,
gjl.attribute2,
gjl.attribute3,
gjl.attribute4,
gjl.attribute5,
gjl.attribute6,
gjl.attribute7,
gjl.attribute8,
gjl.attribute9,
gjl.attribute10,
nvl(gjl.entered_dr,0)-nvl(entered_cr,0) "Amt"
from gl_je_lines gjl, gl_je_headers gjh, gl_je_batches gjb, gl_code_combinations gcc
where not (gjl.attribute1 is null
and gjl.attribute2 is null
and gjl.attribute3 is null
and gjl.attribute4 is null
and gjl.attribute5 is null
and gjl.attribute6 is null
and gjl.attribute7 is null
and gjl.attribute8 is null
and gjl.attribute9 is null
and gjl.attribute10 is null)
and gjl.je_header_id = gjh.je_header_id
and gjh.je_batch_id = gjb.je_batch_id
and gcc.code_combination_id = gjl.code_combination_id
and gjb.je_source in ('Manual','Spreadsheet')
and gjh.period_name in (:Period)
and upper(gjb.name) not like '%BEGBAL%'
and gjl.status = 'P'
【问题讨论】:
-
这应该行得通,你真的用这个语句得到所有 3 个都为 null 的结果吗?
-
@Ab Bennet 有正确的想法。通过使用合并,您正在破坏优化器使用约束和索引的能力。至于为什么您的代码不起作用,请提供一个小样本数据集来说明此问题。
-
我和@Hogan 在一起——这应该可以。您确定 JE Lines DFF 列中没有空格吗?各栏的内容因期刊来源而异 - 电子表格几乎可以导入任何内容
-
@BrianLeach 我编辑了我的原始帖子。我仍然收到错误消息。有任何想法吗?感谢您的帮助。
-
是问题所在,因为您已将过滤条件扩展到属性 4 之后。这是想要的结果吗?上面的 where not (...) 只会返回至少填写了一个属性的行。如果填写了属性 4 但 1 到 3 不是该行,仍将返回该行。