Showing posts with label dbms_output.put_line. Show all posts
Showing posts with label dbms_output.put_line. 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 /

Strange Number

Write a program to check whether a given number is strange or not using pl/sql.


declare
digit number;
temp number;
rem number;
i number;
j number;
begin
digit:=&d;
while digit!=0 loop
j:=digit/10;
rem:=mod(digit,10);
digit:=j;
for i in 2..rem-1 loop
if mod(rem,i) <> 0 then
temp:=0;
exit;
end if;
end loop;
end loop;
if temp <> 1 then
dbms_output.put_line('strange number');
else
dbms_output.put_line(' not strange number');
end if;
end;

Popular Posts