2

我有大量的 DBF 文件(大约 1100 个)需要为客户分析。每个文件包含一个表。我需要对每个表执行查询,将结果复制到一个大的结果表中(它将保存所有文件的结果),然后转到下一个 DBF 文件。最后,我需要以以后可以操作的格式保存结果表。有谁知道一种脚本语言可以让我轻松做到这一点?

有一些注意事项: 1.) 我需要在 Vista 中工作的东西(在 DOS、python 或 GNU Octave 中运行的东西也可以)。2.) 我不是数据库管理员,但我确实有相当好的编程技能。3.) 我只有基本的 SQL 工作知识。我可以编写查询,我的问题是打开 DBF 文件并保存结果。4.) 我实际上已经使用 MS Access 完成了这项工作,但这是一个混乱的解决方案。所以我正在寻找不使用 Access 的东西。

我一直在阅读各种 SQL 脚本语言。我见过的大多数网站都涉及服务器、建立关系、安全性和所有这些事情。这些问题远远超出了我的理解,也不是我关心的问题。我只想查询这些文件,得到我的结果,然后出去。有没有什么东西对初学者来说很容易获得,但功能却非常强大?

任何帮助将非常感激。

4

3 回答 3

1

我写了一个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)
于 2011-07-15T15:48:43.320 回答
1

我的第一选择是Visual FoxPro。它本机处理 .dbf 文件,具有交互式环境并提供 SQL SELECT 功能。SELECT 语句有一个 INTO 子句,它将查询结果发送到另一个表。某些类型的 MSDN 订阅包括 DVD 上的 FoxPro,并可以从 MSDN 下载。

dBASE也可用。

如有必要,.dbf 文件结构很容易用代码操作。过去,我不得不编写代码来修改 C 和 Delphi 中的 .dbf 文件。这不过是一个下午的工作。Google 代码搜索可能会为任何主要编程语言生成与 .dbf 相关的代码。MSDN上记录了 .dbf 文件格式和相关文件格式。

于 2009-08-11T05:55:05.413 回答
1

我会用 SSIS 做到这一点。在 SSIS 中循环和数据转换相当容易。

于 2009-08-11T04:45:58.733 回答