-1
所有行表中的我有這樣的表:更新在二郎
-record(person, {id, firstname, lastname, address}).
例如該表包含此值:
2 alen dumas paris
5 franco mocci parma
3 ali othmani london
現在我有可變Key
包含該值10
我想在erlang中開發一個函數,它將修改表person
的所有id
這個id
的新值將是前值+的Key
值意味着該表的人會變成這個樣子
12 alen dumas paris
15 franco mocci parma
13 ali othmani london
這意味着每個id
將由10被添加(是的的Key
值):(2 + 10)(5 + 10)(3 + 10)
我嘗試與您的代碼:
testmodify()->
Key=22,
[ P#person{id=P#person.id+Key} || P <- Persons ].
,但我有這個錯誤在sysntax:variable Persons is unbound
我嘗試解決此問題,此代碼:
testmodify()->
Key=22,
[ P#person{id=P#person.id+Key} || P <- mnesia:table(person) ].
但我有此錯誤:
1> model:testmodify().
** exception error: no function clause matching
model:'-testmodify/0-lc$^0/1-0-'({qlc_handle,
{qlc_table,
#Fun<mnesia.20.112329951>,
true,
#Fun<mnesia.21.62211129>,
#Fun<mnesia.22.75429001>,
#Fun<mnesia.23.26336897>,
#Fun<mnesia.26.62819299>,
#Fun<mnesia.25.51075493>,
#Fun<mnesia.24.47804912>,
'=:=',undefined,
no_match_spec}})
我認爲爲了更新所有表格人物我們應該在循環中工作 – 2013-02-20 10:35:14
@aliothmani:我不知道你是指Mnesia表格。上述解決方案適用於一個擁有'person'記錄列表的Person變量。 – 2013-02-20 21:25:14