1- Where子句

1.Between…And子句:

When using BETWEEN, make sure the first value is the lowest of the two values provided.    While "BETWEEN 1 AND 10" and "BETWEEN 10 AND 1" might seem logically equivalent, specifying the higher value first guarantees that your condition will always evaluate to FALSE
 
2. NULL关键字:
When working with NULL, the concept of equality does not apply; a column may be NULL, but it will never equal NULL.
 
Oracle doesn't complain if you mistakenly use the equality operator when evaluating for NULL,The following query will parse and execute but will never return rows:
    SELECT order_nbr, cust_nbr, sale_price, order_dt FROM cust_order WHERE ship_dt = NULL;
 
NVL substitutes a specified value for columns that are NULL, as in:
    SELECT fname, lname, manager_emp_id  FROM employee
     WHERE NVL(manager_emp_id, -999) != 11;
 
In this example, the value -999 is substituted for all NULL values, which, since -999 is never equal to 11, guarantees that all rows whose manager_emp_id column is NULL will be included in the result set. Thus, all employees whose manager_emp_id column is NULL or is not NULL and has a value other than 11 will be retrieved by the query.
 
3.如何充分利用 WHERE子句:
 here are a few tips to help you make the most of your WHERE clauses:
 A. Check your join conditions carefully. Make sure that each data set in the FROM clause  is properly joined. Keep in mind that some joins require multiple conditions. See    Chapter 3 for more information.
 
B. Avoid unnecessary joins. Just because two data sets in your FROM clause contain the    same column does not necessitate a join condition be added to your WHERE clause. In   some designs, redundant data has been propagated to multiple tables through a process     called denormalization.
C. Use parentheses. Oracle maintains both operator precedence and condition precedence,         meaning there are clearly defined rules for the order in which things will be evaluated
      but the safest route for you and for those who will later maintain your code is    to  dictate evaluation order using parentheses. For operators, specifying    (5 * p.inventory_qty) + 2 rather than 5 * p.inventory_qty + 2 makes the order in  which the operations should be performed clear. For conditions, use parentheses any   time the OR operator is employed. 
 
D.Handle NULLs properly. After writing your WHERE clause, inspect each condition with  respect to its ability to properly handle NULL values. Take the time to understand  the table definitions in your database so that you know which columns allow NULLs.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值