I am trying to change the value of "TOTAL_TM_R_PT" where all the times a certain player shows up.
create or replace PROCEDURE CalculatePlayerTMPoints(Player IN NUMBER,PointNum IN NUMBER)
DECLARE PtValue INT;
UserNM TABLE;
BEGIN
SELECT POINT_VALUE INTO PtValue FROM POINTS WHERE POINTS.POINT_ID = PointNum;
SELECT ACCT_USERNAME INTO UserNM FROM ROSTERS WHERE ROSTERS.PLAYER_ID = Player;
for i in 1..UserNM.count
loop
UPDATE TEAM_MANAGER_POINTS
SET TOTAL_TM_R_PT = TOTAL_TM_R_PT + PtValue
WHERE TEAM_MANAGER_POINTS.ACCT_USERNAME = UserNM;
End loop;
END;
This is my error:
Error(3,1): PLS-00103: Encountered the symbol "DECLARE" when expecting one of
the following: ; is with authid as cluster order using external
deterministic parallel_enable pipelined result_cache accessible
Any ideas?
答案 0 :(得分:1)
您需要定义集合类型并使用BULK COLLECT INTO
将查询结果存储在集合中。 1}}代码中也缺少AS
关键字,使用Declare
无效。
create or replace PROCEDURE CalculatePlayerTMPoints(Player IN NUMBER,PointNum IN NUMBER) AS
PtValue INT;
TYPE usertype IS TABLE OF ROSTERS.ACCT_USERNAME%TYPE;
UserNM usertype ;
BEGIN
SELECT POINT_VALUE INTO PtValue FROM POINTS WHERE POINTS.POINT_ID = PointNum;
SELECT ACCT_USERNAME BULK COLLECT INTO UserNM FROM ROSTERS WHERE ROSTERS.PLAYER_ID = Player;
for i in 1..UserNM.count
loop
UPDATE TEAM_MANAGER_POINTS
SET TOTAL_TM_R_PT = TOTAL_TM_R_PT + PtValue
WHERE ACCT_USERNAME = UserNM(i);
End loop;
END;