4、oracle迁移到postgres-oracle中使用的`decode`函数使用`case when`统一语法

站着说话不腰疼 / 2023-08-23 / 原文

目录
  • oracle迁移到postgres-oracle中使用的decode函数使用case when统一语法
    • 1、oracle的decode语法
    • 2、postgres的case when

oracle迁移到postgres-oracle中使用的decode函数使用case when统一语法

oracle中也有使用case when语法,使用decode函数比较简洁。

1、oracle的decode语法

匹配stu_type1的值的班级为优秀班级

select 
decode(stu_type,'1','优秀班级','非优秀班级') 
from sys_stu;

2、postgres的case when

select 
(case when stu_type == '1' then '优秀班级' else '非优秀班级' end )
from sys_stu;