Oracle中如何自定义类型

时间:2023-03-10 05:31:16
Oracle中如何自定义类型

一:Oracle中的类型有很多种,主要可以分为以下几类:
1、字符串类型。如:char、nchar、varchar2、nvarchar2。
2、数值类型。如:int、number(p,s)、integer、smallint。
3、日期类型。如:date、interval、timestamp。
4、PL/SQL类型。如:pls_integer、binary_integer、binary_double(10g)、binary_float(10g)、boolean。plsql类型是不能在sql环境中使用的,比如建表时。
5、自定义类型:type / create type。

二:type / create type区别联系
1、相同:
(1)可用用关键字create type 或者直接用type定义自定义类型,
2、区别:
create type语法:
create type 变量 as table of 类型
或:
create type 变量 as object(
     字段1 类型1,
     字段2 类型2
);

type语法:
type 变量 is table of 类型
或:
type 变量 is record(
     字段1 类型1,
     字段2 类型2
);

区别:
(1)用create后面用as,若直接用type后面用 is
(2)create是创建object , 而type是创record .
(3)type用在语句块中,而create 是的独立的.

说明:自定义类型一般分为两种,object类型和table类型。object类似于一个recored,可以表示一个表的一行数据,object的字段就相当与表的字段,自定义的table类型需要用的已经定义好的object类型。

具体可参考:https://www.cnblogs.com/advocate/p/3729998.html