繁体   English   中英

如何运行条件为 SQL Oracle 的查询组

[英]How to Run group of Query with condition SQL Oracle

我正在写一个 SQL 文件,其中包含不同的部分,如下例所示。 在运行整个文件时,如果输入值等于部分名称,它应该运行特定部分:

Def input_var=1;
--//if condition to run 1,2,3 section as per input variable
-------------Section 1-------
--begin
update table1 Set status='RN' where status='IP';
Delete table1  where status='E';
update table2 Set status='RN' where status='IP';
Delete table2  where status='E';
--end
-------------Section 2-------
--begin
update table3 Set status='RN' where status='IP';
Delete table3  where status='E';
update table4 Set status='RN' where status='IP';
Delete table4  where status='E';
--end
..... multiple section

你几乎没有选择。 最简单的可能是 just if/else it:

  BEGIN
    IF   ( section = 1 ) 
    THEN
      Update table1 Set status='RN' where status='IP';
      Delete table1  where status='E';
      Update table2 Set status='RN' where status='IP';
      Delete table2  where status='E';
    ELSIF( section = 2 ) 
    THEN
      Update table3 Set status='RN' where status='IP';
      Delete table3  where status='E';
      Update table4 Set status='RN' where status='IP';
      Delete table4  where status='E';
    ELSIF( section = 3 )
    THEN
      <code>
    ELSE
      <code>
    END IF;
  END;

暂无
暂无

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

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