Oracle中创建游标之前先创建表
我有一个 PL/SQL 过程,它创建一个临时表,然后使用游标从该临时表中提取数据,处理数据,然后删除临时表。然而,如果数据库中不存在该表,Oracle 不允许使用游标。
请帮我处理这个问题。
I have a PL/SQL procedure which creates a temporary table and then extracts the data from this temporary table using cursors, processes the data and then drops the temporary table. However Oracle doesn't allow the usage of cursor if the table doesn't exist in the database.
Please help me handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的说法不太正确。您可以使用游标进行几乎任意的查询。请参阅下文:(
更多详细信息此处< /a> - 特别是这个短过程根本不安全,因为表名是固定的并且不依赖于会话)。
它(相当)有点难看,我并不是建议您使用它 - 相反,您应该考虑是否需要该特定于过程的临时表。
请参阅另一篇文章 :
不能使用全局临时表吗?你真的需要一个临时表吗? (即,在用于填充该表的 select 语句上不使用游标吗?)
Your statement is not quite correct. You can use a cursor for pretty much arbitrary queries. See below:
(More details here - especially this short proc is not safe at all since the table name is fixed and not session-dependent).
It is (quite) a bit ugly, and I'm not suggesting you use that - rather, you should be thinking whether you need that procedure-specific temporary table at all.
See this other article:
Couldn't you use a global temporary table? Do you actually need a temporary table at all? (i.e. doesn't using a cursor on the select statement you'd use to fill that table work?)
或者,如果您希望避免全局临时表和“常规”永久表之间的差异,您可能会习惯(请参阅Oracle 文档 关于临时表数据可用性、生命周期等),只需先创建表(无日志记录)。假设没有其他人使用此表,您的过程可能会在处理之前/之后截断。
Or, if you wish to avoid differences between global temporary tables and "regular" permanent tables you may be used to (see Oracle docs on temp table data availability, lifetime etc), simply create the table first (nologging). Assuming nobody else is using this table, your procedure could truncate before/after your processing.