postgresql自定义类型并返回数组
2015-03-18 17:10
459 查看
create type custom_data_type as ( id int, name varchar(50), score decimal(5,2), create_time timestamp ); create or replace function custom_data_type_demo(p_order_unit_array varchar[],p_goods_array int[]) returns custom_data_type[] as $$ declare v_order_unit_array varchar[] := array['a','b','c']::varchar[]; v_goods_array int[] := array[60.56,82.12,95.32]::int[]; v_tmp_result custom_data_type; v_result_array custom_data_type[]; v_index int := 0; v_order varchar(100); v_goods int; begin if p_order_unit_array is not null then v_order_unit_array := p_order_unit_array; end if; if p_goods_array is not null then v_goods_array := p_goods_array; end if; raise notice '-------1---------'; <<order_label>> foreach v_order in array v_order_unit_array loop <<goods_label>> foreach v_goods in array v_goods_array loop v_tmp_result.id = v_index*round(random()*10); v_tmp_result.name = v_order; v_tmp_result.score = v_goods; v_tmp_result.create_time = current_timestamp; end loop goods_label; raise notice '-------a---------'; v_result_array[v_index] = v_tmp_result; v_index := v_index + 1; end loop order_label; raise notice '-------2---------'; return v_result_array; exception when others then raise exception 'error happen(%)',sqlerrm; end; $$ language plpgsql; select custom_data_type_demo(null,null);
相关文章推荐
- Java调用存储过程(返回:简单类型、自定义对象、列表数组)
- PostgreSQL自定义函数返回单条记录类型的例子...
- Visual C#2005——如何使用ToArray方法返回一个强类型数组
- Crystal自定义函数(转换为大写,返回数组,求和)
- Nhibernate使用HQL返回自定义类型
- 返回值是数组类型或返回的封装类中属性类型是数组类型的注意事项
- SQL自定义函数split 将数组(分隔字符串)返回阵列(表)
- ToArray(type) 方法返回强类型数组
- 定义struct/struct定义在哪里/函数返回指针类型/指针数组与数组指针/{}里是局部定义/fabs、abs
- .net(C#)无法获取Java Web Service返回自定义类型的值
- webService返回自定义类型的数据处理
- java 调用存储过程 传入和返回全部是自定义数组
- VB调用DLL时传递自定义类型数组参数注意
- Oracle 方法返回自定义表类型的例子
- WebServices(C#)--返回自定义数据类型
- XFire实现自定义类型参数传递和调用返回自定义类型方法
- Visual C#2005——如何使用ToArray方法返回一个强类型数组
- 使用自定义JavaScriptConverter返回自定义的复杂类型
- Oracle 方法返回自定义表类型的例子
- 在COM/DCOM中如何将数组作为函数返回的类型传递