首页 > Linux操作系统 > Linux操作系统 > 整型序号产生器(五)
这里介绍如何使用类型构筑表达式()的方法来创建连续整数.
这个方法要求nested table type 和 varry type. 我们创建一个名为INTEGER_TABLE_TYPE 的类型
SQL> create type integer_table_type as table of integer ;
2 /
Type created.
desc integer_table_type
integer_table_type TABLE OF NUMBER(38)
如果你想管理一组数字,例如从10到20,你可以使用如下查询:
select column_value
from table( integer_table_type( 1,2,3,4,5,6,7,8,9,10 ) ) ;
COLUMN_VALUE
------------
1
2
3
4
5
6
7
8
9
10
这个方法和其它方法不同的是它能够产生不连续的整数,例如:
select column_value
from table( integer_table_type( 1,1,4,4,4,8,10 ) ) ;
COLUMN_VALUE
------------
1
1
4
4
4
8
10
在day of the week 中使用下面的查询:.
select
i.column_value as day_of_week ,
t.val
from
table( integer_table_type( 0,1,2,3,4,5,6 ) ) i
left outer join t
on ( i.column_value = t.day_of_week )
order by
i.column_value
;
DAY_OF_WEEK VAL
----------- ----------
0
1 100
2
3 300
4 400
5 500
6
如果你在类型构造中超过999个参数,可能会报ORA-00939: too many arguments for function error (Oracle 10g中测试).
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9036/viewspace-512/,如需转载,请注明出处,否则将追究法律责任。