PL/SQL数据类型

PL/SQL数据类型分为5大类:

1.标量类型(数字,字符,日期时间,布尔)

2.复合类型(record,table,varray)

3.参照(引用)类型(ref cursor,ref object_type)

4.大对象(Lob)类型(blob,clob,nclob,bfile)

5.属性类型(%type,%rowtype)

 

1.标量类型

1-1,数字类型

binary_float(oracle10新增)

binary_double(oracle10新增)

number(又分以下子类型)

decimal(最高精度为38位的10进制定点数)

dec(decimal简称)

double precision(双精度浮点126位)

float(最高精度为126位(大约相当于38位10进制数字)的二进制数字的浮点数)

integer(最高精度38位,与binary_integer区别:integer是sql数据类型,可以用来定义表列,而binary_integer是pl/sql类型,不能定义表列)

int(integer的简写)

smallint

real(最高精度为63位(大约相当于18位10进制)的二进制浮点数)

numeric(不知)

binary_integer,又包含以下子类型

natural;自然数

naturaln;自然数,并且非空

positive;正整数

positiven;正整数,并且非空

signtype;只能存储0,-1,1

pls_integer(大小介于-2的31次方到2的31次方,与binary_integer和number相比运算速度更快,存储空间更小)

 

1-2,字符类型

char

nchar(unicode字符)

chararter(char简称)

varchar(向后兼容的类型,建议使用varchar2)

varchar2

nvarchar2(unicode字符)

string(varchar2的子类)

raw(固定长度的二进制)

raw变量的最大长度为32767byte,数据库列的最大长度为2000byte

long raw

long raw变量的最大值为32760byte,数据库列的最大值为2GB

long(类似于varchar2类型)

 

1-3,日期类型

date

timestamp

 

1-4,布尔类型

boolean(只要三个值true,false,null)

 

2.复合类型

2-1,record(pl/sql记录,相当于高级语言中的结构)用法示例:

declare type stu_record_type is record--is是必须的,不能替换为as ( name student.stuname%type, age student.stuage%type ); stu_record stu_record_type; begin select stuname,stuage into stu_record from student where stuid='001'; dbms_output.put_line('姓名为:'||stu_record.name||' 年龄为:'||stu_record.age); end;

2-2,table(pl/sql表,不能作为表的列类型,相当于高级语言的数组,但没有大小限制,索引下标也没有界限)用法示例:

declare type stu_table_type is table of student.stuname%type index by binary_integer;--定义一个数组类型 stu_table stu_table_type;--定义数组类型的变量 begin select stuname into stu_table(-200) from student where stuid='001';--下标可以随意指定 dbms_output.put_line('姓名为:'||stu_table(-200)); end;

posted on 2012-11-09 17:23  wencansz  阅读(544)  评论(0编辑  收藏  举报