PL/SQL 如何执行带返回游标的存储过程 !(SQL 窗口中如何调用)
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;