PL/SQL: ORA-00913: too many values

2.5k views Asked by At

i am trying to create a sql function that prints the reservations made by a customer when his name is beeing given. The customers names are in a table called CLIENTS.FNAME CLIENTS.MNAME CLIENTS.LNAME and the reservations searched by an id- foreign key there is the code for the function that shows a 'too many values" error, maybe it has to be done by Loop or something?

create or replace FUNCTION cl_reserv(clName VARCHAR2)

RETURN RESERVATIONS%ROWTYPE

IS
resRecord RESERVATIONS%ROWTYPE;

BEGIN
  SELECT RESID,STARTDATE,ENDDATE,ADDINFO INTO resRecord
           FROM RESERVATIONS INNER JOIN CLIENTS ON RESERVATIONS.CLIENTID=CLIENTS.CLIENTID
           WHERE clName IN (FNAME,MNAME,LNAME);
RETURN resRecord;
END;
1

There are 1 answers

2
Codo On BEST ANSWER

Your SELECT clause doesn't match with the record you're trying to select into. Change your code like this:

CREATE OR REPLACE FUNCTION cl_reserv(clName VARCHAR2)
    RETURN RESERVATIONS%ROWTYPE 
IS
    resRecord RESERVATIONS%ROWTYPE;

BEGIN
  SELECT r.* INTO resRecord
           FROM RESERVATIONS r INNER JOIN CLIENTS c ON r.CLIENTID=c.CLIENTID
           WHERE clName IN (FNAME,MNAME,LNAME);
    RETURN resRecord;
END cl_reserv;

By using r.*, you select exactly the number, type and sequence of columns that are needed for the record type.