与很多语言一样,oracle也有其集合结构,首先向大家介绍 :index-by表
index-by 类似c,c++,java中的数组.
一. 定义语法为:
TYPE TableType IS TABLE OF type INDEX BY BINARY_INTEER;
二. 示例
1. 类型为字符串
2. 类型为数值型
3. 类型为自定义
index-by 类似c,c++,java中的数组.
一. 定义语法为:
TYPE TableType IS TABLE OF type INDEX BY BINARY_INTEER;
二. 示例
1. 类型为字符串
sql 代码
- Declare
- Type characterTab Is Table Of Varchar2(10) Index By Binary_Integer;
- v_characters characterTab;
- Begin
- v_characters(0) := 'hello';
- v_characters(1) :='wilent';
- dbms_output.put_line(v_characters(0)||'_'||v_characters(1));
- End;
2. 类型为数值型
sql 代码
- Declare
- Type numberTab Is Table Of Number Index By Binary_Integer;
- numbers numberTab;
- outChar Varchar2(255) := '';
- Begin
- For v_count In 1..10 Loop
- numbers(v_count) := v_count;
- outChar := outChar||'_'||numbers(v_count);
- End Loop;
- dbms_output.put_line(outChar);
- End;
3. 类型为自定义
sql 代码
- --自定义类型testObject;
- Create Or Replace Type testObject As Object
- (
- field_1 Number,
- field_2 Varchar2(20),
- field_3 Varchar2(20)
- );
- /
- Declare
- Type objectTab Is Table Of testObject Index By Binary_Integer;
- t_obj objectTab;
- Begin
- t_obj(1) := testObject(88,Null,Null);
- t_obj(1).field_2 := 'hello';
- t_obj(1).field_3 := '世界';
- dbms_output.put_line(t_obj(1).field_1||t_obj(1).field_2||t_obj(1).field_3);
- End;