I wrote a package to query rows from a table. This select query will call other functions and returns all the rows from table. But when i write a package with all functions and sprocs , my sproc with select statement gives me an error saying i cannot execute without into statement. But if i use into then it will return only one row. How can i retrieve all rows using oracle sp?
Procedure GetData As
BEGIN
Select Jobid, JobName, JobLocation, JobCompany, X(jobid) FROM jobsTable; END GetData;
END;
I had to change it to following make the error go away:
Procedure GetData As
r_Jobid jobsTable.jobid%type;
r_JobName jobsTable.jobName%type;
r_JobLocation jobsTable.jobLocation%type;
r_temp varhar2(10);
BEGIN
Select Jobid, JobName, JobLocation, JobCompany, X(jobid)
INTO r_jobid, r_jobName, r_jobLocation, r_temp
FROM jobsTable;
END GetData;
END;
This is a better approach to returning multiple rows from a function:
I agree with afk though that this doesn’t appear to be what you really need to be using. Here’s my recommendation for using a cursor:
Are you aware that this:
…means you defined local variables? You won’t be able to get information out of the procedure. If you do, you’d need parameters, like this:
I use the IO_ to note which parameters are IN/OUT. I’d use IN_ or OUT_ where applicable. But the key here is to define OUT if you want to get a parameter back out.
Also – packages are just logical grouping of procedures & functions, with the ability to define constants scoped to the package. The package itself doesn’t execute any SQL – it’s still a function or procedure that is executing. God how I wish SQL Server had packages…