variable. In my 2nd query in the predicate, I want to place the tablecolumn = the variable
value.
I have tried simply using the variable after the '=' sign in the SQL query; my query returns
no values. (I am surprised this compiled since the SQL column is CHAR and I would expect use
of single quotes.)
I have tried preceding the variable with the '&', and the compile fails.
Can you advise?
In the second SQL query, goto the two occurrences of var_player_nme.
I've done an extensive search, and cannot find an example.
Thank you.
Here is my code:
- Code: Select all
create or replace procedure "PROC_TEST_CALC_3"
is
var_player_nme VARCHAR2(75);
pr_player_nme score.player_nme%TYPE;
pr_CALC_nbr score.tot_score%TYPE;
CALC NUMBER(2):= 0;
CURSOR get_player_crsr is
SELECT DISTINCT player_nme
FROM score
WHERE player_nme = 'Doe_John';
/* The above query is modified to produce one row for development */
CURSOR fig_player_CALC_crsr is
SELECT (ROUND(AVG(tot_score),0) - 72) as CALC
FROM (
SELECT *
from (SELECT player_nme, yr, rnd_nbr, tot_score
FROM (SELECT *
FROM ( SELECT player_nme, yr, rnd_nbr, tot_score
FROM score
WHERE player_nme = var_player_nme
and yr <= 2011
ORDER BY yr desc, rnd_nbr desc )
WHERE rownum <= 20 )
WHERE player_nme = var_player_nme
ORDER BY tot_score )
WHERE rownum <= 10
)
GROUP BY player_nme;
begin
OPEN get_player_crsr;
OPEN fig_player_CALC_crsr;
LOOP
DBMS_OUTPUT.PUT_LINE('Before Fetching Player Name');
FETCH get_player_crsr into pr_player_nme;
EXIT WHEN get_player_crsr%NOTFOUND;
var_player_nme := pr_player_nme;
DBMS_OUTPUT.PUT_LINE('Fetching Player Name');
DBMS_OUTPUT.PUT_LINE('DISPLAYING VAR_PLAYER_NME: ' || var_player_nme);
DBMS_OUTPUT.PUT_LINE('BeforeFetching Player CALC');
FETCH fig_player_CALC_crsr into pr_CALC_nbr;
DBMS_OUTPUT.PUT_LINE('PR_CALC_NBR: ' || pr_CALC_nbr);
DBMS_OUTPUT.PUT_LINE ('------------------');
DBMS_OUTPUT.PUT_LINE(pr_player_nme);
DBMS_OUTPUT.PUT_LINE(pr_CALC_nbr);
END LOOP;
end;
===The Submission Output======================
- Code: Select all
SQL> exec proc_test_hdcp_3
Before Fetching Player Name
Fetching Player Name
DISPLAYING VAR_PLAYER_NME: Doe_John
BeforeFetching Player CALC
PR_CALC_NBR:
------------------
Doe_John
Before Fetching Player Name
PL/SQL procedure successfully completed.