我有一大堆DBF文件(大约1100个),我需要为客户分析。每个文件都包含一个表。我需要对每个表进行查询,将结果复制到一个大的结果表中(该表将保存所有文件的结果),然后转到下一个DBF文件。最后,我需要将结果表保存为以后可以操作的格式。有谁知道有一种脚本语言可以让我轻松完成这个任务?
有几个注意事项:1.) 我需要一些能在Vista中运行的东西(在DOS、python或GNU Octave中运行的东西也可以)。我不是一个数据库管理员,但我有相当好的编程技能。3.) 我只有基本的SQL知识。我可以写查询,我的问题是打开DBF文件并保存结果。4.) 实际上我已经用MS Access完成了这个任务,但它是一个混乱的解决方案。所以我在寻找一些不用Access的东西。
我一直在阅读各种SQL的脚本语言。我看到的大多数网站都涉及到服务器、设置关系、安全等方面的问题。这些问题远远超出了我的理解范围,也不是我所关心的。我只想查询这些文件,得到结果,然后离开。有没有什么对初学者来说很容易上手,但又显著强大的东西?
任何帮助都将是非常感激的。
我会用SSIS来做这件事。循环和数据转换在SSIS中相当简单。
我写了一篇 python dbf模块 其中有非常基本的SQL支持。 然而,即使SQL不能满足你的需求,使用python语法查询dbf文件也很容易。
以下是一些例子。
import dbf
创建一个结果表并添加记录:
results = dbf.Table('results_table', 'name C(50); amount N(10, 4)')
record = results.append()
with record:
record.name = 'something'
record.amount = 99.928
# to open an existing table
table = dbf.Table('some_dbf_table').open()
# find all sales >= $10,000
records = table.pql("select * where sales >= 10000")
# find all transactions for customer names that start with Bob
records = table.pql("select * where customer.startswith('Bob')")
# nevermind thin sql veneer, just use python commands
records = table.find("sales >= 10000 and customer.startswith('Bob')")
# sum sales by customer
customer_sales = default_dict(int) # if customer not already seen, will default to 0
for record in table:
customer_sales[record.customer] += record.sales
# now add to results table and print them out
for name, total in sorted(customer_sales.items()):
result_record = results.append()
with result_record:
result_record.name = name
result_record.amount = total
print "%s: %s" % (name, total)