在oracle上的存储过程中返回单行

时间:2014-05-21 01:41:58

标签: php sql oracle

我正在使用php&神谕。 如何在存储过程中返回一行,就像选择查询一样,以便我可以将它们读入php。 例如

declare or replace procedure select_row 
(
bookingid in integer,
result out varchar2
) as 
begin
select * into result from booking where booking.id = bookingid;
end;

1 个答案:

答案 0 :(得分:1)

如果你打算像这样使用它,你需要选择一个特定的字段。

declare or replace procedure select_row 
(
    bookingid in integer,
    result out varchar2
) as 
begin
    select booking_name into result from booking where booking.id = bookingid;
end;

否则,您需要先创建一个对象类型,然后在对象类型中选择多个字段并返回该字段。你必须创建OBJECT或创建记录。

CREATE OBJECT BOOKING_OBJ AS (
     bookingid INTEGER
    ,booking_name VARCHAR2(128)
);

declare or replace procedure select_row 
(
    bookingid in integer,
    result out BOOKING_OBJ
) as 
begin
    select booking_obj(bookingid, booking_name) into result from booking where booking.id = bookingid;
end;

或者...

CREATE TYPE BOOKING_REC as record(
    bookingid integer,
    booking_name varchar2(100)
);

declare or replace procedure select_row 
(
    bookingid in integer,
    result out BOOKING_REC
) as 
begin
    select bookingid, booking_name into result from booking where booking.id = bookingid;
end;

或者,您可以返回引用光标。