Oracle type (自定义类型的使用)
oracle - type
type定义:
oracle中自定义数据类型
oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式,
如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型
格式 :create or replace type type_name as object(parameter1 varchar2(20),parameter2 varchar2(30));
这样子定义之后我们就能像使用基本类型一样使用自定义类型去建表:
如:
create or replace type name_format as object(firstname varchar2(20),lastname varchar2(30));
定义了类型之后,我们就可以将它当作普通的基本类型用了,建表,写function等等,如用自定义数据类型建表:
create table testtable(id number primary key,name name_format);
插入数据时,构造我们的这个自定义列时,就像构造对象一样,如上面的表插入数据的sql语句如下:
insert into testtable values(1,name_format('hust','lkq'));
查询自定义列的某个值可以用.来访问,如上面我要查询testtable表中name列的firstname的值可以按照如下查询:
select t.name.firstname from testtable t;
自定义数据类型也可以是集合
例如:create or replace type numers_set as array(10) of number;
这就表示创建了一个包含10个number数据的自定义类型,
注:这里的集合里面的基本元素也可以是你自定义的类型,也就是说支持嵌套定义
create or replace type name_list as array(10) of name_format:(此处的name_format就是我们在上面定义的一个自定义类型
将表中查出来的值赋值给ob:
select rec_planratemain(planrgroupmainid,pl.productid,planrateversion,pl.createuserid,pl.createdate,pl.updateuserid,pl.updatedate,ratedatetype,startdate,enddate,p.branchid,channeltype)into g_rec_planmainrate -- 实例化后的名字from planrgroupmain pl,productbranch_property pwhere pl.productid = 'PROG0000003001024'and p.productid = pl.productid --and startdate <= p_date--and ENDDATE >= p_dateand p.branchid = 'BRA0000000000011'and rownum < 2;
OB:
NT:
调用:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
function getagentbroker(p_branchid IN VARCHAR2,
p_month in VARCHAR2,
p_agentcode in varchar2,
p_type in varchar2) return nt_test is
v_Count SMALLINT DEFAULT 0;
v_NT_test NT_test;
v_num smallint default 10;
begin
if p_type = 'B' then
v_num := 0;
end if;
v_NT_test := NEW nt_test();
for c_ag in ( select a.agentid,
a.recommendagentid,
getagentstatus(a.agentstatus) agentstatus,
a.agentcode,
a.agentname,
a.agentlevelcode,
a.hiredate
from agenthis a
where a.bizyearmonth = p_month
and a.agentstatus = 'AGENTSTATUS_09'
and a.branchid = p_branchid
and (a.agentcode =p_agentcode or p_agentcode is null )
and (rownum <= v_num or v_num = 0)
) loop
v_Count := v_Count + 1;
v_NT_test.Extend;
v_NT_test(v_Count) := ob_test;
v_NT_test(v_Count).ca01 := c_ag.agentname;
v_NT_test(v_Count).ca02 := c_ag.agentcode;
v_NT_test(v_Count).ca03 := c_ag.agentlevelcode;
v_NT_test(v_Count).ca04 := c_ag.agentstatus;
v_NT_test(v_Count).ca05 := c_ag.hiredate;
----一代管理人
if c_ag.recommendagentid is not null then
begin
select agentcode,
agentname,
getagentstatus(agentstatus) agentstatus,
agentlevelcode,
recommendagentid
into v_NT_test(v_Count).ca06,
v_NT_test(v_Count).ca07,
v_NT_test(v_Count).ca08,
v_NT_test(v_Count).ca09,
v_NT_test(v_Count).ca10
from agenthis
where bizyearmonth = '201203'
-- and agentstatus='AGENTSTATUS_09'
and agentid = c_ag.recommendagentid;
exception
when others then
v_NT_test(v_Count).ca10 := '' ;
end ;
----2代管理人
if v_NT_test(v_Count)
.ca10 != '' or v_NT_test(v_Count).ca10 is not null then
begin
select agentcode,
agentname,
getagentstatus(agentstatus) agentstatus,
agentlevelcode,
recommendagentid
into v_NT_test(v_Count).ca11,
v_NT_test(v_Count).ca12,
v_NT_test(v_Count).ca13,
v_NT_test(v_Count).ca14,
v_NT_test(v_Count).ca15
from agenthis
where bizyearmonth = '201203'
-- and agentstatus='AGENTSTATUS_09'
and agentid = v_NT_test(v_Count).ca10;
exception
when others then
v_NT_test(v_Count).ca15 := '' ;
end ;
----3代管理人
if v_NT_test(v_Count)
.ca15 != '' or v_NT_test(v_Count).ca15 is not null then
begin
select agentcode,
agentname,
getagentstatus(agentstatus) agentstatus,
agentlevelcode,
recommendagentid
into v_NT_test(v_Count).ca16,
v_NT_test(v_Count).ca17,
v_NT_test(v_Count).ca18,
v_NT_test(v_Count).ca19,
v_NT_test(v_Count).ca20
from agenthis
where bizyearmonth = '201203'
-- and agentstatus='AGENTSTATUS_09'
and agentid = v_NT_test(v_Count).ca15;
exception
when others then
v_NT_test(v_Count).ca20 := '' ;
end ;
end if;
end if;
end if;
end loop;
return v_NT_test;
end ;
|
Type:
1 CREATE OR REPLACE TYPE "OB_SMSSEND" AS OBJECT ( 2 SMSSENDID VARCHAR2(64), -- N ?????? 3 CREATEUSERID VARCHAR2(32), -- Y ???? 4 CREATEDATE DATE, -- N ???? 5 UPDATEUSERID VARCHAR2(32), -- Y ???? 6 UPDATEDATE DATE, -- N ???? 7 BIZNO VARCHAR2(32), -- Y ?????? 8 SMSBIZCODE VARCHAR2(16), -- Y ?????? 9 SMSTEXTDESC VARCHAR2(1024), -- Y ???? 10 RECVMOBILENO VARCHAR2(32), -- Y ???? 11 APPROVESTATUS VARCHAR2(32), -- Y ?????? 12 SENDSTATUS VARCHAR2(32), -- Y ?????? 13 SENDDATE DATE, -- Y ???? 14 RECVCUSTOMERID VARCHAR2(64), -- Y ???? 15 RECVBACK VARCHAR2(64), -- Y ?????? 16 RECVBACKDATE DATE, -- Y ???? 17 CONSTRUCTOR FUNCTION OB_SMSSEND RETURN SELF AS RESULT 18 );
转自:http://www.cnblogs.com/o-andy-o/archive/2012/05/25/2517741.html
Oracle type (自定义类型的使用)相关推荐
- oracle如何自定义类型,Oracle 自定义类型
一.子类型 这种类型最简单,类似类型的一个别名,主要是为了对常用的一些类型简单化,它基于原始的某个类型.如: 有些应用会经常用到一些货币类型:number(16,2).如果在全局范围各自定义这种类型, ...
- Oracle 自定义类型TYPE(subtype, type object, type body, type table) 用法
原 ORACLE 自定义类型 type/ object 2017年03月28日 13:58:23 tan1012194073 阅读数:5999 版权声明:本文为博主原创文章,未经博主允许不得转载. h ...
- oracle自定义的记录类型,oracle 自定义类型 type / create type
一:Oracle中的类型有很多种,主要可以分为以下几类: 1.字符串类型.如:char.nchar.varchar2.nvarchar2. 2.数值类型.如:int.number(p,s).integ ...
- Oracle自定义类型
Oracle自定义类型可以通过type/create type来声明或者创建 一,四种创建方式 1.1,使用create type创建object类型 create or replace type o ...
- Go 学习笔记(33)— Go 自定义类型 type(自定义结构体、结构体初始化、结构体内嵌、自定义接口)
1. 自定义类型格式 用户自定义类型使用关键字 type ,其语法格式是: type newType oldType oldType 可以是自定义类型.预声明类型.未命名类型中的任意一种. newTy ...
- oracle 自定义类型使用方法,oracle pl/sql中使用自定义数据类型
模式: CREATE OR REPLACE TYPE 类型名 as OBJECT (属性名 属性类型,...); 举例: CREATE OR REPLACE TYPE BITS_IDX_BASE AS ...
- c oracle udt,c#调用Oracle UDT自定义结构数组类型源代码
[实例简介] c#调用Oracle UDT自定义结构数组类型源代码 [实例截图] [核心代码] ffa2062d-cc85-43bf-9aeb-2cf440e254c3 └── vsstart └── ...
- oracle 返回hashmap,解决:oracle+myBatis ResultMap 类型为 map 时返回结果中存在 timestamp 时使用 jackson 转 json 报错...
前言:最近在做一个通用查询单表的组件,所以 sql 的写法就是 select *,然后 resultType="map" ,然后使用 jackson @ResponseBody 返 ...
- Oracle中Clob类型处理解析
最近利用NHibernate映射类型为Clob字段在插入数据时发现当字符的字节数(一个半角字符一个字节,一个全角字符两个字节)在 2000 -4000之间时报错(ORA-01461:仅可以插入L ...
最新文章
- 字段和字段的参数,查询的13个方法,但标的双下划线外键和多对多操作
- 栈的应用_DFS解迷宫问题
- Linq to SQL只支持SQL Server(所选对象使用不支持的数据提供程序)
- 如何节省1T图片带宽?解密极致图像压缩!
- 不同的编译器:GCC G++ C C++的区别
- 小白系列之51单片机的入门速成法
- 140. Word Break II
- 面试官:面对千万级、亿级流量怎么处理?
- jbutton可以设置id吗_Java Swing简单控件实例(JButton,JLabel,JMenuBar,JComboBo)
- c#中ToString(yyyyMMdd) 与ToString(yyyymmdd)区别
- (2)二进制文件方式部署Kubernetes高可用集群----------部署环境准备
- java 读取文件内容 方法
- 怎么在CAD图纸中标注文字
- matplotlib绘制正弦曲线
- R语言28-Prosper 贷款数据分析4
- html/css横向竖向导航栏的绘制
- oracle冷备修改数据文件位置,Oracle冷备迁移脚本(文件系统)
- Linux基础面试篇
- 智能设备主要有哪些特点
- 随机生成6位数字(包括字母和数字)
热门文章
- Texlive安装与环境变量配置
- 判断两个树是否相等和判断tree1是否包含tree2 python实现
- Docker下部署mysql
- 初学MyBatis-Plus
- OFRecord 图片文件制数据集
- MinkowskiEngine实用函数和类
- Yolov4性能分析(下)
- 2021年大数据Flink(四十):​​​​​​​Flink模拟双十一实时大屏统计
- [JS] for-each和map()的区别
- Thread start()方法和run()方法的区别