oracle------如何在方法中返回自己需要的column集合
来源:互联网 发布:哪里有unix系统源码 编辑:程序博客网 时间:2024/05/29 02:09
1、定义你自己需要的对象
如下:
create or replace type poi_columns as object
(
quailty NUMBER(5,2),
serving NUMBER(5,2),
condition NUMBER(5,2),
loopnum NUMBER(8)
)
2、将对象定义成类型
CREATE OR REPLACE TYPE poiinfos AS TABLE OF poi_columns
3、type可以用了,使用方法如下:
create or replace function toplistcounter
(
poiid in number
)
return poiinfos PIPELINED IS//设定返回值类型为数据集和类型
counts number(5,2);
commentcount number(8);
loops number;
voteresult VARCHAR2(16);
quality varchar2(2);
serving varchar2(2);
condition varchar2(2);
quality_g_num number(8);
quality_b_num number(8);
quality_n_num number(8);
serving_g_num number(8);
serving_b_num number(8);
serving_n_num number(8);
condition_g_num number(8);
condition_b_num number(8);
condition_n_num number(8);
results poi_columns := poi_columns(0 , 0 , 0 , 0) ;//声明一个自己的对象变量
cursor poi_voteresult is
select
t.voteresult
from
edz_comment t
where
t.intime > = SYSDATE - 7
and t.objecttype = 1
and t.objectid = poiid;
begin
quality_g_num := 0;
quality_n_num := 0;
quality_b_num := 0;
serving_g_num := 0;
serving_n_num := 0;
serving_b_num := 0;
condition_g_num := 0;
condition_n_num := 0;
condition_b_num := 0;
counts := 0;
loops := 0;
results.loopnum := 0;
results.quailty := 0;
results.serving := 0;
results.condition :=0;
select
count(t.commentid) into loops
from
edz_comment t
where
t.intime > = SYSDATE - 7
and t.objecttype = 1
and t.objectid = poiid;
if(loops = 0) then PIPE ROW(results); return ;end if;
results.loopnum := loops;
open poi_voteresult;
loop
fetch poi_voteresult into voteresult;
exit when loops <= 0;
loops := loops - 1;
quality := substr(voteresult , 1 , 1);
serving := substr(voteresult , 3 , 1);
condition := substr(voteresult , 5 , 1);
if(quality = 'G') then
quality_g_num := quality_g_num + 1;
end if;
if(quality = 'N') then
quality_n_num := quality_g_num + 1;
end if;
if(quality = 'B') then
quality_b_num := quality_g_num + 1;
end if;
if(serving = 'G') then
serving_g_num := serving_g_num + 1;
end if;
if(serving = 'N') then
serving_n_num := serving_g_num + 1;
end if;
if(serving = 'B') then
serving_b_num := serving_g_num + 1;
end if;
if(condition = 'G') then
condition_g_num := condition_g_num + 1;
end if;
if(condition = 'N') then
condition_n_num := condition_n_num + 1;
end if;
if(condition = 'B') then
condition_b_num := condition_b_num + 1;
end if;
end loop;
results.quailty := ((quality_g_num*3+quality_n_num)/((quality_g_num*3+quality_n_num)+(quality_b_num*3+quality_n_num)));
results.serving := ((serving_g_num*3+serving_n_num)/((serving_g_num*3+serving_n_num)+(serving_b_num*3+serving_n_num)));
results.condition := (condition_g_num*3+condition_n_num)/((condition_g_num*3+condition_n_num)+(condition_b_num*3+condition_n_num));
PIPE ROW(results);//将对象放入返回值
return ;
end ;
- oracle------如何在方法中返回自己需要的column集合
- 通过jdbcTemplate如何返回自定义的对象集合,以及在java中如何遍历这个集合
- 如何在oracle中限制返回结果集的大小
- 当在一个方法中需要返回多个参数时的做法
- 如何在大型工程中找到自己所需要的代码
- 在ArcGIS中如何导航至自己所需要的数据?
- 在编程的工作中,需要总结自己,升华自己
- 黑马程序员一在hashSet集合中比较对象需要覆盖的两个方法hashCode(),equlas()
- [VB.NET]问下 :自己写的com,其中一个接口方法返回一个variant类型的值,在.net中如何接收啊
- 如何在自己的对话框调用CAD的内置对话框,并能够再返回自己的对话框中
- ORACLE实现存储过程返回查询结果集合的方法
- 在使用JS编程中,有时需要在一个方法返回两个个或两个以上的数据
- 如何在Oracle中释放flash_recovery_area(温柔的方法)
- 如何在Oracle中释放flash_recovery_area(粗鲁的方法)
- 如何在ORACLE中异步调用存储过程的方法
- 如何在Oracle中实现SELECT TOP N的方法
- 如何在oracle存储过程中返回游标
- 如何在oracle存储过程中返回游标----例子一
- 使用Java自带SAX工具解析XML
- 数学之美(系列十六 (下)) 之 不要把所有的鸡蛋放在一个篮子里 最大熵模型
- Linux下程序的内存占用
- 数学之美(系列十七) 之 闪光的不一定是金子 谈谈搜索引擎作弊问题(Search Engine Anti-SPAM)
- 游戏茶苑港式五张看牌外挂的开发与演示
- oracle------如何在方法中返回自己需要的column集合
- 数学之美(系列十八) 之 矩阵运算和文本处理中的分类问题
- 数学之美(系列十九) 之 马尔可夫链的扩展 贝叶斯网络 (Bayesian Networks)
- DOS/WinPE双启动U盘制作详解
- 数学之美(系列二十) 之 自然语言处理的教父 马库斯
- 告诉你什么是次贷危机
- RS232串口控制智能步进电机控制器
- 数学之美(系列二十一) 之 布隆过滤器(Bloom Filter)
- 数学之美(系列二十二) 之 由电视剧《暗算》所想到的 — 谈谈密码学的数学原理