create or replace procedure flight_search(
v_source in flights.origin_ap%type,
v_destination in flights.destination_ap%type,
v_date in flights.depart_date%type,
v_flightid out flights.flightid%type,
v_fare out flights.fare%type)
is
cursor search_flight is SELECT flightid FROM flights
where v_source = origin_ap and v_destination = destination_ap and v_date =
depart_date;
begin
open search_flight;
loop
fetch search_flight into v_flightid;
exit when search_flight%NOTFOUND;
dbms_output.put_line('Leaves from - ' || v_source || '. Arrives at - ' ||
v_destination || '. Fare - ' || v_fare);
end loop;
close search_flight;
end;
通过
执行execute flight_search('JFK', 'LHR', '11/25/18');
在呼叫flairs_search中获得错误的数字或参数类型。我假设这与flightid和票价变量有关。
您的过程有5个正式参数,您的呼叫只有3。您需要在某个地方提供out
变量。正如您似乎使用的是SQL*Plus或SQL开发人员(根据execute
来判断,您可以使用绑定变量,然后在调用后将其打印出来:
variable l_flightid number;
variable l_fare number;
execute flight_search('JFK', 'LHR', date '2018-11-25', l_flightid, l_fare);
print l_flightid
我还将第三个参数更改为实际日期,而不是必须使用当前的会话NLS设置将其隐式转换为日期的字符串。我已经使用了日期,但是您也可以将to_date()
与字符串文字和合适的格式蒙版使用。
顺便说一句,您当前没有填充v_fare
。因此,我没有打扰通话后打印该变量;而且并不是很明显它的来源。您可能需要考虑使用隐式光标循环而不是显式循环。