项目需要将原本的Oracle数据库换成了pg,之前写的一段SQL执行不通过了,原因是其中用到了两个函数instr和decode,在pg中不存在此种函数,便将原函数改造一番。以下将此次改造做记录;
原Oracle中函数:
select decode (aa.code_count , 0,'01083357','u2021012001)
from (
select count(1) code_count from table a where instr (a.codes,'01083357') > 0
)aa
pg中改造
select case when aa.code_count = 0 then '01083357' else 'u2021012001' end
from (select count(1) code_count from table a where strpos(a.codes,'01083357') > 0
) aa