Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Ruby 中有没有办法通过列名而不是列位置来访问结果中的数据?
例如,如果我有一个名为 的列name,我想做类似的事情:
name
result = db.query "select * from employees" row = result.fetch_row puts row['name']
而不是手动查找表模式,确定这name是第三列,然后执行:
puts row[2]
我在谷歌上搜索过,似乎找不到合适的搜索词组!
谢谢!
result.each_hash do |row| puts row['name'] end