Saturday, July 7, 2018

Write a pl/sql code that will accept emp_no and debit amount from user. if Balance is below 500/- whenever you debit the amount then give error message. “Balance below 500/-“otherwise update the table


              Table: Emp
          
                                           Emp_no    Name       Balance
                                            1001           John         3000
                                            1002           Joly          4000
                                            1003          Tony         2000
                                            1004          Doly          500


          SQL> create table emp(Emp_no number(5),Name varchar2(10),Balance number(10,2));
          SQL> begin
                  insert into emp values('1001','John',3000);
                 insert into emp values('1002','Joly',4000);
                 insert into emp values('1003','Tony',2000);
                 insert into emp values('1004','Doly',500);
                end; 
                

           SQL> declare
                     debit number(10);
                     emp_no number(5);
                     a number(5);
                     b number(5);
                     c number(5);
                     d number(5);
                        
           begin
              emp_no:=&emp_no;
              debit:=&debit;
  
                    select balance into a from emp where emp_no='1001';
                     select balance into b from emp where emp_no='1002';
                     select balance into c from emp where emp_no='1003';
                     select balance into d from emp where emp_no='1004';
                          
             if emp_no=1001 then
                   if debit<a-500 then
                      update emp set balance=balance-debit where emp_no=1001;
             else
                      dbms_output.put_line('Your balance is not sufficient');
                        end if;
             elsif    
                      emp_no=1002 then
                      if debit<b-500 then
                      update emp set balance=balance-debit where emp_no=1002;
            else
                     dbms_output.put_line('Your balance is not sufficient');
                     end if;
           elsif 
                     emp_no=1003 then
                      if debit<c-500 then
                      update emp set balance=balance-debit where emp_no=1003;
           else
                   dbms_output.put_line('Your balance is not sufficient');
                   end if;
          elsif 
                   emp_no=1004 then
                    if debit<d-500 then
                    update emp set balance=balance-debit where emp_no=1004;
          else
                   dbms_output.put_line('Your balance is not sufficient');
                   end if;
          else
                   dbms_output.put_line('Not valid emp_no');
                   end if;
                   end;
                     /


        SQL> select * from emp; 
            output:
                 Enter value for emp_no: 1004
                  old  10: emp_no:=&emp_no;
                  new  10: emp_no:=1004;
               Enter value for debit: 100
                 old   11: debit:=&debit;
                  new  11: debit:=100;
              Your balance is not sufficient

Write a pl/sql code to give maximum salary of Rima or Rekha to Riya


   
               Name
 Salary
               Riya
               10000
               Rima
               6000
 Rekha
               8000

    



    SQL> declare

    a number(10);

    b number(10);

    c number(10);

     

    begin                                                                                                                                                            

   select salary into a from employee where name='Riya';

   select salary into b from employee where name='Rima';

   select salary into c from employee where name='Rekha';

   if b>c then

         update employee set salary=salary+b where name='Riya';

         update employee set salary=salary-b where name='Rima';

   else

         update employee set salary=salary+c where name='Riya';

         update employee set salary=salary-c where name='Rekha';

   end if;

   end;

   /


  output:

    SQL> select * from employee;

     NAME           SALARY

     ----------          ----------

    Riya               22200

    Rima              1800

    Rekha               0

Write a pl/sql code for add 50% salary of ‘Riya’ and 70% salary of ‘Rima’ To salary of ‘Rekha’.


    
   Table: Employee
                                   
           Name
 Salary
            Riya
           10000
            Rima
           6000
Rekha
           8000
                 
  
  


    SQL> create table Employee(Name varchar2(10),Salary number(10,2));

    SQL> insert into employee values('Riya',10000);

    SQL> insert into employee values('Rima',6000);

    SQL> insert into employee values('Rekha',8000);

SQL> declare

          a number(10);

          b number(10);

          c number(10);

   

   begin

   select salary into a from employee where name='Riya';

   select salary into b from employee where name='Rima';

   select salary into c from employee where name='Rekha';

   update employee set salary=salary+0.5*a+0.7*b where name='Rekha';

   update employee set salary=salary-0.5*a where name='Riya';

   update employee set salary=salary-0.7*b where name='Rima';

   end;
   /


   output:

     SQL> select * from employee;

     NAME           SALARY

     ----------          ----------

     Riya               5000

     Rima              1800

     Rekha            17200

Write a pl/sql code for calculator. Accept two values from user and accept Any operator like ‘+’,’-‘,’*’,’/’



   SQL> declare
              a number(5);

              b number(5);

              o varchar2(1);

    

              begin

              a:=&a;

              b:=&b;

              o:='&o';

   

    if o='+' then

              dbms_output.put_line(a+b);

    elsif o='-' then

              dbms_output.put_line(a-b);

    elsif o='*' then

              dbms_output.put_line(a*b);

    elsif o='/' then

              dbms_output.put_line(a/b);

    else

              dbms_output.put_line('not valid operation');

   end if;

   end;

   /


   output:

   Enter value for a: 97

     old   7: a:=&a;

     new   7: a:=97;

   Enter value for b: 5

     old   8: b:=&b;

     new   8: b:=5;

   Enter value for o: -

     old   9: o:='&o';

     new   9: o:='+';

     92



Write pl/sql code for following type output. ************************************* SQL,PL/SQL The Programming Language of ORACLE By- Ivan Bayross *************************************

1.                  
            SQL> BEGIN
     dbms_output.put_line('***************');
     dbms_output.put_line('PL/SQL');
     dbms_output.put_line('A programming language of ORACLE');
     dbms_output.put_line('By- Ivan Bayross');
     dbms_output.put_line('***************');
     END;
     /

    output:
    *************************************
    SQL,PL/SQL
    The Programming Language of ORACLE
    By- Ivan Bayross
    *************************************
                                                                                                       

Write a pl/sql code that will accept emp_no and debit amount from user. if Balance is below 500/- whenever you debit the amount then give error message. “Balance below 500/-“otherwise update the table

              Table: Emp                                                       Emp_no     Name        Balance               ...