Sunday 19 February 2012

pl/sql best examples

Best links for mp3 and movie downloads

To learn UNIX basic commands click here
To learn Shell Script click here

Below is example code of pl/sql concepts
Addition of two numbers:

declare
 a number:=10;
 b number:=20;
 c number;
 begin
 c:=a+b;
 dbms_output.put_line(c);
 end;
 /

getting value from table and storing it in a variable and displaying it

declare
v_name varchar2(10);
begin
select ename into v_name from emp where empno=102;
 dbms_output.put_line('The emp name with emp no:102 is'|| v_name);
end;
/



Pay roll program in pl/sql
 declare
 eno number(5):=1245;
 ename varchar2(50):='jayachandran';
 ebasic number(7,2):=3000;
epf  number(7,2);
ehra number(7,2);
eda number(7,2);
ethome number(9,2);
begin
 epf:=0.02;
 epf:=epf*ebasic;
 ehra:=.12*ebasic;
 eda:=0.05*ebasic;
 ethome:=eda+ehra+ebasic-epf;
 dbms_output.put_line('Employee number ='||eno);
 dbms_output.put_line('Employee Name ='||ename);
 dbms_output.put_line('Employee take home ='||ethome);
 end;
/




 %type example in pl/sql

 declare
 v_name emp.ENAME%type;
begin
select ename into v_name from emp where empno=102;
 dbms_output.put_line('The emp name with emp no:102 is'|| v_name);
end;
/


if - else - if example in pl/sql
create table marks(name varchar2(10),math number(3),english number(3),tamil number(3));
declare
            stu marks.name%type;
            mat marks.math%type;
            eng marks.english%type;
            tam marks.tamil%type;
            tot marks.tamil%type;
            per number(5,2);
begin
            select  math,english,tamil into mat,eng,tam from marks where name = 'bala';
            tot:=mat+eng+tam;
            per:=((tot/300)*100);
            if(per = 100) then
                        dbms_output.put_line('you have scored s grade');
            else
                        if(per < 50) then
                                    dbms_output.put_line('you failed in exam');
            else
                        dbms_output.put_line('you passed exam');
            end if;
            end if;
end;
/


Go to session - 2

1 comment:

  1. awesome bro thanks to u..:)
    but need more explanation on %type and %rowtype.

    ReplyDelete