Showing posts with label Oracle(PL/SQL). Show all posts
Showing posts with label Oracle(PL/SQL). Show all posts

Friday, 29 June 2012

Sum Of Digit's In PL/SQL


set serveroutput on
declare
N number(5);
s number(5):=0;
r number(5);
d number(5);
begin
n:=&N; 
while N<>0 loop
d:=mod(N,10);
s:=s+r+d;
end loop;
dbms_output.put_line('sum of digits is-'||s);
end;
/

Find Out greatest Of Three Number's In PL/SQL

declare
a number(10);
b number(10);
c number(10);
begin
a:=&a;
b:=&b;
c:=&c;
if(a>b)and(a>c) then
dbms_output.put_line('a is greater');
elsif(b>c) then
dbms_output.put_line('b is greater');
else
dbms_output.put_line('c is greater');
end if;
end;
/

Find Out Area nd Circumference In PL/SQL

set serveroutput on
declare
rad number(5):=&r1;
ar number(5,2);
circle number(5,2);
pie constant number(5,2):=3.14;
begin
ar:=pie*rad*rad;
circle:=2*pie*rad;
dbms_output.put_line('area of circle is'|| ar);
dbms_output.put_line('circumference is'||circle);
end;
/

How To Use If Block In PL/SQL


declare
a varchar2(30);
b varchar2(30);
c number(10);
t number(10,2);
begin
select ename,job,sal into a,b,c from emp where empno=7369;
if b='mgr' then
t:=c+(10/100)*c;
elsif b='president' then
t:=c+(20/100)*c;
elsif b='clerk' then
t:=c+(5/100)*c;
elsif b='peon' then
t:=c+(2/100)*c;
else
t:=0;
end if;
dbms_output.put_line('old sal is'||c);
dbms_output.put_line('new sal is'||t);
dbms_output.put_line('job is'||b);
end;

How To Use Cursor In PL/SQL


set serveroutput on
declare
cursor c1 is
select employee_id,first_name,job_id,salary from employees;
a employees.employee_id%type;
b employees.first_name%type;
c employees.job_id%type;
d employees.salary%type;
begin
open c1;
if c1%isopen then
loop
fetch c1 into a,b,c,d;
dbms_output.put_line(a || b||  c|| d);
exit when c1%notfound ;
end loop;
else
dbms_output.put_line('cursor not open');
end if;
close c1;
end;
/