基礎資料型別 (Elementary Data Type):1 Number------------數字型 Int----整數型
2 Pls_integer-------整數型,產生溢出時出現錯誤
3 Binary_integer----整數型,表示帶正負號的整數
4 Char--------------定長字元型,最大255個字元
5 Varchar2----------變長字元型,最大2000個字元
6 Long--------------變長字元型,最長2GB
7 Date--------------日期型
8 Boolean-----------布爾型(TRUE,FALSE,NULL三者一
9
複合資料型別變數
1使用%type定義變數:可以使PL/SQL中的變數類型和資料表中的欄位的資料類型一致
例子:1 Declare
2 mydate testtable.currentdate%type;--欄位testtable.currentdate
3 begin
4 commit
5 end;
2.記錄型變數 type1 set serveroutput on
2 declare
3 type myrecord is record(
4 myrecordnumber int,
5 mycurrentdate date);
6 srecord myrecord;
7 begin
8 select * into srecord from testtable where recordnumber=68;
9 dbms_output.put_line(srecord.mycurrentdate);
srecord 是myrecord 的變數.select .... into.into後面是要被賦值的變數.
3.%rowtype 定義變數:將表的欄位結構定義為變數
1 declare
2 mytable testtable@rowtype;
3 begin
4 select * into mytable
5 from testtable
6 where recordnumber=88;
7 dbms_output.put_line(mytable.currentdate);
8 end;4:定義一維表類型變數(相當於一維數組) 1 declare
2 type tabletype1 is table of varchar2(4) index by binary_integer;
3 type tabletype2 is table of testtable.recordnumber%type index by binary_integer;
4 table1 tabletype1;
5 table2 tabletype2;
6 begin
7 table1(1):="大學";
8 table1(2):="大專";
9 table2(1):=88;
10 table2(2):=55;
11 dbms_output.put_line(table1(1)||table1(2));
12 dbms_output.put_line(table2(1)||table2(2));
13 end;
14
其中||是連接字串的運算子.index by binary_integer表示以符號整數為索引,這樣訪問就可以表變數名(索引符號整數)的方式了
5.定義多維表類型變數(相當於多維陣列)1 declare
2 type tabletype1 is table of testtable%rowtype index by binary_integer;
3 table1 tabletype1;
4 begin
5 select * into table1(60)
6 from testtable
7 where recordnumber=60;
8 dbms_output.put_line(table1(60).recordnumber||table1(60).currentdate);
9 end;
表變數屬性有:count; delect;first,last,next,exists,prior等.使用方法表變數.屬性.返回的是數字.
6.常用的轉換函式1 To_char:將其他類型資料轉換成字元型
2 To_date:將其他類型資料轉換成日期型
3 To_number:將其他類型資料轉換成數值型