Wednesday, 14 January 2015

PL/SQL program to create employe table and insert employment number, name, salary. If it is above 30000 don't perform update operation

Create employee table

     Sql>create table employee(empno varchar2(20),ename varchar2(20),sal number(8,2));

Insert data into employee table
     
     Sql>insert into employee('1001','bcd',10000);

     Sql>insert into employee('1002','abc','1000);

     Sql>insert into employee('1003','xyz',5000);

     Sql>insert into employee('1004','gani',5000);

Program 


    Declare
    emp_no varchar2(20);
    upd_sal number(5);
    total_sal number(8,2);
    begin
    emp_no:='&emp_no';
    upd_sal:='&upd_sal';
    Insert into employee values('1005','ganesh', 2000);
    savepoint no_update;
    update employee set_sal=sal+upd_sal where empno=emp_no;
    select sum(sal) into total_sal from employee;
    if total_sal>30000 then
    rollback to savepoint no_update;
    dbms_output.put_line('no update, we are exceeding the total salary 30000) ;
    else
    dbms_output.put_line('salary updated successfully to the account:'|| emp_no) ;
    end if;
    end;
    /
   
 
 Create your own website

        Click here 

    

Friday, 9 January 2015

Pl/sql program to debit the amount and check the minimum bal 500 while debiting the account

Sql>Create table account(name varchar2(20),anumber varchar2(15),bal number(8,2));

Output: Table created

Sql>insert into account values('abc','101',5000);

Output: row inserted

Sql>insert into account values('abcd','102',500);

Output: row inserted

Sql>insert into account values('ganesh','103',3000);

Output: row inserted.

Sql>insert into account values('raju','104',1000);

Output: row inserted

Sql>insert into account values('gani','105',9000);

Output: row inserted.

Program:

 
declare
acct _bal number(8,2);
acct_no varchar2(15);
debit_amt number(5);
min_bal Number(5);=500;
begin
acct_no:=&acct_no;
debit_amt:=&debit_amt;
select bal into acct_bal from account
      where anumber=acct_no;
acct_bal:=acct_bal-debit_amt;
if  acct_bal>=min_bal then
update account set bal=bal-debit_
     amt where anumber:=acct_no;
else
dbms_output.put_line('insufficient
     bal in the output ');
end if;
end;
/

Sunday, 4 January 2015

PL/SQL program to display the numbers in recursive order

Program:

      Declare 
          a number(4);
          rev number(4);
          d number(4);
      begin 
          a:=&a;
          rev:=a;
      while a>0
      Loop
          d:=mod(a,10);
          rev=(rev*10)+d;
          a:=trunc(a/10);
     end loop;
     dbms. output. put_line('rev ='¦¦rev) ;
     end;
     /