Oracle APEX 使用htp包动态生成HTML源码

Using APEX it’s very easy to display information using forms and reports regions, you could even throw in a chart or dial for a bit of something different. However, it’s also simple to generate HTML pages from PL/SQL code. This opens up a world of choice when it comes to designing and developing your application.

This tutorial is a simple demonstration of creating HTML output from PL/SQL code. It assumes that you have completed the APEX_ITEM Tutorial as it relies on the checkbox and ticked column that you create within this tutorial.

In the APEX_ITEM Tutorial we add a new column to the EMP table called ticked and then added a checkbox to a report to update this column when the checkbox was checked. Now we’ll add a new region to the same page which outputs the employee details, showing those that have been ticked in bold.

In the Application Builder:

  1. Navigate to the page that you previously used for the APEX_ITEM Tutorial. On this page add a new HTML region. In the wizard accept the default options, except set the name to “PL/SQL Output” and the column to 2, then click the Create Region button.
  2. Now edit the region that you’ve just created.
  3. Set the Type to be “PL/SQL (anonymous block)”
  4. Set the Region Source to :
    DECLARE
     CURSOR c_emp IS
     SELECT empno, ename, ticked
     FROM  emp;
    BEGIN
     FOR a IN c_emp LOOP
      IF a.ticked = 'Y' THEN
        htp.p('<b>Employee '||a.ename||' ('||a.empno||') has been ticked.
    </b><br/>');
      ELSE
        htp.p('Employee '||a.ename||' ('||a.empno||') has NOT been ticked.
    <br/>');
      END IF;
     END LOOP;
    END;


  5. Run the page.

Running the page should display a list of all the employees in the table. Those that have been ticked will be displayed in bold and those that haven’t will be normal. The HTML that is generated on the page is controlled by the htp.p call. There are numerous tags that can be used with the htp function, these are explained in detail in the Oracle documentation. I have used htp.p which just generates the HTML without any surrounding tags. I find that this gives me the most flexibility, especially if I need to come back and make changes.

In this example the PL/SQL generated region is ultimately redundant. It’s not giving us any more information than the reports region next to it. However, this is the easiest example I could think of. PL/SQL generated regions are much more powerful. For example, it can be used to generate a summary page pulling on information from different tables and using functions or calculations in PL/SQL. Or to generate a report style page to replace Oracle Reports style output. I’m sure you’ll agree the possibilities are endless.

转载自:

【1】Dynamic HTML Generated From PL/SQL Tutorial

http://www.apex-blog.com/oracle-apex/dynamic-html-generated-from-plsql-tutorial-31.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值