質問

select NVL(B.SEQID, A.LVL5_ID) LVL6_ID, NVL(B.NAME, ' ')  LVL6_NAME, A.LVL5_ID
FROM LVL5 A, ABC B WHERE A.LVL5_ID = B.LVL7

The above query is what defines a view in my system. Here I would like to know why the NVL was used.

The thing is that SEQID is a primary key column and cannot be null. so is there any need for NVL here?

can B.SEQID be null if no records satisfying the where clause can be found?(i know this doesnt make sense but I just had to ask)

役に立ちましたか?

解決

What your nvl function does is it replaces all null values it comes across in the B.SEQID with the value of A.LVL5_ID.

Stating that B.SEQID is a primary key makes this NVL useless in your query as a primary key can never contain a null value. However an unique key certainly can contain multiple null values.

If the where clause has no match whatsoever it will not return a null value but a "no rows selected" which is a feedback message.

他のヒント

A primary key constraint is a unique key constraint plus a not null constraint. So it ensures that the column underneath it, is mandatory. So you can happily remove the NVL.

Regards,
Rob.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top