从未填充的表中选择 - IS NULL不起作用

时间:2014-09-12 21:47:29

标签: sql oracle not-exists isnullorempty

SQL,Oracle - 如果Status ='SO'或Status为Null,我试图从表中提取记录。 如果Status ='SO',我只能检索记录,因为如果它是Null,则意味着我从中取出的地方是无人居住的 - 没有任何东西供它查看。这几乎就像要求某人告诉他们是否在书中找到一个空白页面,但由于它是空白的,所以确实没有可以查看的页面,但该书仍然存在。如果页面上有“SO”,你就可以找到它。

DGMR_DEGS_CODE可以是PN,AW,SO或空白(不存在)

Select distinct sp.sprite_id as "ID", SP.SPRITE_LAST_NAME as "Last", SP.SPRITE_FIRST_NAME as "First", 
sh.TRAN_REQUEST_DATE as "Request Date",
NL.DGMR_DEGS_CODE as "Null Dgr",
SV.RSTS_ENRL as "Enrolled?",
sf.stcr_term_code as "Term",
sysdate as "Current Date"


from Sprite SP

join TRAN SH 
on sp.sprite_pid = sh.tran_pid 

full outer join DGMR NL
on NL.DGMR_pid = sp.sprite_pid

join stcr sf
on sp.sprite_pid = sf.stcr_pid
JOIN stvrsts SV 
on SF.STCR_RSTS_CODE = SV.STVTS_CODE 

where 
Sp.sprite_change_ind is null

and sh.TRAN_REQUEST_DATE between sysdate-1 and sysdate
and (sf.stcr_term_code = '201401' or sf.stcr_term_code = '201402')
AND SV.RSTS_ENRL = 'Y'
AND (NL.DGMR_DEGS_CODE is null or NL.DGMR_DEGS_CODE = 'SO' )
--and (length(NL.DGMR_DEGS_CODE)=0 or NL.DGMR_DEGS_CODE = 'SO' )
--and NL.DGMR_DEGS_CODE <> 'PN'
--and NL.DGMR_DEGS_CODE <> 'AW'
--and NL.DGMR_DEGS_CODE <> 'PN' and NL.DGMR_DEGS_CODE <> 'AW'

如果我没有包含NL.DGMR_DEGS_CODE的标准,它会选择25条记录:这些记录包括SO,AW,PN和NULL记录!! 如果我包含条件,它将不会拉出NULL记录。要求SO或Null只选择SO记录。

1 个答案:

答案 0 :(得分:0)

没有人回答这个问题,所以我想为其他可能遇到类似问题的人提供答案。 这个字段是&#34;不是空的&#34;所以我必须做一个TRIM以使其为空。

我替换了最后一行。

where 
Sp.sprite_change_ind is null
and sh.TRAN_REQUEST_DATE between sysdate-1 and sysdate
and (sf.stcr_term_code = '201401' or sf.stcr_term_code = '201402')
AND SV.RSTS_ENRL = 'Y'
and trim(NL.DGMR_DEGS_CODE) is null
相关问题