Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Oracle APEX Cookbook : Second Edition

You're reading from   Oracle APEX Cookbook : Second Edition Get straight into developing modern web applications, including mobile, using the recipes in this brilliant cookbook for Oracle Application Express (APEX). From the basics to more advanced features, it's a reference book and guide in one.

Arrow left icon
Product type Paperback
Published in Oct 2013
Publisher
ISBN-13 9781782179672
Length 444 pages
Edition Edition
Languages
Arrow right icon
Toc

Table of Contents (21) Chapters Close

Oracle APEX Cookbook Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Creating a Basic APEX Application 2. Themes and Templates FREE CHAPTER 3. Extending APEX 4. Creating Websheet Applications 5. APEX Plug-ins 6. Creating Multilingual APEX Applications 7. APEX APIs 8. Using Web Services 9. Publishing from APEX 10. APEX Environment 11. APEX Administration 12. Team Development 13. HTML5 and CSS3 14. Mobile Index

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.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image