PL/SQL中操作符、條件和迴圈控制

來源:互聯網
上載者:User

1.PL/SQL是一種塊結構語言,它將一組語句放在一個塊中,一次性發送給伺服器,先編譯後執行。對於有名稱的PL/SQL塊,可以單獨編譯,永久的存在資料庫中,隨時準備執行。PL/SQL的優點:

a.支援SQL(忽略大小寫).b.支援物件導向過程.c.更好的效能(SQL非過程語言,只能一條一條執行,PL/SQL可以一次性把一個塊統一進行編譯).d.可移植性.e.安全性.2.PL/SQL塊的文法:
[DECLARE--decalration statements] BEGIN--executable statements [Exception--exception statements]End;
3.賦值運算子:(:=,default,select..into),特殊符號:(||,--,,**求冪操作例如3**2=9),關係運算子:(>,<,>=,<=,=,<>,!=),邏輯運算子(AND,OR,NOT)。4.條件控制語句:
if 條件1 then 條件1結構體elsif 條件2 then 條件2結構體end if;和case:case[selector]when 運算式1 then 語句1;when 運算式2 then 語句2;elseend case;其中必須有選項與值匹配,否則報錯。case作為運算式的例子:p_grade:=casewhen v_grade='A' then 'aa'else 'bb'end;
5.迴圈結構:無條件迴圈(Loop-end Loop語句):Loop --迴圈體 end loop;while迴圈語句:whlie 條件 loop 迴圈體 end loop;for迴圈語句:For 迴圈變數 in[Reverse] 迴圈上限..迴圈下限 loop迴圈體 end loop;例如:
declare       counter number(3):=0;       sumResult number:=0;begin       dbms_output.put_line(counter);       for counter in 1..100 loop        dbms_output.put_line(counter);           sumResult:=sumResult+counter;        end loop;        dbms_output.put_line('result is :'||sumResult);end;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.