基本数据类型:
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.记录型变量 type
1
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:将其他类型数据转换成数值型