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: Klaas Talsma <kltalsma_at_xs4all.nl>
Date: Tue, 09 Jan 2001 11:57:22 GMT
Message-ID: <3a5afc47.941114@news.xs4all.nl>

Thanks, that is ideed what i was looking for however i shoud be able to store the salary into a variable and save some code, with the variable it should be possible to use only one if statement, i'm i correct?

GRTNX, Klaas Talsma

>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
> -- implicit open and fetch
>
>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 Tue Jan 09 2001 - 05:57:22 CST

Original text of this message

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