PL/SQL数据类型
2012-11-09 17:23
537 查看
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新增)
[b]number(又分以下子类型) [/b]
[b][b]decimal(最高精度为38位的10进制定点数) [/b][/b]
dec(decimal简称)
double precision(双精度浮点126位)
float(最高精度为126位(大约相当于38位10进制数字)的二进制数字的浮点数)
[b]integer(最高精度38位,与binary_integer区别:integer是[b][b]sql数据类型,[/b]可以用来定义表列,而binary_integer是pl/sql类型,不能定义表列)[/b] [/b]
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
[b]nvarchar2(unicode字符) [/b]
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;
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新增)
[b]number(又分以下子类型) [/b]
[b][b]decimal(最高精度为38位的10进制定点数) [/b][/b]
dec(decimal简称)
double precision(双精度浮点126位)
float(最高精度为126位(大约相当于38位10进制数字)的二进制数字的浮点数)
[b]integer(最高精度38位,与binary_integer区别:integer是[b][b]sql数据类型,[/b]可以用来定义表列,而binary_integer是pl/sql类型,不能定义表列)[/b] [/b]
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
[b]nvarchar2(unicode字符) [/b]
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;
相关文章推荐
- PL/SQL 数据类型和变量 -- BOOLEAN
- Oracle 10g复合数据类型pl/sql集合学习六——索引表、嵌套表、变长数组
- PL/SQL的数据类型和常用函数
- PL/SQL数据类型及常用函数
- PL/SQL之记录表数据类型
- PL/SQL_使用复合数据类型5(批量绑定)
- PL/SQL复合数据类型(集合与记录)
- Oracle 学习:PL/SQL循序渐进全面学习教程--课程十三 使用组合数据类型* 游标操纵数据
- PL/SQL学习笔记之数据类型中的标量、LOB
- oracle复合数据类型学习五——pl/sql记录
- 10.PL_SQL――PL_SQL中的复合数据类型之RECORDS
- 关于pl/sql 中的数据类型 number 和 binary_integer
- PL/SQL数据类型关注点
- PL/SQL--复杂数据类型
- 使用复合数据类型——PL/SQL记录表
- SQL, PL/SQL 之NUMBER数据类型
- Oracle之PL/SQL编程_数据类型与定义变量和常量
- Oracle PL/SQL复合数据类型
- PL/SQL定义部分之二复合数据类型
- PL/SQL-2 复合数据类型