SAK }‘ŠÙ
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 •ÒŽ‘—¿