oracle之PL/SQL編程基礎

來源:互聯網
上載者:User
--PL/SQL語言--字串串連符 ||select 'abc' || '123' from dual; --常量與變數declare  --<<--用來定義 變數、常量、遊標、自訂資料類型stu_name nvarchar2(4); begin --<<--執行語句的開始stu_name := '盧';  --   := 賦值符號dbms_output.put_line(stu_name);end;--<<--執行語句的結束declare PI constant number := 3.1415926;  -- constant 用於定義常量--定義資料類型declare type student is record (  --<<--這裡允許的資料類型除了 record(記錄)還有 table(表) varray(變長數組)name nvarchar2(20),sex char(2),age int);stul student;  --<<--這裡是在定義 student 類型的變數 stulbeginstul.name := 'text';dbms_output.put_line(stul.name);end;--IF... ELSE 語句declare i number; --定義number類型的變數 ibegin i:= 1; if i < 18 then  dbms_output.put_line('小於18'); else   null;   --空語句,什麼都不執行,起佔位作用 end if;end;-- IF... ELSIF... ELSE 語句declarei number;begin i := 40; if i < 18 then  dbms_output.put_line('小於18'); elsif i > 18 and i < 30 then  dbms_output.put_line('小於30'); else   dbms_output.put_line('不在統計範圍'); end if;end; --case 語句declare c char(2);begin c := 'C'; case c      --<<--可以是運算式  when 'A' then   dbms_output.put_line('你得了A');  when 'B' then   dbms_output.put_line('你得了B');  when 'C' then   dbms_Output.put_line('你得了C');  else   dbms_output.put_line('很抱歉,你沒及格'); end case;end;--LOOP迴圈declare i number;begin i := 1; loop  dbms_output.put_line(i);  i := i + 1; exit when i > 5;   exit when i > 10;--<<--exit 語句可以有多條,不寫的話則是死迴圈 end loop;end;--WHILE 迴圈declare i number;begin i := 0; while i < 10 loop  dbms_output.put_line(i);  i := i + 1; end loop;end;--FOR 迴圈declare i number; sumi number;begin  i := 0; sumi := 100; for i in 1...100 loop  sumi := sumi + i;   dbms_output.put_line(sumi); end loop; dbms_output.put_line(sumi);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.