Oracle--PLSQL之控制結構

來源:互聯網
上載者:User

條件分支語句 • IF 語句: –IF-THEN-END IF –IF-THEN-ELSE-END IF –IF-THEN-ELSIF-END IF –case語句: •迴圈語句 –loop
文法:

  1. </pre><pre name="code" class="plain">IF condition THEN     
  2. statements;   
  3. [ELSIF condition   
  4. THEN   statements;]   
  5. [ELSE   statements;]   
  6. END IF;     
condition     是一個布爾變數或運算式 (值為TRUE, FALSE或NULL) (僅當運算式為TRUE時執行
                     THEN 之後的語句)。
 
THEN     是一個子句,與前面的布林運算式相聯絡。
 
statements   是 若干個PL/SQL 或 SQL 陳述式 (語句中可能還有嵌套的IF 語句)。
ELSIF     這個關鍵字將引入一個布林運算式 (如果第一個條件結果為FALSE或NULL,ELSEIF 關鍵
                字將引出附加的選擇條件) 。
 
ELSE      如果IF條件不成立則執行ELSE關鍵字後面的語句。 

更多Oracle相關資訊見Oracle 專題頁面 http://www.bkjia.com/topicnews.aspx?tid=12
 

NULL的處理
  1. DECLARE • x number(2):= 5;    
  2. y number(2):= NULL;   
  3. BEGIN   
  4.     IF x != y THEN   
  5.         dbms_output.put_line(100);    
  6.     ELSE  
  7.         dbms_output.put_line(200);  
  8.     END IF;   
  9. END;  
 任何包含空值的算術運算式結果均為空白值。
 
 僅當變數值為NULL時,IS NULL 的傳回值是 TRUE 。
 
 可把空變數當作Null 字元串來串連運算式。
  1. DECLARE  
  2.   x  number(2):=null;  
  3.   y  number(2):=null;  
  4.   begin  
  5.     if x!=y then  
  6.       dbms_output.put_line(100);  
  7.     else  
  8.       dbms_output.put_line(200);  
  9.     end if;  
  10.   end;    
  11.     
  12.     
  13.     
  14. DECLARE  
  15.   x  number(2):=null;  
  16.   y  number(2):=null;  
  17.   begin  
  18.     if x=y then  
  19.       dbms_output.put_line(100);  
  20.     else  
  21.       dbms_output.put_line(200);  
  22.     end if;  
  23.   end;   
都輸出200
  1. DECLARE  
  2.   x  number(2):=5;  
  3.   y  number(2):=null;  
  4.   begin  
  5.     if nvl(x,0)!=nvl(y,0) then  
  6.       dbms_output.put_line(100);  
  7.     else  
  8.       dbms_output.put_line(200);  
  9.     end if;  
  10.   end;   

輸出100
邏輯表:
  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.