Print Oracle Pl/sql Cursor

264 Views Asked by At

Can I directly open and print cursor in begin end block without using loops? or without reading each column and printing it individually for each row.

1

There are 1 best solutions below

0
Nancy Guruswamy On

If you want to display one record there is no need for looping in your cursor. If multiple then you need looping in cursor. Eg In **Test_Project** Table has two column:-

projectid           projectname 

p2                  Programming     
p1                 Search Engine    
p3                 Testing

--Below is the code to display one record without using loop

Declare 

   cprojname varchar2(2000)   ;

   CURSOR c1
   IS
      select project_name from test_project WHERE projectid='p1';

BEGIN

   OPEN c1;
   FETCH c1 INTO cprojname;

   if c1%notfound then
      cprojname := 'no data';
   else
   dbms_output.put_line(cprojname);

   end if;

   CLOSE c1;

END;

o/p:- Search Engine