ORACLE的TYPE

sky_0036 2011-06-30 03:33:44
Type Syncdata Is Table Of Varchar2(4000) Index By Varchar2(64);
上面这个是啥意思?解释一下


还有TYPE的基本应用
...全文
99 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
304的的哥 2011-07-01
  • 打赏
  • 举报
回复

SQL>
SQL> declare
2 current varchar2(9 char);
3 element integer;
4 type months_varray is varray(12) of string(9 char);--
5 type calender_table is table of varchar2(9 char)--
6 index by varchar2(9 char);
7 month months_varray :=
8 months_varray('January','February','March','April'
9 ,'May','June','July','August','September'
10 ,'October','November','December');
11 calendar calender_table;
12 begin
13 if calendar.count=0 then
14 dbms_output.put_line('Assignment loop:');
15 dbms_output.put_line('----------------');
16 for i in month.first..month.last loop
17 calendar(month(i)) := to_char(i);
18 dbms_output.put_line('Index ['||month(i)||'] is ['||i||']');
19 end loop;
20 dbms_output.put(chr(10));
21 dbms_output.put_line('Post-assignment loop:');
22 dbms_output.put_line('----------------');
23 for i in 1..calendar.count loop
24 if i=1 then
25 current := calendar.first;
26 element := calendar(current);
27 else
28 if calendar.next(current) is not null then
29 current := calendar.next(current);
30 element := calendar(current);
31 else
32 exit;
33 end if;
34 end if;
35 dbms_output.put_line('Index ['||current||'] is ['||element||']');
36 end loop;
37 end if;
38 end;
39 /

PL/SQL procedure successfully completed

SQL> set serveroutput on;
SQL> /

Assignment loop:
----------------
Index [January] is [1]
Index [February] is [2]
Index [March] is [3]
Index [April] is [4]
Index [May] is [5]
Index [June] is [6]
Index [July] is [7]
Index [August] is [8]
Index [September] is [9]
Index [October] is [10]
Index [November] is [11]
Index [December] is [12]

Post-assignment loop:
----------------
Index [April] is [4]
Index [August] is [8]
Index [December] is [12]
Index [February] is [2]
Index [January] is [1]
Index [July] is [7]
Index [June] is [6]
Index [March] is [3]
Index [May] is [5]
Index [November] is [11]
Index [October] is [10]
Index [September] is [9]

PL/SQL procedure successfully completed

SQL>
Rotel-刘志东 2011-06-30
  • 打赏
  • 举报
回复
type本身是自定义数据类型。
Type Syncdata Is Table Of Varchar2(4000) Index By Varchar2(64);
TABLE 相当于是数组,这里定义了一个数组类型Syncdata
INDEX BY Varchar2(64);这里是定义数组下标是整数,因为ORACLE中下标可以是字符串.
VARCHAR2(4000)这是定义数组里面只能放字符串
shadow1986a 2011-06-30
  • 打赏
  • 举报
回复
TYPE 说明后面是你的自定义类型。
hudingchen 2011-06-30
  • 打赏
  • 举报
回复
定义一个联合数组,
Table Of Varchar2(4000)是数组存在数据的类型,
Index By Varchar2(64)是数组下标的类型。

17,078

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧