项目需要将原本的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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐