I've written a simple cursor to update one or two columns dependant upon criteria.
This works fine,
DECLARE
v_playerid player_details.playerid%TYPE;
v_wage player_details.wage%TYPE;
v_nationalityid player_details.nationalityid%TYPE;
CURSOR c_Wagecalc IS
SELECT Playerid, Wage, Nationalityid FROM Player_Details;
BEGIN
OPEN c_Wagecalc;
LOOP
FETCH c_Wagecalc INTO v_playerid, v_wage, v_nationalityid;
EXIT WHEN c_Wagecalc%NOTFOUND;
IF v_nationalityid = '1'
THEN UPDATE Player_Details
SET Basic_wage = v_wage
WHERE Playerid = v_playerid;
ELSE
UPDATE Player_details
SET Basic_wage = (v_wage*0.80), Bonus = (v_wage*0.20)
WHERE Playerid = v_playerid;
END IF;
END LOOP;
END;
/
Yet this doesn't
DECLARE
v_playerid player_details.playerid%TYPE;
v_wage player_details.wage%TYPE;
v_nationalityid player_details.nationalityid%TYPE;
CURSOR c_Wagecalc IS
SELECT Playerid, Wage, Nationalityid FROM Player_Details;
BEGIN
OPEN c_Wagecalc;
LOOP
FETCH c_Wagecalc INTO v_playerid, v_wage, v_nationalityid;
EXIT WHEN c_Wagecalc%NOTFOUND;
IF v_nationalityid = '1'
THEN UPDATE Player_Details
SET Basic_wage = v_wage
WHERE Playerid = v_playerid;
ELSE
UPDATE Player_details
SET Basic_wage = (v_wage*0.80), Bonus = (v_wage - Basic_wage)
WHERE Playerid = v_playerid;
END IF;
END LOOP;
END;
/
The only difference being
Bonus = (v_wage - Basic_wage)
Is this failing to populate a column because of the order of precedence of operators ?
This works fine,
DECLARE
v_playerid player_details.playerid%TYPE;
v_wage player_details.wage%TYPE;
v_nationalityid player_details.nationalityid%TYPE;
CURSOR c_Wagecalc IS
SELECT Playerid, Wage, Nationalityid FROM Player_Details;
BEGIN
OPEN c_Wagecalc;
LOOP
FETCH c_Wagecalc INTO v_playerid, v_wage, v_nationalityid;
EXIT WHEN c_Wagecalc%NOTFOUND;
IF v_nationalityid = '1'
THEN UPDATE Player_Details
SET Basic_wage = v_wage
WHERE Playerid = v_playerid;
ELSE
UPDATE Player_details
SET Basic_wage = (v_wage*0.80), Bonus = (v_wage*0.20)
WHERE Playerid = v_playerid;
END IF;
END LOOP;
END;
/
Yet this doesn't
DECLARE
v_playerid player_details.playerid%TYPE;
v_wage player_details.wage%TYPE;
v_nationalityid player_details.nationalityid%TYPE;
CURSOR c_Wagecalc IS
SELECT Playerid, Wage, Nationalityid FROM Player_Details;
BEGIN
OPEN c_Wagecalc;
LOOP
FETCH c_Wagecalc INTO v_playerid, v_wage, v_nationalityid;
EXIT WHEN c_Wagecalc%NOTFOUND;
IF v_nationalityid = '1'
THEN UPDATE Player_Details
SET Basic_wage = v_wage
WHERE Playerid = v_playerid;
ELSE
UPDATE Player_details
SET Basic_wage = (v_wage*0.80), Bonus = (v_wage - Basic_wage)
WHERE Playerid = v_playerid;
END IF;
END LOOP;
END;
/
The only difference being
Bonus = (v_wage - Basic_wage)
Is this failing to populate a column because of the order of precedence of operators ?