Skip to main content
Inspiring
November 25, 2008
Question

How do you process this..

  • November 25, 2008
  • 1 reply
  • 390 views
I'm not sure how you loop through this structure.

Oracle SQL (create the types within an SQL window)

create type studentMatch as object (federalIdNumber varchar2(9),
studentNumber varchar2(11),
lastName varchar2(30),
firstName varchar2(30),
middleName varchar2(30),
birthDate date,
gender varchar2(1));

create type studentMatchType as table of studentMatch;

create type studentMatchObject as object (students studentMatchType);

Query:

select studentMatchObject(cast(multiset((select federal_id_number,
student_number,
last_name,
first_name,
middle_name,
birth_date,
gender
from student_info b
where b.federal_id_number = a.federal_id_number))
as studentMatchType)),
b.federal_id_number,
b.last_name
from students

That query is wrapped within a <cfquery name="studentLoop"> statement.

So, how do I loop through the studentMatchType object? Would it be something like:

<cfloop query="studentLoop">
#studentMatchType.federal_id_number# (is that how you do it?)
#studentMatchType.last_name#
</cfloop>

    This topic has been closed for replies.

    1 reply

    Inspiring
    November 25, 2008
    Use cfoutput instead of cfloop.
    NettlesDAuthor
    Inspiring
    November 26, 2008
    quote:

    Originally posted by: Dan Bracuk
    Use cfoutput instead of cfloop.


    Why cfoutput?

    So the syntax is correct for an SQL collection (#studentMatchType.genderr#)?

    November 26, 2008
    quote:

    Originally posted by: NettlesD
    quote:

    Originally posted by: Dan Bracuk
    Use cfoutput instead of cfloop.


    Why cfoutput?

    So the syntax is correct for an SQL collection (#studentMatchType.genderr#)?




    You only really use CFLOOP when you need to loop something but not output it to the page. CFOUTPUT can be used like a CFLOOP, but. at the same time, it handles the output of your variables to the page.

    You could either do:

    <cfoutput>
    <cfloop query="something">
    #i#
    </cfloop>
    </cfoutput>

    OR if what you're looping is a query, you could roll it all into one tag in CFOUTPUT like this:

    <cfoutput query="something">
    #i#
    </cfoutput>

    You can do it both ways, but the second is prefered by most people. But whatever you do, avoid doing this:

    <cfloop query="something">
    <cfoutput>
    #i#
    </cfoutput>
    </cfloop>

    Doing this not only loops your query, but also the cfoutput tag itself. It will work, but I'm pretty sure it has an unnecessary performance hit.

    Mikey.