Nidhin_toms
Nidhin_toms

Reputation: 737

procedure creation issue

I am trying to create a procedure that will list out all contents of a table but oracle tells me that the procedure has compilation errors. I am running on SQL plus. Any ideas?

CREATE OR REPLACE procedure payrollproc
BEGIN
SELECT * FROM payroll;
END;

Upvotes: 0

Views: 832

Answers (2)

Maurice Reeves
Maurice Reeves

Reputation: 1583

The answer is right in the error message: You're missing a keyword before BEGIN. If you were to put the word IS before BEGIN, it will compile. See here for more details. Also, you will need a cursor to view the details. Best of luck.

Upvotes: 0

Anjan Biswas
Anjan Biswas

Reputation: 7912

CREATE OR REPLACE procedure payrollproc as
BEGIN
   for c_rec in ( SELECT * FROM payroll)
   Loop
       dbms_output.put_line(c_rec.col1 || '  ' || c_rec.col2 || ' ' || ......);
   End loop;
END;
/

But, I would suggest just run the select statement, a stored proc is too much work for such a basic function.

Upvotes: 1

Related Questions