Oracle 动态数组使用-2

动态数组语法:

type <类型名> is table of 类型 index by binary_integer;
<变量名> 类型名

  • 示例:
declare 
  type jo_arr_type is table of pljson;  --jo_arr_type 为表(数组)类型
  jo_arr jo_arr_type;  -- jo_arr 为数组类型变量名
  type cur_ref_type is ref cursor; --声明一个游标引用类型  cur_ref_type
  cur cur_ref_type;  --声明一个游标引用类型变量
  i integer;
  ja pljson_listl;
  c clob;
begin
  i:=1;
  ja:=new pljson_list();
  open cur for 'select f1,f2 from tbname';
  for item in cur loop
    jo_arr(i):=new pljson();
	jo_arr(i).put('name',f1);
	jo_arr(i).put('value',f2);
	i:=i+1;
	...
	ja.append(jo_arr(i));
  end loop;
  dbms_lob.createtemporary(c,true);
  ja.to_clob(c);
  dbms_output.put_line(c);
end;
  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章