

在SQL中能否用字符串替换查寻返回的某个数值?例如,
select emp_id from emp_tb
returns
1
2
3
Would it be possible to replace 1 with John and 2 with Mary to give the end result of
John
Mary
3
发表于04年8月13日
是的, 如果你愿意,你可以用整个[syn: batch, deal, flock, good deal, great deal, hatful, heap, lot, mass, mess, mickle, mint, muckle, peck, pile, plenty, pot, quite a little, sight, slew, spate, stack, tidy sum, wad,
whole lot, whole slew]填满SELECT语句。
select case emp_id
when 1 then 'John'
when 2 then 'Mary'
else cast(emp_id as char(4))
end as emp_string
from emp_tb
注意有些数据库可能需要CAST, 有些可能不需要, 需要在CASE内的第一个定义表达式中设定CASE表达式的数据类型。