简体   繁体   English

我正在努力将临时表(SQL Server)迁移到oracle

[英]I am struggling with migrating the temp tables (SQL server) to oracle

I am struggling with migrating the temp tables (SQL server) to oracle. 我正在努力将临时表(SQL Server)迁移到oracle。 Mostly, oracle don't consider to use temporary table inside the store procedure but in sql server, they are using temp tables for small fetching record and also manipulate same. 通常,oracle不考虑在存储过程中使用临时表,但在sql server中,他们使用临时表来获取较小的记录并对其进行操作。 How to overcome this issue. 如何克服这个问题。 I am also searching some online articles about migrating temp table to oracle but they are not clearly explained for my expectations. 我也在搜索一些有关将临时表迁移到oracle的在线文章,但对于我的期望并没有明确解释。 i got information like using inline view, WITH clause, ref cursor instead of temp table. 我得到了诸如使用内联视图,WITH子句,ref游标而不是临时表的信息。 I am totally confused. 我很困惑。 Please suggest me, in which case may use Inline view, WITH clause, ref cursor. 请建议我,在这种情况下,可以使用内联视图,WITH子句,引用游标。 This may be helpful for improve my knowledge and also doing job well. 这可能有助于提高我的知识并做好工作。

As always thank you for your valuable time in helping out the newbies. 与往常一样,感谢您宝贵的时间来帮助新手。 Thanks Alsatham hussain 感谢Alsatham hussain

Like many questions, the answer is "it depends". 像许多问题一样,答案是“取决于”。 A few things 一些东西

  1. Oracle's "temp" table is called a GLOBAL TEMPORARY TABLE (GTT). Oracle的“临时”表称为GLOBAL TEMPORARY TABLE(GTT)。 Unlike most other vendor's TEMP tables, their definition is global. 与大多数其他供应商的TEMP表不同,它们的定义是全局的。 Scripts or programs in SQL Server (and others), will create a temp table and that temp table will disappear at the end of a session. SQL Server(和其他)中的脚本或程序将创建一个临时表,并且该临时表将在会话结束时消失。 This means that the script or program can be rerun or run concurrently by more than one user. 这意味着脚本或程序可以由多个用户重新运行或并发运行。 However, this will not work with a GTT, since the GTT will remain in existence at the end of the session, so the next run that attempts to create the GTT will fail because it already exists. 但是,这不适用于GTT,因为GTT在会话结束时仍然存在,因此尝试创建GTT的下一次运行将失败,因为它已经存在。 So one approach is to pre-create the GTT, just like the rest of the application tables, and then change the program to INSERT into the gtt, rather than creating it. 因此,一种方法是像其余应用程序表一样预先创建GTT,然后将程序从INSERT更改到gtt中,而不是创建它。
  2. As others have said, using a CTE Common Table Expression) could potentially work, buy it depends on the motivation for using the TEMP table in the first place. 就像其他人所说的那样,使用CTE公用表表达式可能会起作用,是否购买它取决于首先使用TEMP表的动机。 One of the advantages of the temp table is it provides a "checkpoint" in a series of steps, and allows for stats to be gathered on intermediate temporary data sets; 临时表的优点之一是它在一系列步骤中提供了“检查点”,并允许在中间临时数据集上收集统计信息。 it what is a complex set of processing. 它是一套复杂的处理过程。 The CTE does not provided that benefit. CTE没有提供该好处。

  3. Others "intermediate" objects such as collections could also be used, but they have to be "managed" and do not really provide any of the advantages of being able to collect stats on them. 也可以使用其他“中间”对象(例如集合),但是必须对其进行“管理”,并且不能真正提供能够收集其统计信息的任何优势。

So as I said at the beginning, you choice of solution will depend somewhat on the motivation for the original temp table in the first place. 因此,正如我在开始时所说的那样,您对解决方案的选择首先将取决于原始临时表的动机。

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

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