for in loop

Hi,

Below is the pl sql code i am trying to execute but i am getting an error.

create or replace
PROCEDURE PROCEDURE2 IS
  inst varchar2(5);
  cursor c_student is select * from PS_SCRTY_TBL_STGP;
  r_student c_student%ROWTYPE;
BEGIN
  open c_student;
 
  loop
   fetch c_student into r_student;
 
   for inst in (select INSTITUTION from PS_SCRTY_TBL_INST where OPRID=r_student.OPRID)
   loop
   
    /*if eachInstitution !=r_student.INSTITUTION THEN*/
    DBMS_OUTPUT.PUT_LINE(inst);
     /*delete from PS_SCRTY_TBL_STGP where OPRID=r_student.OPRID and INSTITUTION=inst;*/
       
   /*END IF;*/
   end loop ;
  end loop;
   close c_student;
END PROCEDURE2;

Error(16,5): PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'

1) Why am i getting this error?

2) lso i would like to know whether my approach of looping through the record is correct?
sriramvemaraju2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
1: inst is an object. You need:   DBMS_OUTPUT.PUT_LINE(inst.INSTITUTION )

2:  don't know.  What are you trying to do?

If I understand, I'm thinking you don't need the cursor at all.


On mobile so cannot get a great look at the code but something like:

...
 for inst in (select INSTITUTION from PS_SCRTY_TBL_INST where OPRID in (select OPRID from PS_SCRTY_TBL_STGP))
   loop

...


0
sdstuberCommented:
better would be to skip looping altogether and simply delete in one step.

less code and more efficient

CREATE OR REPLACE PROCEDURE procedure2
IS
BEGIN
    DELETE FROM ps_scrty_tbl_stgp stgp
     WHERE EXISTS
               (SELECT NULL
                  FROM ps_scrty_tbl_inst inst, ps_scrty_tbl_stgp r_student
                 WHERE inst.oprid = r_student.oprid
                   AND stgp.oprid = r_student.oprid
                   AND stgp.oprid = inst.oprid
                   AND stgp.institution = inst.institution);
END;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
schwertnerCommented:
You definevariable  called 'inst':

inst varchar2(5);

After that you try to use it in a LOOP:

for inst in (select INSTITUTION ....

You do not need to do this.

Fix:

1. Comment or delete  this definition

--  inst varchar2(5);

2. Change

DBMS_OUTPUT.PUT_LINE(inst);

with

DBMS_OUTPUT.PUT_LINE(inst.institution);
0
sriramvemaraju2000Author Commented:
Thanks every one!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.