Sybase开发人员问:如何在Oracle中创建临时表?
我熟悉 Sybase / SQL 服务器,我可以在其中创建临时文件。 像这样的表:
SELECT *
INTO #temp
FROM tab1 ,
tab2
WHERE tab1.key = tab2.fkey
SELECT *
FROM #temp
WHERE field1 = 'value'
#temp 仅在本次会话期间存在,并且只能由我看到。
我想在 Oracle 中做类似的事情,但我正在阅读有关“全局临时表”的内容,这听起来不像同一件事。
如何在 Oracle 中执行与 Sybase 中相同的操作?
谢谢 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的第一种方法应该是将其作为单个查询来执行:
对于非常复杂的情况或 temp# 非常大的情况,请尝试子查询分解子句,可选地使用物化提示:
如果这没有帮助,请转到全局临时表方法。
Your first approach ought to be to do this as a single query:
For very complex situations or where temp# is very large, try a subquery factoring clause, optionally with the materialize hint:
If that is not helpful, go to the Global Temporary Table method.
全局临时表则不同,其定义在会话结束后仍然保留,并且该表(但不是数据)对所有会话都可见。
如果您正在编写存储过程,您是否研究过游标? 它有点复杂,但是是处理临时数据集的非常有效和干净的方法。
A global temporary table is not the same, the definition remains after the end of the session, also the table (but not the data) is visible to all sessions.
If you are writing stored procedures, have you looked into cursors? It's a bit more complicated, but a very efficient and clean way to work with a temporary data set.
Oracle 不提供此工具的直接类似物。 全局临时表类似,但它必须提前创建,并且由于锁定问题可能很难更改。
这种性质的大多数需求可以通过游标或不同的 pl/sql 集合类型之一(嵌套表、变量、关联数组)来满足,但这些都不能像表一样使用。 也就是说,您无法从中进行 SELECT。
Oracle does not provide a direct analogue of this facility. A global temporary table is similar, but it must be created in advance and can be difficult to alter down the line due to locking issues.
Most needs of this nature can be met with cursors or one of the different pl/sql collection types (nested tables, varrays, associative arrays), but none of those can be used as if they were a table. That is, you cannot SELECT from them.
我相信 全局临时 表是相同的。 它们将为您提供对临时表的私有访问权限,该临时表在会话结束时就会消失:
多读几次问题后,我相信这是主要的区别,也许您的问题是临时表在会话之间持续存在。 因此,完全等效的情况是不可能的,就像您在 Oracle 中想象的那样:
该表将一直存在,直到它被删除,即使通过会话也如此,尽管其中的数据不会。 相反,您需要提前创建临时表。
I believe global temporary tables are the same. They will give you private access to a temporary table that dies when the session ends:
After reading the question a few more times I believe it the main difference, and maybe your issue is that the temporary tables persist between sessions. So the exact equivalent is not possible as you would imagine in Oracle it would be something like:
That table will live until it is dropped even through sessions although the data in it does not. Instead you would need to create the temporary table in advance.
Oracle 中的临时表模型有些不同,它以“CREATE GLOBAL TEMPORARY TABLE..”语句为中心。 临时表定义始终是全局的,但数据始终是会话私有的,并且数据是否在提交后保留取决于是否指定了“提交时保留行”或“提交时删除行”限定条件。
我有一些 Perl 脚本和一篇博客文章,探讨 我的博客。
The temporary table model is somewhat different in Oracle, and centers around the "CREATE GLOBAL TEMPORARY TABLE.." statement. Temp table definitions are always global, but data is always private to the session, and whether data persists over a commit depends on whether the qualification "on commit preserve rows" or "on commit delete rows" is specified.
I have some Perl scripts and a blogpost that explores the specific behaviour or Oracle temp tables on my blog.
是的,卡森说得对。 全局临时表仅对创建它们的会话可见,并在第一次提交或回滚时或在会话结束时消失。 您可以在创建 gtt 时进行设置。
Yes, carson has it right. Global temporary tables are only visible to the session that creates them, and disappear either at the first commit or rollback, or at the end of the session. You can set that when you create the gtt.