Showing posts with label for loop. Show all posts
Showing posts with label for loop. Show all posts

Prime Number From a Table

Write a pl/sql source code to check all data from a student_id column of a student table. After check show all student_id which are prime.


Hits: PL/SQL code with Table/View

SQL> create table studentt
2 (
3 student_id number(10),
4 student_name varchar(20)
5 );

Table created.


SQL> insert into studentt
2 values
3 (5,'aaa');

1 row created.


SQL> declare
2 a number(10);
3 b number(10);
4 c number(10):=1;
5 begin
6 select student_id into a from studentt;
7 for b in 2..a/2 loop
8 if (a mod b)=0 then
9 c:=0;
10 exit;
11 end if;
12 end loop;
13 if(c=1)then
14 dbms_output.put_line('student_id is a prime number');
15 else
16 dbms_output.put_line('student_id is not a prime number');
17 end if;
18 end;
19 /

Prime Number From a Table

Write a pl/sql source code to check all data from a student_id column of a student table. After check show all student_id which are prime.


Hits: PL/SQL code with Table/View

SQL> create table studentt
2 (
3 student_id number(10),
4 student_name varchar(20)
5 );

Table created.


SQL> insert into studentt
2 values
3 (5,'aaa');

1 row created.


SQL> declare
2 a number(10);
3 b number(10);
4 c number(10):=1;
5 begin
6 select student_id into a from studentt;
7 for b in 2..a/2 loop
8 if (a mod b)=0 then
9 c:=0;
10 exit;
11 end if;
12 end loop;
13 if(c=1)then
14 dbms_output.put_line('student_id is a prime number');
15 else
16 dbms_output.put_line('student_id is not a prime number');
17 end if;
18 end;
19 /

Popular Posts