create or replace procedure aaa(str in varchar2) is sql varchar2; begin if str is null or str="" then sql:='select * from table where....'; else sql:='select * from table where ...'; end if execute immediate sql; end aaa;
如果你的条件是固定的就可以。 比如现有字段A,B,C可做为条件 select * from tab where ( A > 参数A OR 参数A IS NULL ) AND ( B = 参数B OR 参数B IS NULL ) AND ( C = 参数C OR 参数C IS NULL ) 当参数A带入值为NULL时,表明参数A不使用。
is
sql varchar2;
begin
if str is null or str="" then
sql:='select * from table where....';
else
sql:='select * from table where ...';
end if
execute immediate sql;
end aaa;
比如现有字段A,B,C可做为条件
select * from tab
where ( A > 参数A OR 参数A IS NULL )
AND ( B = 参数B OR 参数B IS NULL )
AND ( C = 参数C OR 参数C IS NULL )
当参数A带入值为NULL时,表明参数A不使用。