PL/SQL可选哪里

Mau*_*dez 5 sql oracle plsql

嘿,我在PL/SQL中有这个查询:

--Ver todos los atributos de las OL de una OS.
SELECT attr.swspattrdataid attr_data_id,
       att.swname attribute_swname,
       attr.swvalue attr_data_swvalue
  FROM sw_sp_attr_data attr, 
       sw_sp_attribute att
 WHERE swobjectid IN (SELECT swsporderlineid
                        FROM sw_sp_order_line
                       WHERE swsporderid = 21444963 --Orden 
                       **AND swsporderlineid = a_number**
                     );
   AND att.swspattributeid = attr.swspattributeid
 --AND att.swname LIKE '%%'                          --Filtrar por nombre
Run Code Online (Sandbox Code Playgroud)

我需要让**之间的AND过滤器是可选的,所以无论我在那里放一个数字,查询都运行正常,这是可行的吗?

谢谢!

a_h*_*ame 7

使用默认值NULL声明参数.因此,如果它没有传递给过程,它将自动为null.

然后将条件更改为:

AND(a_number IS NULL或swsporderlineid = a_number)