且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以在一个查询中执行mysql选择,更新和删除吗?

更新时间:2023-01-30 15:34:17

您不能减少查询的数量-它们都做不同的事情-但您可以减少往返数据库的次数和解析的次数通过将它们全部包装为PLSQL函数.

You can't reduce the number of queries - they all do different things - but you could reduce the number of round trips to the database and the number of parses by wrapping it all as a PLSQL function.

但是,删除数据后,您将无法选择数据.....但请考虑:

However you can't select the data after you've deleted it.....but consider:

CREATE PROCEDURE s_u_d(a)
BEGIN

UPDATE tab_x SET tab_x.avalue=1 WHERE tab_x.another=a;

DELETE FROM tab_y WHERE tab_y.avalue=a;

SELECT * 
FROM tab_x
WHERE tab_x.another=a;

END;

NB-您还可以在同一过程中运行多个选择,并处理多个不同形状的结果集,例如请参阅本页

NB - you can also run multiple selects in the same procedure and handle multiple, different shaped result sets, e.g. see this page