While inside the cursor tag, variables are preceded by a colon (Example:
":variable"). While outside the tag, variables are preceded by an (&) and
followed by a (;) (Example: "&variable;").
Try These Demo Examples
Below are some examples of forms that send data to SQmlTM files. Each form
contains a link to a copy of the SQmlTM file that processes the information. I
recommend viewing the SQmlTM source both before you submit and after you have
seen the output. The SQmlTM material is in red and the comments explaining the SQmlTM code are in grey. In some of the examples I have numbered the cursors for clarity. These numbers are not in the actual script. You should also helpful to view the source for the HTML form by clicking the top of your browser: first on View, then on Document Source.
Practice 1: In this example, the value
that names a product line is passed from an HTML form to an SQmlTM file. The value passed is inserted into a SQmlTM iterative cursor (<sql.iter>).
Specifically, the value is inserted into the cursor's where clause so the
value may be used to narrow the database query. The data retrieved will
represent only the product line that was chosen in the HTML form. The data retrieved is
assigned to variables in the into statement. After the values have been
assigned to variables, they are used in the document.
The <sql.iter> cursor acts like cursors in most languages. It releases
the information retrieved by the select statement one row at a time. Each row
retrieved is used to fill in the document's variable values. The cursor loops
until it is empty.
Practice 2: In this example, three values
are passed from an HTML form. We still use the value which names a product
line. The two new values represent the low number and high number in a price
range. They are all used in the where clause to narrow the search.
Practice 3: This example uses four
variables sent from an HTML form. They are the same three that were used before
plus the value which describes a color. They are also inserted into the where
clause. This example also shows how to get around the problem of null values by
using a SQL*PLUS function. This problem occurs when a variable is not assigned
a value. For instance, someone might leave a text field blank.
Practice 4: This example is very similar
to Practice 3. In fact, The HTML form is exactly the same. The difference
is in the SQmlTM file that processes the information sent by the form. When you
look at the SQmlTM source code, you will see two cursors. The first one is the
same as it was in the last example. The second one contains a variable in its
where clause. This variable was created in the first cursor's into
statement. The information retrieved in the first cursor is used in the second
cursor, the nested cursor. In this case, we used the value retrieved for the
product's number.
The second cursor will then retrieve information pertaining to one specific
product. The second cursor selects from a different table than the first cursor.
It will loop until all its rows have been used. Once the second cursor
is finished, the first cursor releases another row for processing. This pattern
will continue until the first cursor empties.
Note the placement of the second cursor and its end tag (</sql.iter>).
See how this placement allows the table to become either as large or as small
as it needs to be?
Customer Catalog Search: This example
expands on the previous examples. The HTML form allows customers to search for
products according to several different criteria. The SQmlTM file the information
is sent to contains four cursors. Each cursor selects from a different table.
The first and second cursors use values passed from the form in their where
clauses. The third and fourth cursors use the product number retrieved
by the first cursor.
Distributor Catalog Search: This
example is a lot like the Customer Catalog Search. The HTML form is a little
different though. It uses check boxes. In the form we are giving the user the
option to choose one or more product lines and one or more status. This data
must be handled a little differently than other data we have seen used in the
cursor. When you look at the SQmlTM source, notice how the parentheses are placed
in the where clause.