如何缩短数据库表的 DELETE 语句?



你有没有办法把它放在一个语句中?

DELETE e_worklist where wbs_element  = '00000000000000000054TTO'.
DELETE e_worklist where wbs_element  = '00000000000000000056TTO'.
DELETE e_worklist where wbs_element  = '00000000000000000055TTO'.
DELETE e_worklist where wbs_element  = '00000000000000000261TTO'.
DELETE e_worklist where wbs_element  = '00000000000000000263TTO'.
DELETE e_worklist where wbs_element  = '00000000000000000262TTO'.

上面提出的带有IN的答案仅对数据库表有效:

从wbs_element所在的e_worklist中删除( '

000000000000000000054TTO', '0000000000000000056TTO', '00000000000000000055TTO' (。

在您的示例中,您放置了内部表语句,对于它们,建议的IN语法对于文本无效。它仅适用于选择表/范围,这些表/范围也需要正确填充。所以你不能只是将文字包装到IN子句中,你需要像这样做:

ws_wbs-sign   = 'I'. 
ws_wbs-option = 'EQ'. 
ws_wbs-low    = '00000000000000000054TTO'. 
APPEND ws_wbs TO rt_wbs. 
DELETE e_worklist WHERE wbs_element IN rt_wbs.

这确实很麻烦,不会给你带来简洁。

但是,由于您的模式是单调的,您可以带来您的幻想并使用正则表达式,例如:

DELETE e_worklist WHERE wbs_element CP '00000000000000000*TTO'.

再给你一个提示。没有任何范围表,您还可以使用FILTEREXCEPT实现更好的陈述。文档在这里。

您必须复制或制作e_worklist作为sorted table

data: 
ls_worklist like line of e_worklist,
****Ajust your key if necessary
lts_worklist like sorted table of ls_worklist with unique key table_line,  
lth_wbs_element like hashed table of ls_worklist-wbs_element with unique key table_line.
lts_worklist = e_worklist.
****Add your other values if necessary
lth_wbs_element = value #( ( |00000000000000000054TTO| ) ( |00000000000000000263TTO| ) ). 
e_worklist = filter #( lts_worklist except in lth_wbs_element where wbs_element = table_line ).

由于它是一个内部表,因此与数据库命令不同,因此减少 DELETE 命令的数量不会对性能产生实际影响。您可以通过以下方式使其更简洁一些:

DELETE e_worklist where wbs_element  =: '00000000000000000054TTO', 
'00000000000000000056TTO',
'00000000000000000055TTO',
'00000000000000000261TTO',
'00000000000000000263TTO',
'00000000000000000262TTO'.

相关内容

  • 没有找到相关文章

最新更新