Simple Oracle Stored Procedure

Source: Internet
Author: User
Simple Oracle Stored Procedure

-- The salary is increased by 500, old. SAL> 2500 not added, new. SAL> 2500 is changed to 2500;

Select * from EMP -- before salary increase

Create or replace procedure sp_add (add in number) is -- add parameter receives incoming salary increase

-- Declare
-- Cursor emp_cur is select * from EMP;

Begin

For sal_sum in (select * from EMP) loop -- open the cursor emp_cur or

-- (Select * from EMP) (this cursor does not need to be declared in the for loop)
-- Automatically retrieves rows from the activity set and closes the cursor after processing all rows
If sal_sum.sal> 2500 then -- compare values by row
Update EMP set sal = sal_sum.sal where empno = sal_sum.empno;

Elsif (sal_sum.sal + Add) & gt; 2500 then
Update EMP set sal = 2500 where empno = sal_sum.empno;

Else
Update EMP set sal = sal_sum.sal + Add where empno = sal_sum.empno;
End if;

End loop;

End;

Begin

Sp_add (500 );
-- Input the increment range


End;

select * from EMP -- after salary increase

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.