Monday 30 June 2014

pl/sql program to check weather given number is Prime or not.

Procedure:

  declare
       num number;
       i number:=1;
       c number:=0;
  begin
        num:=#
       for i in 1..num
       loop
          if((mod(num,i))=0)
           then
              c:=c+1;
         end if;
      end loop;
     if(c>2)
     then
         dbms_output.put_line(num||' not a prime');
     else
        dbms_output.put_line(num||' is prime');
     end if;
  end;
   /

Execution:

SQL> @e:\plsql\prime.sql
Enter value for num: 5
old   6:  num:=#
new   6:  num:=5;
5 is prime


Conclusion:
       A pl/sql program is successfully executed to check the given number is prime or not.

4 comments:

  1. can i install a compiler of sql and pl/sql in windows 7.?? if it is only for windows xp then i need to install it, but where to download that compiler for xp..??

    ReplyDelete
  2. I want code for find prime number using procedure concept in plsql

    ReplyDelete
  3. I want code for find prime number using procedure concept in plsql

    ReplyDelete
    Replies
    1. This is anonymous block.. please use it as procedure it will work for you :-)

      Delete

Copyright © ORACLE-FORU - SQL, PL/SQL and ORACLE D2K(FORMS AND REPORTS) collections | Powered by Blogger
Design by N.Design Studio | Blogger Theme by NewBloggerThemes.com