我想获取已删除的记录数的行数。以下查询返回将受影响的记录数,但
SELECT COUNT(*) FROM suppliers
WHERE EXISTS
( SELECT customers.customer_name
FROM customers
WHERE customers.customer_id = suppliers.supplier_id
AND customer_id > 25 );
我需要这样的东西,删除行后,我可以显示前端已删除的记录数。
SELECT COUNT(*) FROM suppliers(
DELETE from supplier(
WHERE EXISTS
( SELECT customers.customer_name
FROM customers
WHERE customers.customer_id = suppliers.supplier_id
AND customer_id > 25 ));
我不想两次运行查询,一次是获取要删除的记录数,如果大于0,则运行第二次查询删除记录。
答案 0 :(得分:5)
您可以使用RETURNING INTO
子句来删除所有行 - 然后计算这些行。
PL / SQL代码中更简单的计数方法是SQL%ROWCOUNT
。像这样:
BEGIN
DELETE from supplier(
WHERE EXISTS
( SELECT customers.customer_name
FROM customers
WHERE customers.customer_id = suppliers.supplier_id
AND customer_id > 25 );
dbms_output.put_line(SQL%ROWCOUNT);
END;
答案 1 :(得分:-2)
你可以使用 声明@countDelete int 设置nocount 删除表名 哪里.. 选择@@ ROWCOUNT