Sunteți pe pagina 1din 7

Forms: How to base a Data Block on a table join

If you are like most Oracle Forms developers, you will agree that there are four data sources for a Forms Data Block. They are: Table, View, Stored Procedure and From Clause Query. Sometimes, however, it would be nice if I didnt have to use a From Clause Query or create a database view just to build a block that performs a simple join on two tables. Well, this is actually possible and is extremely simple to accomplish. This document will demonstrate how to achieve this using the new HR demo schema and the EMPLOYEES and DEPARTMENTS tables. Disclaimer: This example is based on using Oracle Forms 10g R2 (10.1.2.0.2) but it should work with older versions as well. As you must explicitly identify each column in the block, data blocks that are based on a Join can be made to be updateable, but typically you would treat them the same as a block based on a From Clause Query. 1. Open Oracle Forms Builder and create a new form module. 2. Create a new Canvas and set the following Canvas Properties: 1. Name: EMP_DEPT 2. Canvas Type: Content 3. Window: WINDOW1 (created by default with a new Module) 4. Width: 540 5. Height: 325 3. Connect to the HR schema or as a user that has SELECT privileges to the HR schema. 4. Create a new data block object and select the Build a new data block manually option. 5. Set the following Block Properties: 1. NAME: EMP_DEPT_JOIN 2. Number of Records Displayed: 10 3. Query Data Source Name: hr.employees, hr.departments 4. WHERE Clause: employees.department_id = departments.department_id 5. Insert Allowed: Yes 6. Update Allowed: Yes 7. Delete Allowed: Yes

8. Locking Mode: Delayed 9. Key Mode: Updateable 10. DML Data Target Name: hr.employees, hr.departments 11. Show Scroll Bar: yes 12. Scroll Bar Canvas: EMP_DEPT 13. Scroll Bar X Position: 500 14. Scroll Bar Y Position: 42 15. Scroll Bar Width: 14 16. Scroll Bar Height: 140
Note: Key Mode = Updatable instructs Forms to perform any DML statements using the Primary Key values.

6. Add the following Block Items and set their properties as indicated: 1. Name: Employee_id i. Data Type: Number ii. Maximum Length: 6 iii. Column Name: hr.employees.employee_id iv. Primary Key: Yes v. Prompt: Employee ID vi. Prompt Attachment Edge: Top vii. Prompt Alignment: Center 2. Name: First_name i. Date Type: Char ii. Data Length Semantics: Byte iii. Maximum Length: 20 iv. Column Name: hr.employees.first_name v. Prompt: First Name vi. Prompt Attachment Edge: Top vii. Prompt Alignment: Center 3. Name: Last_name i. Data Type: Char ii. Data Length Semantics: Byte

4.

5.

6.

7.

iii. Maximum Length: 20 iv. Column Name: hr.employees.last_name v. Prompt: Last Name vi. Prompt Attachment Edge: Top vii. Prompt Alignment: Center Name: Job_id i. Data Type: Char ii. Data Length Semantics: Byte iii. Maximum Length: 20 iv. Column Name: hr.employees.job_id v. Prompt: Job ID vi. Prompt Attachment Edge: Top vii. Prompt Alignment: Center Name: Manager_id i. Data Type: Number ii. Maximum Length: 6 iii. Column Name: hr.employees.employee_id iv. Prompt: Manager ID v. Prompt Attachment Edge: Top vi. Prompt Alignment: Center Name: Salary i. Data Type: Number ii. Maximum Length: 11 iii. Column Name: hr.employees.salary iv. Prompt: Salary v. Prompt Attachment Edge: Top vi. Prompt Alignment: Center Name: Department_name i. Data Type: Char ii. Data Length Semantics: Byte iii. Maximum Length: 30

iv. Column Name: hr.departments.department_name v. Prompt Name: Department Name vi. Prompt Attachment Edge: Top vii. Prompt Alignment: Center 7. Add the items to a Canvas using the Layout Wizard. i. Select EMP_DEPT_JOIN as the data block ii. Select all available fields iii. Select Tabular layout iv. Enter Employee Information as the Frame Title v. Set number of record displayed = 10 vi. Check the Display Scrollbar option vii. Click Finish 8. At this point you should have a form that look similar to the following:

9. Now run your form and press Ctrl + F11 to query data into the EMP_DEPT_JOIN block. Your Forms Runtime should look like the following:

Youre done! You have successfully based a Forms Data Block on two tables by joining them through the WHERE Clause of the data block. How many tables you join in your block is up to you. I have successfully joined 6 tables. The advantage of joining tables

in your block is that the result set is faster than the traditional block based on the primary table and using a Post-Query trigger to display the relevant data from the joined tables.

S-ar putea să vă placă și