LNNVL函数使用

转载自:http://blog.csdn.net/stevendbaguo/article/details/12611189

显示那些佣金比例(commision)不大于20%或者为NULL的员工的信息。

CREATE TABLE plch_employees
(
    employee_id      INTEGER PRIMARY KEY
,  last_name        VARCHAR2 (100)
,  salary           NUMBER
,  commission_pct   NUMBER
);
INSERT INTO plch_employees   VALUES (100,  'Picasso',  1000000 ,  .3);
INSERT INTO plch_employees VALUES (200,  'Mondrian',  1000000,  .15);
INSERT INTO plch_employeesVALUES (300,  'O''Keefe',  1000000,  NULL);
COMMIT;

SQL> SELECT last_name,e.salary,e.commission_pct
       FROM plch_employees e
      WHERE e.commission_pct <= .2
         OR e.commission_pct IS NULL;
LAST_NAME           SALARY COMMISSION_PCT
--------------- ---------- --------------
Mondrian           1000000            .15
O'Keefe            1000000


SQL> SELECT last_name,e.salary,e.commission_pct
       FROM plch_employees e
     WHERE LNNVL (e.commission_pct > .2);
LAST_NAME           SALARY COMMISSION_PCT
--------------- ---------- --------------
Mondrian           1000000            .15
O'Keefe            1000000


LNNVL 解释:

LNNVL provides a concise way to evaluate a condition when one or both operands of the condition may be null. The function can be used only in the WHERE clause of a query. It takes as an argument a condition and returns TRUE if the condition is FALSE or UNKNOWN and FALSE if the condition is TRUELNNVL can be used anywhere a scalar expression can appear, even in contexts where the IS [NOTNULLAND, or OR conditions are not valid but would otherwise be required to account for potential nulls. Oracle Database sometimes uses the LNNVL function internally in this way to rewrite NOT IN conditions as NOT EXISTS conditions. In such cases, output from EXPLAIN PLAN shows this operation in the plan table output. The condition can evaluate any scalar values but cannot be a compound condition containing ANDOR, or BETWEEN.

The table that follows shows what LNNVL returns given that a = 2 and b is null.

ConditionTruth of ConditionLNNVL Return Value
a = 1FALSETRUE
a = 2TRUEFALSE
IS NULLFALSETRUE
b = 1UNKNOWNTRUE
IS NULLTRUEFALSE
a = bUNKNOWNTRUE

      大致的意思是:lnnvl用于某个语句的where子句中的条件,如果条件为true就返回false;如果条件为UNKNOWN或者false就返回true。该函数不能用于复合条件如AND, OR, or BETWEEN中。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值