Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keep getting error Component must me declared?

Status
Not open for further replies.

vb89

MIS
Aug 21, 2008
47
US
im working in pl/sql and I keep getting the error componet 'first' must be declared, and i have no idea why...

here is my code for my cursor and proc
Code:
cursor cGetTeamStats is
   select *
   from varsity.soccer_period_results
   where game_code = p_GameCode;

type team_stats_1d is table of cGetTeamStats%rowtype index by varsity.soccer_period_results.team_id%type;
type team_stats_2d is table of team_stats_1d index by pls_integer;
aTeamStats team_stats_1d;
xTeamStats team_stats_2d;

Code:
procedure pWriteTeamStats(tTeamID in varchar2, tTeamType in varchar2, iIndent in number) as
   iCurrStatType number;
   tCurrTeamID varsity.soccer_period_results.team_id%type;
begin
    utl_file.put_line(file_handle, sp(iIndent) || '<' || tTeamType || '-team-stats>');
   
    iCurrStatType := xTeamStats(tTeamID).first;
    loop
        exit when iCurrStatType is null;
   
   
        tCurrTeamID := xTeamStats(tTeamID)(iCurrStatType).first;
        loop
           exit when tCurrTeamID is null;
      
           utl_file.put(file_handle, sp(iIndent + 2) || '<' || aStatTypes(iCurrStatType) || ' ');
   
   
           case iCurrStatType
                when 2 then -- goal
                     utl_file.put_line(file_handle, 'goals="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).goals ||  '">');
                when 4 then -- shots
                     utl_file.put_line(file_handle, 'shots="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).shots || '">');
                when 5 then -- shots on goal
                     utl_file.put_line(file_handle, 'shots on goal="' || xTeamStats (tTeamID)(iCurrStatType)(tCurrTeamID).shots_on_goal || '">');
                when 9 then -- saves
                     utl_file.put_line(file_handle, 'saves="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).saves || '">');
                when 10 then -- fouls committed
                     utl_file.put_line(file_handle, 'fouls committed="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).fouls_committed || '">');
                when 11 then -- corner kicks
                     utl_file.put_line(file_handle, 'corner kicks="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).corner_kicks || '">');
                when 12 then -- yellow cards
                     utl_file.put_line(file_handle, 'yellow cards="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).yellow_cards || '">');
                when 13 then -- red cards
                     utl_file.put_line(file_handle, 'red cards="' || xTeamStats(tTeamID)(iCurrStatType)(tCurrTeamID).red_cards || '">');
           end case;
   
             tCurrTeamID := xTeamStats(tTeamID)(iCurrStatType).next(tCurrTeamID);
          end loop;
      
      iCurrStatType := xTeamStats(tTeamID).next(iCurrStatType);
   end loop;
   
   utl_file.put_line(file_handle, sp(iIndent) || '</' || tTeamType || '-team-stats>');


end pWriteTeamStats;
 
VB,

I must say, I agree with the PL/SQL interpretter. I cannot see where you have defined what "first" is. In the immortal words of Inigo Montoya (in "The Princess Bride"):
Inigo Montoya said:
I don't think it means what you think it means.
Please tell us what "first" should mean.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm. The cost will be your freedoms and your liberty.”
 
You are making your homework assignment a bit more complicated than it needs to be and confusing nested tables with associative arrays. An associative array (or PL/SQL table) is indexed by a numeric column but you seem to be trying to locate an element using a varchar2 column.

"xTeamStats(tTeamID)" means "find me the tTeamID element on xTeamStats", but since tTeamID is a varchar2 and xTeamStats is indexed by an integer, this is meaningless. Putting a ".first" on the end is simply wrong and not surprisingly the compiler objects to it.

You can do away with team_stats_2d altogether and simply go in on team_stats_1d using:

xTeamStats team_stats_1d;
..
tCurrTeamID := xTeamStats(tTeamID).StatType;
..

 
Got the wrong line there:

iCurrStatType := xTeamStats(tTeamID).StatType;

or whatever the column is called.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top