type aaa is table of number;
v_ray aaa;有如上数组,已经在里面放了数据,现在怎样查询里面的最大值和最小值呀( ⊙ o ⊙ )?~~~帮忙看看~~
v_ray aaa;有如上数组,已经在里面放了数据,现在怎样查询里面的最大值和最小值呀( ⊙ o ⊙ )?~~~帮忙看看~~
解决方案 »
- spool导出性能问题
- 年月拼凑方法实现:实现199001.。199002.。199003.。。。。。。。。。。299911.。299912,并导出导excel 求助高手~~~
- merge 的小问题 帮我看看谢谢
- oracle 连接字符串是什么啊
- 初学者问题:PL/SQL和SQL*Plus有什么区别?
- 重做段和回滚段 区别
- 如何使用DBA往一个类型为date的字段内插入数据?
- 请各位高手帮忙看一下这是什么问题,我的数据库已经启动了?
- 报表导入EXCEL,并且得到正确的格式
- TO KingSunSha(弱水三千)兄: 再问一个关于GROUP查询的问题
- failed to start the service,error 0
- 数据物理存储方式求扫盲
已写入 file afiedt.buf 1 declare
2 v_ray aaa:=aaa();
3 v_max int;
4 v_min int;
5 begin
6 v_ray.extend(3);
7 v_ray(1):=1;
8 v_ray(2):=2;
9 v_ray(3):=3;
10 select max(column_value) into v_max from table(v_ray);
11 select min(column_value) into v_min from table(v_ray);
12 dbms_output.put_line('最大值:'||v_max);
13 dbms_output.put_line('最小值:'||v_min);
14* end;
wf@ORA10> /
最大值:3
最小值:1
-- nested table 类型在块中声明
1 declare
2 type n_tab_type is table of number;
3 n_tab n_tab_type:=n_tab_type(1,2,3);
4 n_max number;
5 n_min number;
6 i number;
7 begin
8 i:=n_tab.first;
9 n_max:=n_tab(i);
10 n_min:=n_tab(i);
11 loop
12 i:=n_tab.next(i);
13 exit when i is null;
14 n_max:=(case when n_tab(i)>n_max then n_tab(i) else n_max end);
15 n_min:=(case when n_tab(i)<n_min then n_tab(i) else n_min end);
16 end loop;
17 dbms_output.put_line('Max:'||n_max||' Min:'||n_min);
18* end;
SQL> /
Max:3 Min:1-- 在数据库中生成 nested table 类型
SQL> create type n_tab_type is table of number;
2 /Type created.SQL> declare
2 n_tab n_tab_type:=n_tab_type(1,2,3);
3 n_max number;
4 n_min number;
5 begin
6 select max(column_value) into n_max from table(n_tab);
7 select min(column_value) into n_min from table(n_tab);
8 dbms_output.put_line('Max:'||n_max||' Min:'||n_min);
9 end;
10 /
Max:3 Min:1