【发布时间】:2019-12-14 17:53:00
【问题描述】:
我只想在满足'if'条件时执行三个或更多删除语句。
我有这个查询,它有几行,每一行都有一个名为last_update_date 的列。看看:
SELECT PRODUCT_ATTR as CATEGORY,
product_attr_val as COD_CATEGORY,
qer.last_update_date
FROM qp_modifier qer
JOIN qp_list qar ON qar.list_header_id = qer.list_header_id
ORDER BY qer.last_update_date desc
我只想在last_update_date 的情况下执行这 3 个删除语句
从上面的查询等于实际的或实际上是前面的
天。
delete from TABLE_PRODUCTS where product_id like 'WAL%';
delete from TABLE_PRODUCTS where item_code like 'MAS%';
delete from TABLE_PRODUCTS where customer_class_code='K' and customer_number is null;
我正在考虑做这样的事情:
select max (last_update_date)
into v_date
from qp_modifier
然后写下这样的语句:
if v_date = sysdate or v_date = sysdate - 1 then
delete from TABLE_PRODUCTS where product_id like 'WAL%';
delete from TABLE_PRODUCTS where item_code like 'MAS%';
delete from TABLE_PRODUCTS where customer_class_code='K' and customer_number is null;
end if;
但这对我来说没有多大意义。
你会如何修改它?
【问题讨论】:
-
由于您显示的查询可能会返回多行,哪一行是提供比较日期的行?真的是最大吗?如果日期低于满足条件的最大值怎么办?在这种情况下会被忽略吗?
标签: sql oracle sql-delete