Create Form Layout using columns from different tables [message #131547] |
Mon, 08 August 2005 04:05 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi,
I'm newbie in Oracle.
I have 3 tables which have properties something like below:
Table A
item_a(Primary Key)
item_b
Table B
item_c(Primary Key)
item_d(Primary Key)
item_e
Table C
item_c(Primary Key)
item_a(Foreign Key)
item_f
I would like to have a layout that display all rows like the below query:
SELECT item_b, item_e, item_f
FROM Table A, Table B, Table C
WHERE Table A.item_a = Table C.item_a
AND Table B.item_c = Table C.item_c
Would be much appreciated if someone can provide me step by step on how to create the above layout.
Thanks!
|
|
|
Re: Create Form Layout using columns from different tables [message #131653 is a reply to message #131547] |
Mon, 08 August 2005 18:11 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
Which table is the controlling table? (Which has more fields in its primary key?) Which tables are the subordinate tables?
For me, table B with 2 items in the primary key, one of which is not used by another table is the 'pivot' (main / controlling) table.
You have a few choices (not in order)
- create a view and base your block on it,
- base your block on table B and use Post-Query to populate the table A and table C fields, then use pre- and post- insert, update, and delete triggers to maintain the other tables, or
- base your main block on table B, then create blocks on tables A and C, and create relationships on A for B and C.
I would suggest trying the last option first.
David
|
|
|
|
|
|
|
|
Re: Create Form Layout using columns from different tables [message #131675 is a reply to message #131671] |
Mon, 08 August 2005 22:15 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi David,
I would like the form to display item_e (from Table B) and item_b (from Table A)
I created Table B, A, and C accordingly together with their relationships respectively. In Table B data block, I added in item_c, item_e, and item_b(non-database). I created Post_query in Table B data block as follows:
DECLARE
CURSOR lookup_table IS
SELECT item_b
FROM Table_B
WHERE item_a = :Table_C.item_a
AND :Table_C.item_c = :Table_B.item_c;
BEGIN
OPEN lookup_table;
FETCH lookup_table
INTO :Table_B.item_b;
CLOSE lookup_table;
END;
Finally, I created the layout to display item_b and item_e.
When I executed the query, the item_e records were displayed whereas item_b didn't return any records; and I got this error: 'No navigable items in destination block'.
I'm not sure which part did I left out.
Thanks.
Regards,
Aaron
|
|
|
Re: Create Form Layout using columns from different tables [message #131677 is a reply to message #131675] |
Mon, 08 August 2005 22:29 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
Aaron,
My first suggestions were for an updateable form, for a display only form, as I said in my last post, you only need one block.
Delete the table_a and table_c blocks, and any relationships.Quote: | Table A
item_a(Primary Key)
item_b
Table B
item_c(Primary Key)
item_d(Primary Key)
item_e
Table C
item_c(Primary Key)
item_a(Foreign Key)
item_f
|
In your block on table_b create non-database fields for item_a, item_b, and item_f, and populate them in your Post-Query.DECLARE
CURSOR lookup_table IS
SELECT c.item_a,
a.item_b,
c.item_f
FROM Table_A a,
Table_C c
WHERE a.item_a = c.item_a
AND c.item_c = :Table_B.item_c;
BEGIN
OPEN lookup_table;
FETCH lookup_table
INTO :Table_B.item_a,
:Table_B.item_b,
:Table_B.item_f;
CLOSE lookup_table;
END; Hope this helps.
David
[Updated on: Mon, 08 August 2005 22:30] Report message to a moderator
|
|
|
|
Re: Create Form Layout using columns from different tables [message #131735 is a reply to message #131677] |
Tue, 09 August 2005 04:17 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi David,
I would like to add in a user parameter (item_z) to the form.
I add-in the bolded code to the previous POST-QUERY.
DECLARE
CURSOR lookup_table IS
SELECT c.item_a,
a.item_b,
c.item_f
FROM Table_A a,
Table_C c,
Table_B b
WHERE a.item_a = c.item_a
AND c.item_c = :Table_B.item_c
AND b.item_z = :Table_B.item_z;
BEGIN
OPEN lookup_table;
FETCH lookup_table
INTO :Table_B.item_a,
:Table_B.item_b,
:Table_B.item_f;
CLOSE lookup_table;
END;
However, when I executed the form, no record is displayed for item_b and item_f.
Your help is much appreciated.
Thanks.
Regards,
Aaron
|
|
|
|
|
Re: Create Form Layout using columns from different tables [message #131881 is a reply to message #131867] |
Tue, 09 August 2005 23:10 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi David,
I created Table_B.item_z (non-database) in Table B data block to serve as user input for query. In the Table B's properties, I inserted 'item_z = :GL06MAST.item_z' in the 'WHERE' section.
Is it the correct way?
Anothing thing is that if I want to query the items in Table B as well, do I need to put in the POST-QUERY select statement as well?
OR
I just created a database item in Table B data block?
Thanks...
Regards,
Aaron
[Updated on: Tue, 09 August 2005 23:17] Report message to a moderator
|
|
|
|
Re: Create Form Layout using columns from different tables [message #131904 is a reply to message #131888] |
Wed, 10 August 2005 00:32 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi David,
Thanks for the reply.
I would like to perform the following query:
Table A
item_a (PK)
item_b
Table B
item_c(PK)
item_d(PK)
item_e
Table C
item_c(PK)
item_a(FK)
item_f
SELECT item_b, item_e, item_f
FROM Table A, Table B, Table C
WHERE Table A.item_a = Table C.item_a
AND Table B.item_c = Table C.item_c
AND Table B.item_z = user input
in which, the user input item_z to make the query.
Thanks.
Regards,
Aaron
|
|
|
|
|
Re: Create Form Layout using columns from different tables [message #131929 is a reply to message #131922] |
Wed, 10 August 2005 02:04 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
You don't search for your main block fields in your Post-Query.
Date ranges need to be handled differently because they are not a straight search.
If item_z is your date then you need to 'massage' your date to match the structure of your search criteria.
Create a non-database field on your table_b block, let's call it z_year. We populate it in the Post-Query by, now, adding table_b to the cursor.DECLARE
CURSOR lookup_table IS
SELECT c.item_a,
a.item_b,
c.item_f,
to_char(c.item_z,'YYYY')
FROM Table_A a,
Table_C c,
Tabel_B b
WHERE a.item_a = c.item_a
AND c.item_c = c.item_c
AND b.item_c = :Table_B.item_c
AND b.item_d = :Table_B.item_d;
BEGIN
OPEN lookup_table;
FETCH lookup_table
INTO :Table_B.item_a,
:Table_B.item_b,
:Table_B.item_f,
:Table_B.z_year;
CLOSE lookup_table;
END; When you reference your base table in a Post-Query make sure that you fully utilize its primary key.
We then have to change the 'default_where' depending on whether we are searching by date range or not.
Pre-Query trigger
declare
stmnt varchar2 (200);
begin
if :Table_B.z_year is not null then
stmnt := 'to_date(item_z,''YYYY'') = :Table_B.z_year';
end if;
set_block_property ('Table_B', DEFAULT_WHERE, stmnt);
end;
Try that and see what happens.
David
[Updated on: Wed, 10 August 2005 02:05] Report message to a moderator
|
|
|
Re: Create Form Layout using columns from different tables [message #131964 is a reply to message #131929] |
Wed, 10 August 2005 03:17 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi David,
I tried the above method and created the PRE-QUERY, however, I received this message when I execute the form:
FRM-40735:POST-QUERY trigger raised unhandled exception ORA-01481.
I tried to change to_char to to_number, AND/OR change the z_year's data type to char/number but still receive the same message.
Thanks.
Regards,
Aaron
|
|
|
|
Re: Create Form Layout using columns from different tables [message #132115 is a reply to message #132103] |
Wed, 10 August 2005 19:49 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
David,
Post-Query:
DECLARE
CURSOR lookup_table IS
SELECT c.item_a,
a.item_b,
c.item_f,
to_char(b.item_z,'YYYY')
FROM Table_A a,
Table_C c,
Tabel_B b
WHERE a.item_a = c.item_a
AND c.item_c = c.item_c
AND b.item_d = :Table_B.item_d;
BEGIN
OPEN lookup_table;
FETCH lookup_table
INTO :Table_B.item_a,
:Table_B.item_b,
:Table_B.item_f,
:Table_B.z_year;
CLOSE lookup_table;
END;
Thanks.
Regards,
Aaron
|
|
|
|
|
Re: Create Form Layout using columns from different tables [message #132121 is a reply to message #132120] |
Wed, 10 August 2005 20:53 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
I made am incorrect assumption. I assumed the 'year' in item_z was a date type field. As item_z is a four digit number then you do not need to mention table_b in the Post-Query and you do not need the Pre-Query trigger. Just add item_z as a number to your block_b, define it on the canvas and the query will accept search values and then display it as part of the 'base' table on retrieval.
David
PS keep copies of your form before doing major deletions, just in case you want to go back and try a different approach
[Updated on: Wed, 10 August 2005 20:54] Report message to a moderator
|
|
|
|
Maintain user input's visibility [message #132615 is a reply to message #132121] |
Mon, 15 August 2005 04:13 |
aarontan78
Messages: 63 Registered: August 2005
|
Member |
|
|
Hi David,
I created a form which allowed user to enter input (eg. 2005) in a field to perform query.
I would like the user input (2005) to remain visible in the field after I execute query.
May I know how should I do that?
Thank you.
Regards,
Aaron
|
|
|