Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.tools -> Re: PL/SQL cursor question

Re: PL/SQL cursor question

From: Paul <paul_fountain_at_my-deja.com>
Date: Tue, 09 Jan 2001 04:07:53 GMT
Message-ID: <93e2qm$t5c$1@nnrp1.deja.com>

I'm a bit rusty on PL/SQL but I'll give it a go. Expect a few syntax type errors but this should be pretty close to what you are after

cursor salary_cursor IS

	Select empno, salary
        from emp
        order by empno;

salary_record salary_cursor%rowtype;
new_salary varchar2;

BEGIN FOR salary_record in salary_cursor LOOP

IF (salary_record.salary <= 2000) THEN

   new_salary = salary_record.salary + (salary_record.salary * (8/100));

ELSEIF (salary_record.salary > 2000) AND (salary_record.salary < 2500)

   new_salary = salary_record.salary + (salary_record.salary * (6/100));

ELSEIF (salary_record.salary > 2500) AND (salary_record.salary < 3500)   new_salary = salary_record.salary + (salary_record.salary * (4/100));

ELSE
   new_salary = salary_record.salary + (salary_record.salary * (2/100));

END IF;

          UPDATE emp
          SET salary = new_salary
          WHERE empno = salary_record.empno;

END LOOP; COMMIT; END; In article <3a59f4b7.8039043_at_news.xs4all.nl>,   kltalsma_at_xs4all.nl (Klaas Talsma) wrote:
> I need to achieve the following
>
> using a cursor i need to update a table wich stores employee's and
> their salary, now i need to know how,
>
> the salary's up to 2000 need to by updated by 8%
> ,, .. from 2000 to 2500 need to be updated by 6%
> ,, ,, ,, 2500 to 3500 ,, ,, ,, updated by 4%
> and from 3500 and above updated by 2%
>
> i have no clue what so ever to do this with a cursor
>
> i'm able to do this with normal SQL but know i would like to know how
> to achieve this with a cursor
>
> can someone help me?
>
> grtnx,
>
> Klaas Talsma
>

Sent via Deja.com
http://www.deja.com/ Received on Mon Jan 08 2001 - 22:07:53 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US