简体   繁体   English

如何在Oracle中组织查询?

[英]How do I organize my queries in Oracle?

I have a base query made (Thanks Justin Cave!) 我做了一个基本查询(谢谢贾斯汀·凯夫!)

Now I have to use that query and join it to different tables and sub queries many times over to do checks against our data. 现在,我不得不多次使用该查询并将其连接到不同的表和子查询,以对我们的数据进行检查。 Additional queries are likely to be added in the future. 将来可能会添加其他查询。 So in the end there will be maybe two dozen checks for the data and the findings will be summarized in an SSRS report. 因此,最后可能会进行两打数据检查,并将结果汇​​总在SSRS报告中。 If this were in MSSQL, I would put the results of the queries into a temp table and finally run a select on the temp table. 如果在MSSQL中,则将查询结果放入临时表中,最后在临时表上运行select。 Doing as much research as possible I've decided that the best way would be to use the WITH clause and joining with the other temp tables and queries to get results, then Unionize all of the queries together to get my result. 经过尽可能多的研究,我决定最好的方法是使用WITH子句,并与其他临时表和查询联接以获取结果,然后将所有查询统一在一起以得到结果。 However this seems like it is going to be extremely messy and large. 但是,这似乎将变得极为混乱和庞大。 I'd use Global Temporary Tables, but they seem to be frowned upon in Oracle. 我会使用全局临时表,但在Oracle中似乎不赞成使用它们。 Perhaps you have a better method for modularizing and organizing this? 也许您有更好的方法来对此进行模块化和组织?

Per our licensing agreement we are not able to add new tables in oracle (so I am told), but we are able to add view, stored procedures and functions. 根据我们的许可协议,我们无法在oracle中添加新表(所以有人告诉我),但是我们可以添加视图,存储过程和函数。

Thanks in advance! 提前致谢!

If materialized views are not forbidden to use, you can use them to get all the advantages of a temp table. 如果不禁止使用实例化视图,则可以使用它们来获得临时表的所有优点。

But unless you need results of a sub-query in several different queries, you can just use as many independent sub-queries per query as you like, and operate on them as if these were tables. 但是除非您需要几个不同查询中的子查询结果,否则您可以根据需要在每个查询中使用尽可能多的独立子查询,并对它们进行操作就好像它们是表一样。 Most of the time you'll have pretty decent query plans. 大多数时候,您将拥有相当不错的查询计划。

Also, in my eyes, using a global temp table to speed up analysis 10x is worth it — as long as you don't expose sensitive data to someone not trusted. 另外,在我眼中,使用全局临时表将分析速度提高10倍是值得的-只要您不将敏感数据暴露给不信任的人即可。

Roll them all up into various stored procedures and enclose them in Oracle packages. 将它们全部汇总到各种存储过程中,并将其包含在Oracle软件包中。

Then you can have a package for each logic area of your application. 然后,您可以为应用程序的每个逻辑区域提供一个程序包。 Eg PKG_USERS, PKG_ACCOUNTS, etc. 例如PKG_USERS,PKG_ACCOUNTS等。

It is also easier to track changes because you can put these under version control and see all changes at a glance. 跟踪更改也更加容易,因为您可以将这些更改置于版本控制之下,并一目了然地查看所有更改。

It works for me, hopefully it helps you... 它对我有用,希望对您有帮助...

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

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