> Erlang中文手册 > match_delete/2 根据匹配模式删除表里的对象数据

ets:match_delete/2

根据匹配模式删除表里的对象数据

用法:

match_delete(Tab, Pattern) -> true
-spec match_delete(Tab, Pattern) -> 'true' when
      Tab :: tab(),
      Pattern :: match_pattern().

match_delete(Table, Pattern) ->
    ets:select_delete(Table, [{Pattern,[],[true]}]),
    true.

删除在表 Tab 里符合匹配模式 Pattern 的所有对象数据。更多匹配模式描述可看 ets:match/2 里的介绍。

Tab = ets:new(ets_tab, [named_table, bag]),
ets:insert(Tab, [{rufsen, dog, 7}, {brunte, horse, 5}, {ludde, dog, 5}]),
ets:match_delete(Tab, {'_', dog, '$1'}).
Tab = ets:new(ets_tab, [named_table, bag]),
ets:insert(Tab, [{rufsen, dog, 7}, {brunte, horse, 5}, {ludde, dog, 5}]),
ets:match_delete(Tab, {'_', dog, '$1'}),
ets:match(Tab, '$1').