官术网_书友最值得收藏!


Creating a report with PL/SQL Dynamic Content>

APEX offers many item types and templates to use when designing an application. Sometimes this isn't enough, for example, when you have an existing web application built with mod PL/SQL that you want to reuse.

It's possible by using built-in packages such as HTP or HTF, or by using some native APEX code to create these types of pages directly in PL/SQL.

How to do it...

In this example, we are going to build a report without using any items, but only PL/SQL code.

On an empty page, create a new region:

  1. Choose a PL/SQL Dynamic Content region type.
  2. Name it Employees.

The PL/SQL Source is the most important part of this region. With this, we will be building up the report. To show how this works, we will first create the region without any layout.

Enter the following as the PL/SQL and click on Next, and then on Create Region:

declare
  cursor c_emp
      is
         select apex_item.hidden(1,emp.id) id
              , apex_item.display_and_save(2,emp.firstname) firstname
              , apex_item.display_and_save(2,emp.lastname) lastname
              , apex_item.display_and_save(2,emp.username) username
              , apex_item.display_and_save(2,dept.name) department
              , apex_item.display_and_save(2,job.abbreviation) job
              , apex_item.display_and_save(2,job.description) job_desc
           from app_employees emp
              , app_departments dept
              , app_jobs job
          where emp.dept_id = dept.id
            and emp.job_id  = job.id;
begin
  for r_emp in c_emp
  loop
    htp.p(r_emp.id);
    htp.p(r_emp.firstname);
    htp.p(r_emp.lastname);
    htp.p(r_emp.username);
    htp.p(r_emp.department);
    htp.p(r_emp.job);
    htp.p(r_emp.job_desc);
  end loop;
end;
[9672_01_20.txt]

When the page is run, all data from each employee is placed on one continuous line. To change this and make it look more like a report, we will add some HTML encoding, using the htp package.

Change the code inside the begin-end to the following:

  htp.tableopen;

  for r_emp in c_emp
  loop
      htp.tablerowopen;
        htp.tabledata(r_emp.id);
        htp.tabledata(r_emp.firstname);
        htp.tabledata(r_emp.lastname);
        htp.tabledata(r_emp.username);
        htp.tabledata(r_emp.department);
        htp.tabledata(r_emp.job);
        htp.tabledata(r_emp.job_desc);
      htp.tablerowclose;
  end loop;

  htp.tableclose;
[9672_01_21.txt]

This looks a lot better and gives us a starting point to apply a better layout:

Applying layout can now be done on multiple levels. For starters, the APEX_ITEM package can be used to select different item types in the cursor query. We have now used APEX_ITEM.DISPLAY_AND_SAVE to show the data as text only, but we could also use item type TEXT to make it a text field.

On a second level, we can start using classes from the CSS that is used by the application. These can be applied to the items, tables, tablerows, and so forth. How this can be done as explained in Chapter 2, Themes and Templates.

主站蜘蛛池模板: 成都市| 临海市| 新闻| 盐边县| 栖霞市| 巧家县| 靖西县| 咸阳市| 建昌县| 永吉县| 长岭县| 交口县| 西畴县| 阿城市| 台南市| 华安县| 会东县| 伊通| 西藏| 克东县| 普兰县| 阳城县| 七台河市| 宕昌县| 望都县| 稷山县| 旌德县| 菏泽市| 漳浦县| 都匀市| 镇康县| 宁都县| 金门县| 甘德县| 兴国县| 侯马市| 邻水| 衢州市| 罗城| 沛县| 汽车|