SAK }‘ŠÙ

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

PostgreSQL •Ò15 - “ÁŽêŠÖ”A‘½d”»’èAƒkƒ‹”»’èAƒkƒ‹”äŠrAcaseAnullif

¡‘½d”»’è

  EOracle ‚Æ“¯‚¶‚悤‚É case ‚ªŽg‚¦‚é‚Ì‚Å”ñí‚É‹­—Í‚Å‚ ‚éB
    ®AOracle ‚ÅŒ¾‚¤ decode ‚Í PostgreSQL ‚Å‚Í encode ‚ƃZƒbƒg‚Ì•Ê‚Ì
    ŠÖ”‚É‚È‚Á‚Ä‚¢‚é‚Ì‚Å’ˆÓ‚·‚éB

select key,
  case
    when key = 'a001' then 'aaa'
    when key = 'b002' then 'bbb'
    when key = 'c003' then 'ccc'
    else 'xxx'
  end
  from testm
;

   key    | case
----------+------
 a001     | aaa
 a011     | xxx
 b002     | bbb
 c003     | ccc

select key,
  case key
    when 'a001' then 'aaa'
    when 'b002' then 'bbb'
    when 'c003' then 'ccc'
    else 'xxx'
  end
  from testm
;

select key,
  case key
    when 'a001' then (select b.key from test2m b where b.code1 = a.key)
    when 'b002' then 'bbb'
    when 'c003' then 'ccc'
    else 'xxx'
  end
  from testm a
;

   key    |   case
----------+----------
 a001     | abc01
 a011     | xxx
 b002     | bbb
 c003     | ccc

¡ƒkƒ‹”»’è

  Ecoalesce() ŠÖ”‚ÍAʼn‚Ì null ‚Å‚È‚¢ƒf[ƒ^‚ð•Ô‚·B

select coalesce(null, 'abc', 'def');

 case
------
 abc

¡ƒkƒ‹”äŠr

  Enullif() ŠÖ”‚ÍA“™‚µ‚¯‚ê‚Î null ‚ªA“™‚µ‚­‚È‚¯‚ê‚΃f[ƒ^1 ‚ª•Ô‚éB
    ŽŸ‚Ì—á‚ÍAnull ‚ª•Ô‚éB

select nullif('abc', 'abc');

 case
------

  EŽŸ‚Ì—á‚ÍA'abc' ‚ª•Ô‚éB

select nullif('abc', 'def') ;

 case
------
 abc

¡PostgreSQL •ÒAJAVA ServletAJSP •ÒŽ‘—¿
¡MySQL •ÒŽ‘—¿
¡SQL Šî‘b•ÒŽ‘—¿
¡SQL Šî‘bŽÀ’n•ÒŽ‘—¿
¡SQL ƒ`ƒ…[ƒjƒ“ƒO•ÒŽ‘—¿
¡Oracle PL/SQL •ÒŽ‘—¿
| VB | SQL | Perl | PHP | ASP | JSP | C | PC | HP | FAQ | ƒtƒŠ[ƒ\ƒtƒg |

SAK Streets ƒƒCƒ“ƒXƒgƒŠ[ƒg }‘ŠÙEƒJƒtƒF ˆê—— SAK Streets ŒŸõ



Copyright (C) 1999-2024 Y.SAK