【问题标题】:PL/SQL Developer 8.0 LOOP IF ELSE THEN SQL WindowPL/SQL Developer 8.0 LOOP IF ELSE THEN SQL 窗口
【发布时间】:2014-10-23 13:51:29
【问题描述】:

我在 PL/SQL Developer 的 SQL 窗口 下创建了一个 .sql 文件。它非常 loooooog,但基本上是在执行以下操作:

TRUNCATE TABLE table_1
REUSE STORAGE;
COMMIT;

INSERT INTO table_1
Select * from table2
Where ...;
COMMIT;

但是,在运行此脚本之前,我们需要确保所有源都已轻松加载。所以我想在这个脚本之前添加一个如下的逻辑来执行检查:

Do check the timestamp field of table1 and table2
If table1.timestamp is NOT today
   If table2.timestamp is today then execute the script listed above
   Else do nothing
   End If
Else do nothing
End If
(Maybe wait for 60 minutes)
Loop

我可以找出 VBA 中的循环,但我更希望有一种方法可以将它添加到现有的 .sql 文件中,或者其他不需要我更改的方法很多现有的 SQL 语言。 不幸的是,我在财务部门工作,不允许在 PL/SQL Developer 中使用任何程序窗口。

有没有人知道有没有办法解决这样的案子??

感谢您的帮助!

【问题讨论】:

  • 在 PL/SQL 中检查 LOOP

标签: sql loops plsql


【解决方案1】:

您可以编写匿名 PL/SQL 块(有关详细信息,请参阅 oracle 文档)。例如,它可能看起来像:

declare -- keyword
  /* Here you can declare some variables */
begin -- keyword (starts script)
  /* some statements to do */

exception -- keyword to catch exceptions, if you want to do that
  /* statements to process errors */
end; -- keyword (end of script)
/ /* you need this symbol to show oracle that script body is ended 
     and after this symbol you can write another script, that will 
     be executed automatically after the first one */

如果您不想声明任何变量并捕获错误,则可以省略 DECLARE 和 EXCEPTION 部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-28
    • 2023-03-04
    • 2013-05-22
    • 2021-08-10
    • 1970-01-01
    • 2021-07-25
    • 2017-07-22
    相关资源
    最近更新 更多