我尝试编译以下程序并得到PLS-00103错误。
create or replace PROCEDURE getFlightDetails
(ticketNumberIn IN integer, fullName OUT varchar2(60), flightNumberOut OUT integer,
route OUT varchar2(50), durationInHours OUT number(6,4))
IS
BEGIN
select
pe.FirstName || ' ' || pe.LastName into fullName,
fl.FlightNumber into flightNumberOut,
fl.DepartureAirport || ' - ' || fl.ArrivalAirport into route,
ROUND((fl.ArrivalDate - fl.DepartureDate)*24,1) into durationInHours
from Purchase pu
inner join Person pe on pe.SSN = pu.SSN
inner join Ticket ti on ti.TicketNumber = pu.TicketNumber
inner join Flight fl on fl.FlightNumber = ti.FlightNumber
where pu.TicketNumber = ticketNumberIn;
END;
我做错了什么?我的意思是,我已经搜索了错误,找到的解释没有多大帮助。
答案 0 :(得分:1)
假设您的查询只返回一行,您只需要一个INTO
子句。您没有在投影中放置INTO
子句(您选择的列列表)。您也无法仅在数据类型的参数上指定长度。
create or replace PROCEDURE getFlightDetails
(ticketNumberIn IN integer, fullName OUT varchar2, flightNumberOut OUT integer,
route OUT varchar2, durationInHours OUT number)
IS
BEGIN
select
pe.FirstName || ' ' || pe.LastName,
fl.FlightNumber,
fl.DepartureAirport || ' - ' || fl.ArrivalAirport,
ROUND((fl.ArrivalDate - fl.DepartureDate)*24,1)
into fullName,
flightNumberOut,
route,
durationInHours
from Purchase pu
inner join Person pe on pe.SSN = pu.SSN
inner join Ticket ti on ti.TicketNumber = pu.TicketNumber
inner join Flight fl on fl.FlightNumber = ti.FlightNumber
where pu.TicketNumber = ticketNumberIn;
END;
与您的问题无关,我建议为您的参数提供一个命名约定,以区别于列名并使用一致。如果一个参数的名称为Out
但在所有其他OUT
参数上没有做同样的事情,则可能会造成混淆。就个人而言,我只使用参数<{p>的p_
前缀
create or replace PROCEDURE getFlightDetails
(p_ticketNumberIn IN integer,
p_fullName OUT varchar2,
p_flightNumber OUT integer,
p_route OUT varchar2,
p_durationInHours OUT number)
如果您希望pin_
和pout_
区分in
和out
参数,那就不合理了。