PL/SQL 如何执行带返回游标的存储过程 !(SQL 窗口中如何调用)

skyakon 2010-09-03 10:42:26
CREATE OR REPLACE PROCEDURE POOLING_GETSTATISTICSLIST (
idstations in varchar2,
idresults in INT,
hotNames in VARCHAR,
startTime in DATE,
endtime in DATE,
PID in varchar2,
p_curosr out p_myrefcursor.my_cursor
) AS
--
-- NAME :
-- DESCRIPTION :
-- AUTHOR :

contions VARCHAR2(4000);
tableId INt;
tableName VARCHAR2(20);
sqlStr VARCHAR(4000);
RunitID int;

BEGIN
SELECT ID into RunitID FROM RUnit WHERE ID_Station=idstations;
tableId:= mod(RunitID,10);
tableName := 'Re_Polling_' || to_char(tableId);
contions := ' where 1=1 ';
if idstations is not null then
contions := contions ||' and '||GetPerfectCond('ID_Station',idstations);
end if;
IF idresults != -1 then
contions := contions||' and Re_Result= ' || to_char(idresults);
end if;
IF hotNames is not null then
contions := contions||' and '||GetPerfectCond('HOT_Name',hotNames);
end if;
IF startTime is not null then
contions := contions||' and InsertTime>= ' || GetTimeQuoted(startTime) ;end if;
IF endtime is not null then
contions := contions||' and InsertTime<= ' || GetTimeQuoted(endtime);
end if;
IF PID is not null then
contions:=contions||' and '||GetPerfectCond('PID',PID);
end if;

sqlStr := '';
sqlStr := sqlStr || ' SELECT ID_Station ';
sqlStr := sqlStr || ' ,PID ';
sqlStr := sqlStr || ' ,AVG(to_number (PValue)) as PValue ';
sqlStr := sqlStr || ' ,Name_Station ';
sqlStr := sqlStr || ' ,Location ';
sqlStr := sqlStr || ' ,HOT_Name , Re_Result';
sqlStr := sqlStr ||','||GetTimeQuoted(StartTime)||' StartTime,'||GetTimeQuoted(EndTime)||' EndTime';
sqlStr := sqlStr || ' FROM ' || tableName ;sqlStr := sqlStr || contions;
sqlStr := sqlStr || ' GROUP BY ';
sqlStr := sqlStr || ' ID_Station,PID , Re_Result ';
sqlStr := sqlStr || ' ,Name_Station ';
sqlStr := sqlStr || ' ,Location ';
sqlStr := sqlStr || ' ,HOT_Name ' ;OPEN p_curosr FOR sqlstr;
END Pooling_GetStatisticsList;
...全文
1231 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Phoenix_99 2010-09-03
  • 打赏
  • 举报
回复
SQL> var cur refcursor;
SQL>exec POOLING_GETSTATISTICSLIST('a',1,'a',sysdate,sysdate,'a',:cur);
SQL>print :cur;

cnwz 2010-09-03
  • 打赏
  • 举报
回复
定义一个游标,执行后遍历游标,用语句查看你的游标内容
--测试:
declare
cur SYS_REFCURSOR;
l_data ADDBOOK%ROWTYPE;
begin
pinfo(cur);
loop
exit when cur%notfound;
FETCH cur INTO l_data;
DBMS_OUTPUT.put_line (l_data.col_name||' '||l_data.idx_name||' '||l_data.data_type||' '||l_data.nullable||' '||l_data.comments);
end loop;
CLOSE cur;
END;

参考这个试试看
vber1010 2010-09-03
  • 打赏
  • 举报
回复
得到返回的游标,和普通的一样用。
vber1010 2010-09-03
  • 打赏
  • 举报
回复
declare
v_cur p_myrefcursor.my_cursor;
begin
POOLING_GETSTATISTICSLIST('aa', 1, sysdate, sysdate, 'bbb', v_cur);
for cur in v_cur loop
--...
end loop;
--...
end;
minitoy 2010-09-03
  • 打赏
  • 举报
回复
sql窗口调用不了.
使用sqlplus按楼上的方法定义变量后调用存储过程,然后显示cursor内容
心中的彩虹 2010-09-03
  • 打赏
  • 举报
回复
[Quote=引用楼主 skyakon 的回复:]
CREATE OR REPLACE PROCEDURE POOLING_GETSTATISTICSLIST (
idstations in varchar2,
idresults in INT,
hotNames in VARCHAR,
startTime in DATE,
endtime in DATE,
PID in varchar2,
p_……
[/Quote]

var cur refcursor;

exec POOLING_GETSTATISTICSLIST('wkc',....,:cur);

print cur;


17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧