我有一张mnesia表,让我们说employee
。我需要找到名称在EmployeeNameList = ["Erlich", "Richard", "Gilfoyle", "Dinesh"]
的所有员工记录。有没有办法使用mnesia:select
或其他功能?
答案 0 :(得分:1)
遵循Mnesia的文档 它可以按如下方式完成:
get_employees_by_name(NameList) ->
MatchHead = #employee{name = '$1', _ = '_'},
Result = '$_'
MatchSpec = [ { MatchHead, [{'=:=', '$1', Name}], [Result]} || Name <- NameList ],
F = fun() ->
mnesia:select(employee, MatchSpec)
end,
{atomic, Result} = mnesia:transaction(F),
Result.