Write a cursor to accept the student's name from the user as an input and display names of all teachers teaching that student.

Write a cursor to accept the student's name from the user as an

input and display names of all teachers teaching that student.









Write a cursor to accept the student's name from the user as an

input and display names of all teachers teaching that student.


---->>>


create or replace function std1(v varchar(25)) returns void as

'

declare


c1 cursor for select * from student  where name = v;

c2 cursor for select * from stdteach;

c3 cursor for select * from  Teacher;


r1 student%rowtype;

r2 stdteach%rowtype;

r3 Teacher%rowtype;


begin

open c1 ;

loop

    fetch c1 into r1;

    exit when not found;

            open c2;

                loop

                fetch c2 into r2;

                exit when not found;

                    if r1.rollno = r2.rollno then 

                    open c3;

                        loop

                            fetch c3 into r3;

                            exit when not found;

                                if r2.tno = r3.tno then 



            raise notice ''%  '',r3.tname;                                     

                           

                    end if;                                

                

                        end loop;

                    close c3;

                    end if;

                end loop;

            close c2;    


        

end loop;

close c1;

end;



'language'plpgsql';




Output of Cursor

Acode3=# select std1(' BBBB' );


o\p

Acode3=# select std1(' BBBB' );

NOTICE:   aa                   

NOTICE:   cc                   

NOTICE:   dd                   

NOTICE:   ee                   

 std1 

------

 

(1 row)



Post a Comment

0 Comments