mysql or与||的区别 希望能有简单的例子说明下。
想到网上搜索,结果基本不会

解决方案 »

  1.   

    没有区别。MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  2.   

    OR, || Logical OR. When both operands are non-NULL, the result is 1 if any operand is non-zero, and 0 otherwise. With a NULL operand, the result is 1 if the other operand is non-zero, and NULL otherwise. If both operands are NULL, the result is NULL. mysql> SELECT 1 || 1;
            -> 1
    mysql> SELECT 1 || 0;
            -> 1
    mysql> SELECT 0 || 0;
            -> 0
    mysql> SELECT 0 || NULL;
            -> NULL
    mysql> SELECT 1 || NULL;
            -> 1
      

  3.   


    在使用上,基本没有区别吧!看如下结果:
    select 1 or 1 , 1 || 1;
    -- 1, 1
    select 1 or 0, 1 || 0;
    -- 1, 1
    select 1 or null,1 || null;
    -- 1, 1
    select 0 or 0, 0 || 0;
    -- 0, 0