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 

    

No comments:

Post a Comment