--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;