从Excel执行Oracle Query(DML)

时间:2009-10-27 23:34:50

标签: sql oracle excel

我可以将现有表/视图的结果链接到Excel电子表格(通过从ODBC向导的“选择数据库和表”窗口中选择表,但是我想改为执行原始查询。 / p>

我想基于单元格值生成查询(作为字符串)。然后,用户可以手动“刷新”数据表,该数据表将当前字符串发送到Oracle并返回结果。

有没有办法将原始查询(DML)的结果链接到Excel电子表格?

3 个答案:

答案 0 :(得分:3)

我在博客herehere中有过一次(好吧,两次)。也许,这对你有所帮助。

答案 1 :(得分:2)

将数据库表链接到电子表格后,您可以使用宏执行此操作。假设您的链接表在单元格A1中开始:

' Build your query string - using whatever cell values you need
sqlQuery = "select * from myTable"

' Get the cursor on the top left cell of the existing linked table
Range("A1").Select

' Set the CommandText of that QueryTable to your new query and refresh it
With Selection.QueryTable
    .CommandText = sqlQuery
    .Refresh BackgroundQuery:=False
End With

尝试一下......

答案 2 :(得分:0)

您必须设置查询,然后在查询中创建一个参数来限制结果集。通常,您可以使用该查询填充新工作表。系统将提示您为参数添加值。将其设置为单元格引用,并选中复选框以自动重新查询该单元格是否更改。

相关问题