时间:2021-07-01 10:21:17 帮助过:3人阅读
Oracle数组类型
Oracle的数组类型,范例: Sql代码 create or replace function my_test(p_str varchar2) return number as --普通变量 v_var varchar2(1000); --固定长度数组 type v_ar is varray(10) of varchar2(30); my_ar v_ar:=v_ar(‘g‘,‘m‘,‘d‘,‘龚‘,‘帅‘); --可变长度数值 type type_array is table of varchar2(20) index by binary_integer; var_array type_array; --类似二维数组 type serv_array is table of itmis_pri_serv_tbl%rowtype index by binary_integer; var_serv serv_array; www.2cto.com --记录块,保存一条记录的变量,类似C的struct TYPE t_myRecord is record ( Field1 number, Field2 varchar2(50)); var_record t_myRecord; begin v_var := ‘hello world‘; dbms_output.put_line(v_var); for i in 1..my_ar.count loop dbms_output.put_line(my_ar(i)); end loop; ------------------------------------------ var_array(1):=‘aa‘; var_array(2):=‘bb‘; --下标必须是连续的 for i in 1..var_array.count loop dbms_output.put_line( var_array(i)); end loop; -------------------------------------------- 可以作为一个临时表变量来使用 --select * bulk collect into var_serv from itmis_pri_serv_tbl where year =2013; --类似二维数组 select * bulk collect into var_serv from itmis_pri_serv_tbl ; --二维数组的访问 for i in 1..var_serv.count loop dbms_output.put_line(var_serv(i).serv_id); dbms_output.put_line(var_serv(i).status); end loop;Oracle数组类型
标签: