簡體   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