Home » SQL & PL/SQL » SQL & PL/SQL » function returning more ...
function returning more ... [message #8249] Wed, 06 August 2003 03:27 Go to next message
Mubeen
Messages: 44
Registered: February 2003
Member
Hi All,

I have created a function with the following code

create or replace function q_lastname(v_jobid in employees.job_id%type)
return varchar2
is
v_lastname employees.last_name%type;
begin
select last_name into v_lastname from employees
where job_id = v_jobid;
return(v_jobid);
end;

Function created.

But i am getting the following error as the requested value is more than one row,so may i know how can i use cursors in a function and if possible please explain using the above function.

Elapsed: 00:00:00.00
SQL> execute :g_job_id := q_lastname('sa_rep')
BEGIN :g_job_id := q_lastname('sa_rep'); END;

*
ERROR at line 1:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "SCOTT.Q_LASTNAME", line 6
ORA-06512: at line 1

thanx in advance
mubeen.
Re: function returning more ... [message #8252 is a reply to message #8249] Wed, 06 August 2003 06:31 Go to previous messageGo to next message
Maaher
Messages: 7065
Registered: December 2001
Senior Member
This means that your query
SELECT last_name --(into v_lastname)  -- ommit the  part between brackets in plain sql
  FROM employees
 WHERE job_id = v_jobid;
returns more than one row while the PL/SQL engine only expects one. Test your query in SQL*Plus, it should only return one row. If not it returns the error you are talking about.

MHE
Re: function returning more ... [message #8266 is a reply to message #8249] Wed, 06 August 2003 17:40 Go to previous message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
In addition to what Maaher said, you need to take a closer look at what your function is doing. As it is right now, it is accepting a job_id, selecting the last_name that corresponds to that job_id, but then attempting to return the job_id. Do you want it to accept a job_id and return a last_name or accept a last_name and return a job_id?
Previous Topic: UTL_FILE - Invalid Path
Next Topic: How to re-write this trigger....
Goto Forum:
  


Current Time: Tue Apr 23 04:08:03 CDT 2024