我想有这样的事情宏替换在SQL
condition := case {SOME_VAR}
when 1 then 'tbl.id = 3 and tbl.code = 6'
when 2 then 'tbl.id != 4 and tbl.code = 5'
when 3 then 'tbl.id = 2 and tbl.code != 7'
else '1 = 1'
end
select
*
from
some_table tbl
where
$condition
;
和$condition
将被相应的SQL代码从select
上述条款所取代,有点像宏替换。这在Oracle中可能吗?
你可以运行一些动态SQL。 –
构建时或运行时“宏”更换? –
这些条件只包含静态值,所以如果在编译时替换宏就足够了。 – tuxx