Anu
Anu

Reputation: 176

construct to be used in a for loop

I have sample Data like:

Table empdata:

Name    Desig       Sal
-------------------------
john    staff       26000
sen     owner       50000
smith   assistant   10000

i want to print each of the columns like

Current field value is : John
Current field value is : staff
Current field value is : 26000
Current field value is : sen
Current field value is : owner
Current field value is : 50000.. and so on

I am able to use cursor to fetch the emp data:

cursor c1 is 
select name, desig, sal from empdata;

but i want to iterate over the columns too. I have shown 3 columns here, but there are atleast 30 columns in actual data, and i would like to print each of the field. Please help.

Upvotes: 0

Views: 15

Answers (2)

Boneist
Boneist

Reputation: 23578

If I understand you correctly, I think you're after something like:

select name,
       desig,
       sal,
       (select approved from approval_table apv1 where apv1.data = emp.name) name_aprvd,
       (select approved from approval_table apv2 where apv2.data = emp.desig) desig_aprvd,
       (select approved from approval_table apv3 where apv3.data = emp.sal) sal_aprvd
from   empdata emp;

Quite what you expect to do with the information once you've got it, I'm not sure. Maybe you return this as a cursor? Maybe you pass it into a procedure? I'm not sure, but hopefully you have enough information to sort out your requirement?

Upvotes: 0

vishnu sable
vishnu sable

Reputation: 358

Hi you can use this kind basic code.

begin
 for i in (select * from emp where rownum < 5)
    Loop
     dbms_output.put_line('Current field value is: '||i.Emp_id);
     dbms_output.put_line('Current field value is: '||i.emp_name);
    end loop;
end;

Upvotes: 1

Related Questions