Pablo
Pablo

Reputation: 29519

How to retrieve and use row(s) from database in HTML page?

In my APEX application, I would like to use rows from query as variables, but I don't want to create items for each element. Those variables I will have to show in my custom HTML page.

For example this is query:

SELECT cells.id as id, cells.name as name, storage.capacity as capacity from cells, storage WHERE storage.capacity > 120

Then in my custom HTML code I would like to reference those rows, something like this(sorry I don't know the syntax of variables):

<div>#name[1]#</div><a href="p?#id[1]"...
<div>#name[2]#</div><a href="p?#id[2]"...

So how can I do it for single fetched row and for multiple rows? Which type of process and region to engage?

Upvotes: 0

Views: 1137

Answers (1)

Dmitriy
Dmitriy

Reputation: 5565

If you don't want to create items for each element MANUALLY, you can use region of type Form on table or view. APEX creates them automatically. If you don't want to create items automatically, you can create region of type HTML, then go to Region Definition -> Identification, select Type - PL/SQL (anonymous block), Source - type your PL/SQL code there. Example:

declare
  ...
begin
  for i in (select text_col, rownum from mytable) loop
    htp.p(apex_item.text(rownum, text_col) || '<br>');
  end loop;
end;

You can pass to procedure htp.p any string variables. If they contain valid HTML, it will be displayed properly, otherwise you will see your HTML source code. Also you can use apex_item (http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_item.htm#AEAPI192) package to generate HTML code of required items.

Upvotes: 1

Related Questions