Decode函数是oracle/SQL提供的特有函数计算方式,语法:DECODE(value,if1,then1,if2,then2,if3,then3,...else),通常我们在写语句的时候可能会遇到多种Case,一般的处理方法是通过Case when或者if...then....else的方式实现,但是如果用decode函数,就显得简洁和方便很多,举例:

假设在table1 中有一列company的值122和123,我们可以通过以下方式,将两个值以两列的形式显示出来:

SELECT 
DECODE(company, '122', '122', ''),
DECODE(company, '123', '123', ''),

sum(field1)

FROM table1

上述语句表示,在列company中,表示if 122 then 122 else为空;同样if 123 then 123 else为空

相关文章:

  • 2022-12-23
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
  • 2022-02-13
  • 2022-12-23
  • 2021-10-30
猜你喜欢
  • 2021-12-26
  • 2021-06-19
  • 2021-12-14
  • 2021-06-18
  • 2021-11-05
相关资源
相似解决方案