Просто показывая вам пример (если вы хотите именно то, что вам нужно, а не только почему, согласно вашему тестовому сценарию), вы можете достичь своих результатов довольно просто.Я собрал тестовый набор, чтобы показать вам
create table HOTELS (hname varchar2(50) ) ; --create table for test
declare --put data into it for test
i number ;
begin
for i in 1 .. 50 loop
insert into hotels (hname) values('Hotel: ' || i);
end loop ;
commit ;
end ;
/
- теперь создайте процедуру и покажите результаты
set serveroutput on
declare
resultQuery sys_refcursor ;
countOfHotels number ;
hotelName HOTELS.hname%type ;
procedure getHotels(HotelCount out number ,
HotelList out nocopy sys_refcursor) is
begin
select count(*)
into HotelCount
FROM HOTELS ;
open HOTELLIST For
select *
from HOTELS ;
end getHotels;
begin
getHotels(countOfHotels, resultQuery) ;
dbms_output.put_line('Count Of Hotels ' || countOfHotels);
loop
fetch resultQuery into hotelName;
exit when resultQuery%notfound;
dbms_output.put_line('Found Hotel: ' || hotelName);
end loop;
end ;
А теперь для результатов:
/**
results
Count Of Hotels 50
Found Hotel: Hotel: 1
Found Hotel: Hotel: 2
Found Hotel: Hotel: 3
Found Hotel: Hotel: 4
Found Hotel: Hotel: 5
....
**/
но вся работа здесь выполняется:
procedure getHotels(HotelCount out number ,
HotelList out nocopy sys_refcursor) is
begin
select count(*)
into HotelCount
FROM HOTELS ;
open HOTELLIST For
select *
from HOTELS ;
end getHotels;
Вы выбираете переменные , а затем открываете REFCURSOR FOR курсоры