There are a couple of problems with your code.
Firstly, the not enough values
error was because you are querying 7 columns and only providing one variable to put them in in the INTO
clause. However, you don't use the INTO
clause when looping over the results of a query that way, so the first thing you can do is to get rid of it. Your loop variable x
will contain each row of data read from your Employee_details
table, you don't need another variable for it.
The next thing to note is that you declared e_ret
of type e_record_table
. Your pipelined function returns e_record_table
, but the type of each row you pipe out needs to be the type your table type contains, not the table type. The expression is of wrong type
error is because you were attempting to pipe out a value of type e_record_table
. Anyway, you're not selecting anything into e_ret
any more, so you can just delete this local variable.
Your loop variable x
contains each row read from the query. As written, it contains 7 values, so you could create an e_record
row to pipe back using something like the following:
pipe row(e_record(x.e_uid, x.e_first_name, x.e_surname, x.e_age, ...));
However, that makes quite a lot of typing since you are repeating the list of columns in your query. You can avoid the duplicated typing by creating the record in the query and then piping that out:
for x in(select e_record(e_uid,e_first_name,e_last_name,e_age,e_department,e_designation,e_salary) as emp from Employee_details) Loop
pipe row(x.emp);
End Loop;
The full working function is below:
Function list_empDetails return e_record_table pipelined
IS
Begin
for x in(select e_record(e_uid,e_first_name,e_last_name,e_age,e_department,e_designation,e_salary) as emp from Employee_details) Loop
pipe row(x.emp);
End Loop;
return;
end list_empDetails;