APEX 动态操作案例学习



1.      Oracle APEX 动态操作案例学习

参考:https://o7planning.org/en/10449/oracle-apex-dynamic-action-tutorial

1.1.        Introduction

This document is based on:

· Oracle APEX 5

1.2.        Preparing for example

1)      EMP表添加列BONUS

-- Add/modify columns

alter table EMP add BONUS number;

2)      创建空白页

       页码:300

       名称:Dynamic Action Example

       导航菜单:创建新的导航菜单,导航条目:Dynamic Action Example

3)      在刚创建的页中创建新区域Parameter Region

标识》标题:Parameter Region

标识》类型:静态值

4)      在区域Parameter Region创建页项

页项信息如下:

Identification:

· Name: P300_PARAM_EMPNO

· Type: Select List

List of Values:

· Type: SQL Query

· SQL Query: Select Ename, Empno From Emp

5)      右击content body创建区域Emp Form Region

区域信息如下:

Identification:

· Title: Emp Form Region

· Type: Static Content

6)      在区域Emp Form Region下建多个页项

Set the properties for Items:

No

Item

Label

Source
(Type= Database Column)

1

P300_EMPNO

Empno

EMPNO

2

P300_ENAME

Ename

ENAME

3

P300_JOB

Job

JOB

4

P300_MGR

Manager

MGR

5

P300_HIREDATE

Hiredate

HIREDATE

6

P300_SAL

Salary

SAL

7

P300_COMM

Commission

COMM

8

P300_BONUS

Bonus

BONUS

9

P300_DEPTNO

Deptno

DEPTNO

7)      创建处理过程

当web页面显示,数据需分配到页项,需要新建一个过程来处理数据显示。

在右侧导航栏中,选择“呈现”标签页》页面之后》右击创建处理

       信息如下:

Identification:

· Name: Fetch EMP Row

· Type: Automatic Row Fetch

Setting:

· Table Name: EMP

· Primary Key Column: EMPNO

· Primary Key Item: P300_EMPNO


8)      修改页项

The value of P300_EMPNO is pass from outside,  "Fetch  EMP RowProcess will query EMP table with EMPNO = :P300_EMPNO at a time before the page is renderred, and assign values to the other items.

When you run this page, it has no data, the causes are :P300_EMPNO null (no value passed to it from outside).

修改页项P300_JOB如下

Identification:

· Name: P300_JOB

· Type: Select List

List of Values:

· Type: Static Values

· Static values:STATIC:CLERK;CLERK,SALESMAN;SALESMAN,PRESIDENT;PRESIDENT,MANAGER;MANAGER,ANALYST;ANALYST

P300_MGR:

Identification

· Name: P300_MGR

· Type: Select List

List of Values

· Type: SQL Query

· SQL Query: Select ename d, empno r from emp where job in ('MANAGER', 'PRESIDENT')

P300_HIREDATE

Identification

· Name: P300_HIREDATE

· Type: Date Picker

P300_DEPTNO

Identification

· Name: P300_DEPTNO

· Type: Select List

List of Values

· Type: SQL Query

· SQL Query: Select Dname,Deptno From Dept

9)      保存并运行

1.3.        Dynamic Action example - Change

1)      创建动态操作

Create a Dynamic Action for P300 PARAM EMPNO item, when you change the value ofP300_PARAM_EMPNO, Dynamic Action will submit this page.

右击页项P300_PARAM_EMPNO创建动态操作,信息如下

Identification

· Name: Change EMPNO Param

When

· Even: Change

· Selection Type: Item(s)

设置动态操作的“真“,

标识》操作:提交页

2)      创建分支

在右侧导航栏中选择“处理“标签页,右击”提交之后“创建分支,作用是,但提交页之后重定向到特定页,本例重定向到本页。分支信息如下:

       标识》名称:Goto this page

       行为》类型:页或URL(重定向)

       行为》目标:目标》页:300,设置项》名称:P300_EMPNO,设置项》值:&P300_PARAM_EMPNO

3)       保存并运行

实现目标,选择员工后,将会将该员工信息显示出来。

4)      实现过程如下

(1)       在列表中选择员工

(2)       页项P300 PARAM EMPNO的动态操作判断到值变动,将提交页

(3)       分支Goto this page将重定向到指定页,并给页项P300_EMPNO赋&P300_PARAM_EMPNO值

(4)       处理Fetch EMP Row根据传入的值,搜索并展现信息;

The operating principle:

1.4.        Dynamic Action example - Enable/Disable

通过动态操作判断,符合条件时某些项可编辑,否则不可。

下列示例实现:当部门为SALESMAN,时,COMM项将可编辑,其他部门不可编辑。

1)      右击页项P300_JOB创建动态操作"Change JOB".

Identification

· Name: Change JOB

When

· Even: Change

· Select Type: Item(s)

· Item(s): P300_JOB

· Condition: equal to

· Value: SALESMAN

2)      动态操作真假设置:

When P300_JOB = 'SALESMAN':

真:

标识》操作:启用

受影响的元素》选择类型:项

受影响的元素》项:P300_COMM

Else, P300_JOB does not equal 'SALESMAN', clause in the 'FALSE' will be executed.

创建假操作:

标识》操作:禁用

受影响的元素》选择类型:项

受影响的元素》项:P300_COMM

3)      保存并执行

选择不同的JOB,COMM项将处于可编辑或不可编辑状态。

1.5.        Dynamic Action example - Set Values using SQL Statement

1)      在EMP FORM REGION下创建两个页项

Identification:

· Name: P300_LOCATION

· Type: Display Only

Label

· Label: Location

Settings:

· Save Sesion State: NO

Source

· Type: Null

Identification:

· Name: P300_NUM_EMPLOYEES

· Type: Display Only

Label

· Label: NUM_EMPLOYEES

Settings:

· Save Sesion State: NO

Source

· Type: Null

Note: P300_LOCATION and P300_NUM_EMPLOYEES are items not based on columns of a table, its value is calculated at the time of "Page Load" so you need to put "Save Session State = NO".

Create Dynamic Action for P300_DEPTNO when you change department of employee, Dynamic Action will recalculate the location and number of employees of the new department and assign values to the P300_LOCATION and P300_NUM_EMPLOYEES.

2)      右击页项P300_DEPTNO创建动态操作

标识》名称:CHANGE DEPTNO

动态操作真设置为:

Identification

· Action: Set Value

Settings

· Set type: SQL Statement

· SQL Statement:  .....

Select d.Loc Location ,Count(e.Empno) Num_Employees

From   Dept d ,Emp  e

Where  d.Deptno = e.Deptno(+)

And    d.Deptno = :P300_Deptno

Group  By d.Loc

· Page Items to Submit: P300_DEPTNO

Affected Elements

· Selection Type: Item(s)

· Item(s): P300_LOCATION, P300_NUM_EMPLOYEES

3)      保存并运行

选择不同的部门,将动态显示位置和员工人数。

1.6.        Dynamic Action example - Set Values using PL/SQL

In this example, simulating to calculate bonus for an employee, bonus is calculated by multiplying the salary to bonus coefficient of employees, when "page load", the value of BONUS will be calculated by the PL/SQL.

在本示例中,通过PL/SQL中设置不同的奖金系数,动态计算员工奖金。

1)      设置页项P300_BONUS

标识》类型:数字字段

       外观》格式编码:¥5,234.10

2)      创建动态操作

页编辑窗口》右侧导航栏中“动态操作“标签》事件》右击”加载页“创建动态操作

       标识》名称:Calculate BONUS

       时间》事件》加载页

3)      动态操作真设置

标识》操作:设置值

受影响的元素》选择类型:项

受影响的元素》项:P300_BOUNS

设置》设置类型:PL/SQL FUNCTION BODY

设置》PLSQL函数体:

Declare

   v_Multiplier Number;

Begin

   -- Determine multiplier based on job.

   Case :P300_Job

      When 'CLERK' Then

         v_Multiplier := 0.1;

      When 'ANALYST' Then

         v_Multiplier := 0.2;

      When 'SALESMAN' Then

         v_Multiplier := 0.3;

      When 'MANAGER' Then

         v_Multiplier := 0.4;

      When 'PRESIDENT' Then

         v_Multiplier := 0.5;

      Else

         v_Multiplier := 0;

   End Case;

   -- Return bonus which is calculated by

   -- Multiplying Salary My Multiplier

   Return :P300_Sal * v_Multiplier;

End;

4)      保存并运行

刷新页面后切换不同job,将看到bonus有变化。

1.7.        Dynamic Action example - Button

本示例中,对保存按钮创建动态操作,如点击将保存所作修改。

1)      添加按钮

在Sub Regions区域的CHANGE处,添加一个类型为Text的按钮。

Identification:

· Button Name: APPLY_CHANGE

· Type: Apply change

Behavior:

· Action: Submit Page

· Database Action: SQL UPDATE action

2)      创建用于更新的处理

在右侧导航栏的“处理“标签页中,右击”处理“创建”处理“

Identification:

· Name: Process ROW of EMP

· Type: Automatic ROW Processing (DML)

Settings

· Table Name: EMP

· Primary Key Column: EMPNO

· Primary Key Item: P300_EMPNO

· Supported Operation: Update

3)      保存并运行










来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29519108/viewspace-2156541/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29519108/viewspace-2156541/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值