DB/Oracle/PLSQL/ʬ

Top / DB / Oracle / PLSQL / ʬ

ܼ

ˤäʬ롣 IF ʸ CASE ʸ


IF ʸ

IF ʸˤʬۤθȰʤΤۤɤΤΤǤʤʤȤݡ

  • IF ʸε
    declare
        hoge number := 10;
    begin
        -- IF ʸ
        if hoge > 100 then
            ...
        -- ʣξ ELSIF ¤٤
        elsif hoge > 50 then
            ...
        -- ٤ƹפʤä餳¹
        else
            ...
        -- IF ʸλ
        end if;
    end;
    

CASE ʸ

CASE ʸˤʬۤθȰʤΤۤɤΤΤǤʤʤȤݡ

CASE CASE ʸ餷ͤ˻ȤΤ CASE ʬ˻ȤΤ CASE ʸ

CASE

ͤȤ˻Ȥ

  • CASE
    declare
        hoge number := 1;
        fuga varchar2(10);
    begin
        -- hoge ͤ˱ fuga ͤѤ
        fuga := case hoge
            when 1 then 'foo'
            when 2 then 'bar'
            else 'baz'
        end; 
    
        -- ̤νwhen ˤϥ֤֡ͤȽ꼰ͳ˽񤱤
        fuga := case
            when hoge = 1 then 'foo'
            when hoge = 2 then 'bar'
            else 'baz'
        end; 
    end;
    

CASE ʸ

IF ʸƱȤ CASE ʸǤ⤫롣֤ IF ʸΤŪ

  • CASE ʸ
    declare
        hoge number := 1;
    begin
        case hoge
            when 1 then
                ...
            when 2 then
                ...
            else
                ...
        end case;
    end;
    

NULL ͤΰ

NULL ͤȤñӡʤꡢʤꡢʤɡˤϾ˷̤ NULL ˤʤ롣TRUE Ǥ FALSE Ǥʤ NULL

黻ξϤäʣ

NULL ˤʤä硢ξξμ¹ʸϼ¹Ԥʤ

NULL ñ

羮ӡӤʤɤñӤξ硢̤Ͼ NULL ˤʤ롣IF ʸ CASE ʸȽ̤ NULL ä硢ʬϼ¹ԤʤξǤϰ FALSE Ʊ

  • NULL
    declare
        hoge number;
    begin
        -- hoge  NULL 
        if hoge > 100 then
            -- ϼ¹Ԥʤ
            ...
        else
            -- ξϤ¹Ԥ
            ...
        end if;
    end;
    

NULL 黻

TRUE FALSE NULL Ȥ AND Ȥ OR DZ黻ɤʤΤȤá

  • AND 黻
    ANDTFN
    TTFN
    FFFF
    NNFN
  • OR 黻
    ORTFN
    TTTT
    FTFN
    NTNN
  • NOT 黻
    NOT
    TF
    FT
    NN

Ūʹͤϰʲ̤ꡣ

  • AND Ǥ FALSE ͥ衣OR Ǥ TRUE ͥ
  • AND ξ TRUE ΤȤΤ TRUE
  • OR ξ FALSE ΤȤΤ FALSE

Last-modified: 2011-11-08 () 10:39:12 (2361d)