为什么小弟我将一个显式游标和一个隐式游标一起用,只能显示出隐式游标的结果
为什么我将一个显式游标和一个隐式游标一起用,只能显示出隐式游标的结果?
create or replace PROCEDURE CUSTOMER_BOOKED_AT_A_CONCERT
(concert_id in number)
AS
venue_name W_CONCERT.VENUENAME%type;
street_address w_concert.streetaddress%type;
city_name w_concert.city%type;
country_name w_country.countryname%type;
linecount number(4);
concertline number(4);
cursor customercursor is select lastname, firstname, quantity, ticketprice
from w_customer, W_booking, w_concert
where W_CONCERT.CONCERTID=w_booking.concertid and W_CUSTOMER.CUSTOMERID=W_booking.CUSTOMERID and w_concert.concertid=concert_id;
lastname_cursor W_CUSTOMER.LASTNAME%type;
firstname_cursor W_CUSTOMER.FIRSTNAME%type;
quantity_cursor W_BOOKING.QUANTITY%type;
ticketprice_cursor W_CONCERT.TICKETPRICE%type;
BEGIN
linecount:=0;
concertline:=0;
select venuename, streetaddress, city, countryname into venue_name, street_address, city_name, country_name
from w_concert, w_country
where w_country.COUNTRYID=w_concert.COUNTRYID and w_concert.concertid=concert_id;
DBMS_OUTPUT.PUT_LINE('venue name ' ||venue_name|| 'street name : ' ||street_address|| 'city is '||city_name|| 'country ' ||country_name);
exception
when no_data_found then
DBMS_OUTPUT.PUT_LINE('no concert');
open customercursor;
loop
fetch customercursor into lastname_cursor, firstname_cursor, quantity_cursor, ticketprice_cursor;
exit when customercursor%notfound;
DBMS_OUTPUT.PUT_LINE('last name ' ||lastname_cursor|| ' first name : ' ||firstname_cursor|| 'quantity is '||quantity_cursor|| 'total price is ' ||quantity_cursor*ticketprice_cursor);
linecount:=linecount+1;
end loop;
if linecount=0 and concertline=0 then
DBMS_OUTPUT.PUT_LINE('no artist') ;
end if;
close customercursor;
END CUSTOMER_BOOKED_AT_A_CONCERT;
运行结果显示只有venue name Town Greenstreet name : 2 George Streetcity is Sydneycountry Australia, 但是下面的customercursor的查询就不显示。但是我把位置换下,把customercursor移到上面,两个查询就都能显示了,这是为什么?
------解决方案--------------------
create or replace PROCEDURE CUSTOMER_BOOKED_AT_A_CONCERT
(concert_id in number)
AS
venue_name W_CONCERT.VENUENAME%type;
street_address w_concert.streetaddress%type;
city_name w_concert.city%type;
country_name w_country.countryname%type;
linecount number(4);
concertline number(4);
cursor customercursor is select lastname, firstname, quantity, ticketprice
from w_customer, W_booking, w_concert
where W_CONCERT.CONCERTID=w_booking.concertid and W_CUSTOMER.CUSTOMERID=W_booking.CUSTOMERID and w_concert.concertid=concert_id;
lastname_cursor W_CUSTOMER.LASTNAME%type;
firstname_cursor W_CUSTOMER.FIRSTNAME%type;
quantity_cursor W_BOOKING.QUANTITY%type;
ticketprice_cursor W_CONCERT.TICKETPRICE%type;
BEGIN
linecount:=0;
concertline:=0;
select venuename, streetaddress, city, countryname into venue_name, street_address, city_name, country_name
from w_concert, w_country
where w_country.COUNTRYID=w_concert.COUNTRYID and w_concert.concertid=concert_id;
DBMS_OUTPUT.PUT_LINE('venue name ' ||venue_name|| 'street name : ' ||street_address|| 'city is '||city_name|| 'country ' ||country_name);
exception
when no_data_found then
DBMS_OUTPUT.PUT_LINE('no concert');
open customercursor;
loop
fetch customercursor into lastname_cursor, firstname_cursor, quantity_cursor, ticketprice_cursor;
exit when customercursor%notfound;
DBMS_OUTPUT.PUT_LINE('last name ' ||lastname_cursor|| ' first name : ' ||firstname_cursor|| 'quantity is '||quantity_cursor|| 'total price is ' ||quantity_cursor*ticketprice_cursor);
linecount:=linecount+1;
end loop;
if linecount=0 and concertline=0 then
DBMS_OUTPUT.PUT_LINE('no artist') ;
end if;
close customercursor;
END CUSTOMER_BOOKED_AT_A_CONCERT;
运行结果显示只有venue name Town Greenstreet name : 2 George Streetcity is Sydneycountry Australia, 但是下面的customercursor的查询就不显示。但是我把位置换下,把customercursor移到上面,两个查询就都能显示了,这是为什么?
------解决方案--------------------