简体   繁体   English

Excel 2016 Power Query-从Oracle数据字典获取数据

[英]Excel 2016 Power Query - Get data from Oracle data dictionary

I've got an Excel 2016 spreadsheet set up with an Oracle db data source and I already have several queries set up in PowerQuery to get data from the tables in a specific schema and all is working well. 我已经建立了一个使用Oracle db数据源的Excel 2016电子表格,并且我已经在PowerQuery中设置了几个查询,以从特定模式中的表中获取数据,并且一切正常。

I now need to get some data from the data dictionary - I need to find the name of a trigger associated with a specific table in the schema - so I've set up a query to try to get data from user_triggers, but so far I've not been able to get it to work. 现在,我需要从数据字典中获取一些数据-我需要找到与架构中的特定表相关联的触发器的名称-因此,我已经建立了一个查询以尝试从user_triggers中获取数据,但是到目前为止一直无法使它正常工作。

This is the query I have set up so far (SourceTableName is a reference to a named cell in the sheet to get the table name) : 这是我到目前为止已设置的查询(SourceTableName是对工作表中命名单元格的引用,以获取表名):

let
    STN = Excel.CurrentWorkbook(){[Name="SourceTableName"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(STN,{{"Column1", type text}}),
    table_name = #"Changed Type"{0}[Column1],
    Source = Oracle.Database("MY_DB", [HierarchicalNavigation=true]),
    Schema = Source{[Schema="MY_SCHEMA"]}[Data],
    USER_TRIGGERS = Schema{[Name="USER_TRIGGERS"]}[Data]
in
    USER_TRIGGERS

This works perfectly fine for the other queries I already have set up as long as the table name is one of the tables in the schema, but referring to a data dictionary view as in the above example doesn't seem to work. 只要表名是模式中的表之一,这对于我已经设置的其他查询来说就可以很好地工作,但是如上例中那样引用数据字典视图似乎无效。

The error I get when trying to run the this query is: 我在尝试运行此查询时遇到的错误是:

Expression.Error: The key didn't match any rows in the table. Expression.Error:键与表中的任何行都不匹配。 Details: Key=Record Table=Table 详细信息:键=记录表=表

Does anyone know if it's actually possible to get data from the data dictionary using powerquery and if it is what do I need to change to get it to work? 有谁知道实际上是否可以使用powerquery从数据字典中获取数据,以及是否需要更改才能使其正常工作?

Thanks in advance for any help with this! 在此先感谢您的任何帮助!

Cheers, Dave 干杯,戴夫

I've figured it out! 我知道了! Answering my own question in case it's useful for anyone else in the future 回答我自己的问题,以防将来对其他人有用

It's actually possible to specify an SQL query directly in the db connection line and you can include variable names from other parts of the query in the SQL, like so: 实际上,可以直接在db连接行中指定SQL查询,并且您可以在SQL中将查询其他部分的变量名包括在内,如下所示:

let
    STN = Excel.CurrentWorkbook(){[Name="SourceTableName"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(STN,{{"Column1", type text}}),
    table_name = #"Changed Type"{0}[Column1],
    upper_tn = Text.Upper(table_name),
    Triggers = Oracle.Database("MY_DB", [HierarchicalNavigation=true, Query="select trigger_name from user_triggers where table_name = '" & upper_tn & "'"])
in
    Triggers

Using the SQL query directly in this way seems to work fine for data dictionary views :) 以这种方式直接使用SQL查询似乎可以很好地用于数据字典视图:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM