Many to many join
Hello,
Please help me create the many-to-many relationship between these tables that I willl need to do a Master Detail form. The master is tblStandardSheets (PK: ID) the detail is tblSubject (PK: SUBJECTID) and the link is tblLink (PK: RECID, FK: ID, SUBJECTID).
CREATE TABLE "tblStandardSheets"
( "ID" NUMBER NOT NULL ENABLE,
"SHEET" VARCHAR2(100),
"TITLE" VARCHAR2(255),
CONSTRAINT "tblStandardSheets_PK" PRIMARY KEY ("ID") ENABLE
CREATE OR REPLACE TRIGGER "BI_tblStandardSheets"
before insert on "tblStandardSheets"
for each row
begin
if :NEW."ID" is null then
select "TBLSTANDARDSHEETS_SEQ".nextval into :NEW."ID" from dual;
end if;
end;
ALTER TRIGGER "BI_tblStandardSheets" ENABLE
CREATE TABLE "tblLink"
( "ID" NUMBER NOT NULL ENABLE,
"RECID" NUMBER NOT NULL ENABLE,
"SUBJECTID" NUMBER NOT NULL ENABLE,
CONSTRAINT "tblLink_PK" PRIMARY KEY ("RECID") ENABLE
ALTER TABLE "tblLink" ADD CONSTRAINT "TBLLINK_FK" FOREIGN KEY ("ID")
REFERENCES "tblStandardSheets" ("ID") ON DELETE CASCADE ENABLE
ALTER TABLE "tblLink" ADD CONSTRAINT "TBLLINK_FK2" FOREIGN KEY ("SUBJECTID")
REFERENCES "tblSubject" ("SUBJECTID") ON DELETE CASCADE ENABLE
CREATE OR REPLACE TRIGGER "BI_tblLink"
before insert on "tblLink"
for each row
begin
if :NEW."RECID" is null then
select "TBLLINK_SEQ".nextval into :NEW."RECID" from dual;
end if;
end;
ALTER TRIGGER "BI_tblLink" ENABLE
CREATE TABLE "tblSubject"
( "SUBJECTID" NUMBER NOT NULL ENABLE,
"SUBJECT" VARCHAR2(255),
CONSTRAINT "tblSubject_PK" PRIMARY KEY ("SUBJECTID") ENABLE
CREATE OR REPLACE TRIGGER "BI_tblSubject"
before insert on "tblSubject"
for each row
begin
if :NEW."SUBJECTID" is null then
select "TBLSUBJECT_SEQ".nextval into :NEW."SUBJECTID" from dual;
end if;
end;
ALTER TRIGGER "BI_tblSubject" ENABLE
ALTER TABLE "tblSubject" ADD CONSTRAINT "tblSubject_FK" FOREIGN KEY ("SUBJECTID")
REFERENCES "tblLink" ("SUBJECTID") ON DELETE CASCADE ENABLE
ORA-02270: no matching unique or primary key for this column-list
Edited by: user6753348 on Mar 31, 2009 1:39 PM
Like this:
CREATE TABLE "tblStandardSheets"
( "ID" NUMBER NOT NULL ENABLE,
"SHEET" VARCHAR2(100 BYTE),
"TITLE" VARCHAR2(255 BYTE),
CONSTRAINT "tblStandardSheets_PK" PRIMARY KEY ("ID")
CREATE OR REPLACE TRIGGER "BI_tblStandardSheets"
before insert on "tblStandardSheets"
for each row
begin
if :NEW."ID" is null then
select "TBLSTANDARDSHEETS_SEQ".nextval into :NEW."ID" from dual;
end if;
end;
ALTER TRIGGER "BI_tblStandardSheets" ENABLE
CREATE TABLE "tblSubject"
( "SUBJECTID" NUMBER NOT NULL ENABLE,
"SUBJECT" VARCHAR2(255 BYTE),
CONSTRAINT "tblSubject_PK" PRIMARY KEY ("SUBJECTID")
CREATE OR REPLACE TRIGGER "BI_tblSubject"
before insert on "tblSubject"
for each row
begin
if :NEW."SUBJECTID" is null then
select "TBLSUBJECT_SEQ".nextval into :NEW."SUBJECTID" from dual;
end if;
end;
ALTER TRIGGER "BI_tblSubject" ENABLE
CREATE TABLE "HR"."tblLink"
( "ID" NUMBER NOT NULL ENABLE,
"RECID" NUMBER NOT NULL ENABLE,
"SUBJECTID" NUMBER NOT NULL ENABLE,
CONSTRAINT "tblLink_PK" PRIMARY KEY ("RECID")
CONSTRAINT "TBLLINK_FK" FOREIGN KEY ("ID")
REFERENCES "tblStandardSheets" ("ID") ON DELETE CASCADE ENABLE,
CONSTRAINT "TBLLINK_FK2" FOREIGN KEY ("SUBJECTID")
REFERENCES "tblSubject" ("SUBJECTID") ON DELETE CASCADE ENABLE
CREATE OR REPLACE TRIGGER "BI_tblLink"
before insert on "tblLink"
for each row
begin
if :NEW."RECID" is null then
select "TBLLINK_SEQ".nextval into :NEW."RECID" from dual;
end if;
end;
ALTER TRIGGER "BI_tblLink" ENABLE
/You have to create the sequences yourself...
HTH
Roel
Similar Messages
-
How just return one row of a one to many join..
So I have a one to many join where the SMOPERATOR table has data I need however it has a couple of rows that match the JOIN condition in there. I just need to return one row. I think this can be accomplished with a subquery in the join however have not been able to come up with the right syntax to do so.
So:
SELECT "NUMBER" as danumber,
NAME,
SMINCREQ.ASSIGNMENT,
SMOPERATOR.PRIMARY_ASSIGNMENT_GROUP,
SMOPERATOR.WDMANAGERNAME,
SMINCREQ.owner_manager_name,
SMINCREQ.subcategory, TO_DATE('01-'||TO_CHAR(open_time,'MM-YYYY'),'DD-MM-YYYY')MONTHSORT,
(CASE WHEN bc_request='f' THEN 'IAIO'
WHEN (bc_request='t' and substr(assignment,1,3)<>'MTS') THEN 'RARO'
WHEN (bc_request='t' and substr(assignment,1,3)='MTS') THEN 'M'
ELSE 'U' end) as type
from SMINCREQ
left outer join SMOPERATOR on SMINCREQ.assignment=SMOPERATOR.primary_assignment_group
WHERE SMINCREQ.owner_manager_name=:P170_SELECTION and SMOPERATOR.wdmanagername=:P170_SELECTION
AND open_time BETWEEN to_date(:P170_SDATEB,'DD-MON-YYYY') AND to_date(:P170_EDATEB,'DD-MON-YYYY')
AND
(bc_request='f' and subcategory='ACTIVATION' and related_record<>'t')
OR
(bc_request='f' and subcategory<>'ACTIVATION')
OR
(bc_request='t' and substr(assignment,1,3)<>'MTS')
order by OPEN_TIMeHi,
This sounds like a Top-N Query , where you pick N items (N=1 in this case) off the top of an orderded list. I think you want a separate ordered list for each assignment; the analytic ROW_NUMBER function does that easily.
Since you didn't post CREATE TABLE and INSERT statements for your sample data, I'll use tables from the scott schema to show how this is done.
Say you have a query like this:
SELECT d.dname
, e.empno, e.ename, e.job, e.sal
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
ORDER BY dname
;which produces this output:
DNAME EMPNO ENAME JOB SAL
ACCOUNTING 7934 MILLER CLERK 1300
ACCOUNTING 7839 KING PRESIDENT 5000
ACCOUNTING 7782 CLARK MANAGER 2450
RESEARCH 7876 ADAMS CLERK 1100
RESEARCH 7902 FORD ANALYST 3000
RESEARCH 7566 JONES MANAGER 2975
RESEARCH 7369 SMITH CLERK 800
RESEARCH 7788 SCOTT ANALYST 3000
SALES 7521 WARD SALESMAN 1250
SALES 7844 TURNER SALESMAN 1500
SALES 7499 ALLEN SALESMAN 1600
SALES 7900 JAMES CLERK 950
SALES 7698 BLAKE MANAGER 2850
SALES 7654 MARTIN SALESMAN 1250Now say you want to change the query so that it only returns one row per department, like this:
DNAME EMPNO ENAME JOB SAL
ACCOUNTING 7782 CLARK MANAGER 2450
RESEARCH 7876 ADAMS CLERK 1100
SALES 7499 ALLEN SALESMAN 1600where the empno, ename, job and sal columns on each row of output are all taken from the same row of scott.emp, though it doesn't really matter which row that is.
One way to do it is to use the analytic ROW_NUMBER function to assign a sequence of unique numbers (1, 2, 3, ...) to all the rows in each department. Since each sequence startw with 1, and the numbers are unique within a department, there will be exactly one row per departement that was assigned the numebr 1, and we''ll display that row.
Here's how to code that:
WITH got_r_num AS
SELECT d.dname
, e.empno, e.ename, e.job, e.sal
, ROW_NUMBER () OVER ( PARTITION BY d.dname
ORDER BY e.ename
) AS r_num
FROM scott.dept d
JOIN scott.emp e ON d.deptno = e.deptno
SELECT dname
, empno, ename, job, sal
FROM got_r_num
WHERE r_num = 1
ORDER BY dname
;Notice that he sub-query got_r_num is almost the same as the original query; only it has one additional column, r_num, in the SELECT clause, and the sub-qeury does not have an ORDER BY clause. (Sub-queries almost never have an ORDER BY clause.)
The ROW_NUMBER function must have an ORDER BY clause. In this example, I used "ORDER BY ename", meaning that, within each department, the row with the first ename (in sort order) will get r_num=1. You can use any column, or expression, or expressions in the ORDER BY clause. You muight as well use something consistent and predictable, like ename, but if you really wanted arbitrary numbering you could use a constant in the analytic ORDER BY clause, e.g. "ORDER BY NULL". -
Hello,
I__m wondering if there is a way to limit a many to many join by a specific
value in a column in the join table. I have a join table that has the two
foreign key fields which are the ids to the tables and another column that
I want to limit on. So the SQL would be something like below but I want
to do it through ejb3. Any idea how this can be accomplished?
Select phone.number, __ from company, company_phone, phone where
company_phone.primay = __Y__ and company.id = company_phone.company_id and
phone.id = company_phone.phone_id and company.id = __1234__;
If so does it work for the other relationships (one to many and many to
one)?
Thanks,
CraigKodo does have support for limiting a join based on a constant value; we
call them "constant joins". See the following documentation, and let us
know if you have any questions:
http://solarmetric.com/Software/Documentation/4.0.0EA/docs/full/html/ref_guide_mapping_notes_nonstdjoins.html -
Flatten a Key Value Pair...how many joins are too many?
Hello,
So, a product can have many attributes...things that describe the product. In our 3rd party ERP, these are stored in a key-value manner.
product_code
attribute_code
attribute_value
etc.
Now, for some products there are 150+ attributes....you can pretty much guess where this is going...
User wants a report that shows an product_code and it's attributes on a single line (in separate columns) for Excel manipulation(s).
So, the SQL would require joining the same attribute table as many times as there are distinct attribute_codes for a given product_code.
If there are 150 named/distinct attributes that need to be lined up, this would mean 150 joins on that one table.
OR write scalars for each attribute
OR write a function that fetches the attribute_value when you pass the product_code and attribute_code and call this function 150 times in the SQL select list.
Yes, I know, I should benchmark each approach and select the one that works best....BUT, I would like to poll the wisdom of outstanding individuals on this group to see which of the 3 approaches would be preferred.
Oh and the users typically "query" hundreds to thousands of products and want this result set.
We are still on the terminally supported Oracle 10g database on Linux.
Thanks,
ManishMarc mentioned it already
with
eav as
(select 1 + mod(level,trunc(dbms_random.value(5,20))) product_code,
trunc(dbms_random.value(1,500)) attribute_code,
dbms_random.string('u',dbms_random.value(1,10)) attribute_value
from dual
connect by level <= 50
select csv
from (select product_code,
'name' att_type,
product_code||',attribute codes,'||listagg(to_char(attribute_code),',') within group (order by attribute_code) csv
from eav
group by product_code
union all
select product_code,
'value' att_type,
product_code||',attribute values,'||listagg(to_char(attribute_value),',') within group (order by attribute_code)
from eav
group by product_code
order by product_code,att_type
CSV
1,attribute codes,13,299,476
1,attribute values,LOCO,FKEKQ,UQHBYITKZ
2,attribute codes,66,72,121,126,198,307,346
2,attribute values,DJBBK,FVBYYBPQ,LCHQ,BCFYN,ZP,UYWDSGFEJ,CZ
3,attribute codes,32,101,213,352,369,449,499
3,attribute values,XKYBDRKPY,RZBU,RWQN,FVCQKWL,N,HCYTLHN,HCHXQLSU
4,attribute codes,116,210,244,307
4,attribute values,FKCMZCIJ,BAWZV,RCTDQLRE,CF
5,attribute codes,89,144,283,293,389
5,attribute values,YK,CEEAEFX,JEEZLJ,XESPFSWN,TRNYF
6,attribute codes,183,435,449
6,attribute values,CZYGEDPH,QEN,HO
7,attribute codes,282,333,358,373
7,attribute values,GRIY,ZCS,FGFQKEPQ,VITJKBNU
8,attribute codes,180,195,374
8,attribute values,UJPNIOGYS,GNWXLMB,XSFHO
9,attribute codes,30,103,216,485
9,attribute values,FJB,VXQHBYIX,RNZGRDBK,I
10,attribute codes,234
10,attribute values,VKCDNJ
11,attribute codes,27
11,attribute values,QDQHQHGD
12,attribute codes,51,101,223,333
12,attribute values,UMJXWTRLCI,XHSPFNFAX,FNFDEBGAYI,INBNTICY
13,attribute codes,298
13,attribute values,RQOS
14,attribute codes,270,480
14,attribute values,TMWSSNZNXT,PRLODAMEJ
16,attribute codes,297
16,attribute values,CITFASX
Regards
Etbin -
Messy One to Many Joins and Grouping
I manage websites for a large state agency in Texas. I have a
need to redo
queries that list the Local intake numbers for Long term
support services
(LTSS), Area Agencies on Aging (AAA), and Mental Retardation
Authorities
(MRA) by county for each of the state's 254 counties -- in
the past there
was only one intake number per county for each AAA and MRA,
with there being
the possibility for multiple LTSS intake numbers. Now there
are counties
that have multiple numbers for MRA intake.
Basic Structure of Database Tables:
CountyCenter Table
County (text)
CountyNumber (integer)
AAA_ID (integer)
MRA_ID (integer)
LTSS Table
County (text)
CountyNumber (integer)
City (text) -- optional used when there are multiple offices
for a county
IntakeNumber (text)
Region (text)
AAA Table
AAA_ID (integer)
AAAName (text)
AAAPhone (text)
MRA Table
MRA_ID (integer)
MRAName (text)
MRAPhone
MRAOffices
MRA_ID (integer)
IntakePhone (text)
City (Text)
CountyNumber (integer)
My goal is for each county to list in a combined table:
Column 1 = County Name
Column 2 = LTSS Office (Number(s))
Column 3 = MRA Intake Number
Column 4 = AAA Intake Number(s)/City if not main
Do I need a separate table for county that simply has the
CountyNumber and
CountyName to use as a control table?
I'd like to do this as efficiently as possible -- thankfully
the query won't
be accessed by the general public and will be run only when
updated
information is received. Any suggestions as to order of the
joins and
groupings in CFOUTPUT? (what I have now creates a lot of
duplication)
Thanks in advance for your help,
Michael Brown
Webmaster, Texas Department of Aging and Disability ServicesPhil,
Thanks for taking a look. You're definitely right. The data
structures are a mess. What was originally intended to be on
three
separate pages has been requested to be "available at a
glance."
With both the LTSS Offices and MRAs having the possiblity of
multiple offices for a given county what would be the best
way to
normalize the data? The tables for MRA, AAA, and LTSS have
CountyNumber (county exists only in those tables to provide
context for those who update the information manually (not my
choice/decision)).
So to break it down 254 Counties, each can have one or
multiple
LTSS numbers (and the number's city), only one AAA number,
and one
MRA with the possiblity for multiple intake numbers (and note
containing location information).
Hopefully, there is a graceful way of getting the output the
way
it has been requested. I'm open to suggestions.
Thanks again,
Michael
"paross1" <[email protected]> wrote in
news:[email protected]:
> After taking a quick glance, it looks like you already
have
> normalization issues with your data model, since LTSS
Table and
> CountyCenter Table both contain County (text), and
MRAOffices
and LTSS
> Table both have City (text), etc. It is hard to tell
which
fields are
> primary keys and which are foreign keys to which tables.
Some of
these
> that may have a one-to-many relationship that now
changes to a
> many-to-many will require a link table (associative
entity) and
the
> foreign keys migrated to them.
>
> You need to resist creating actual "combined tables",
spreadsheet
> style, and
> instead normalize your database, so that you can create
your
"combined
> table" virtually using SQL. It is hard to offer
specifics, since
I
> would need more information to do so, but the bottom
line is
that you
> do have some obvious data model issues that need to be
resolved
before
> you can get much further. Otherwise, you are going to
have to
write
> some very kludgey SQL to solve your problem with your
current
model.
>
> Phil
>
> -
Many to many join table with different column names
Hi have a joint table with different column names as foreign keys in the joining
tables...
e.g. i have a many to many reltnshp btwn Table A and Table B ..and join table
C
both have a column called pk.
and the join table C has columns call fk1 and fk2
does cmd require the same column name in the join table as in the joining table?
are there any workarounds?
thanksHI,
No, the foreign key column names in the join table do not have to match the primary
key names in the joined tables.
-thorick -
How to resolve many-to-many join by 2 one-to-many joins
Hi,
I was asked many times how to resolve many to many relationship between two tables. I read to use 2 one -to- many relationships to resolve this. Can some expalin me when many to many relationship occurs between two tables and how to reslove them with practicle examples. Is there any article on this?
Regards,
Nanda KishoreHi,
Please check below link.
http://www.forumtopics.com/busobj/viewtopic.php?p=859029&sid=20d79e3df07b0d8b41aadfbd902bb6b2
http://blog.oaktonsoftware.com/2011/04/bridge-tables-and-many-to-many.html
Thanks,
Amit -
Insert/delete many to many join in 9.0.3
Can anyone tell me a good way to create/delete an intersection row in a many to many relationship? I can do it programmatically in the client, but I'd rather have the middle tier view object or application module handle the code. Currently I'm creating a JClient application but later I will be putting the application in a browser. I don't want to rewrite the code every time I change my client application.
ThanksI forgot to mention that I'm using the BC4J framework.
Mike -
Duplication of Amounts in report based on One-many joins
Sorry for the long description but I think it's better to be explicit. This is a very generic problem though with the design of BO. We have BO /Webi 6.5. I support a reporting system delivered by a third party, and need to fix issues with the reports. I am free to customise the views, the Universe and the reports. The most frequent problem I am faced with, is that of duplication of figures in report columns derived from 'measure' objects. For eg:
A report needs to display Fixed Asset Capital Cost and Depreciation over period from-to. In a simplified form, the views and universe design are as following:
Two tables(views):
1. Fixed Asset:
Asset Number,
Asset Description,
Acquisition Date,
Retire Date,
Capital Cost ($)
The capital cost (acqusition cost) does not change
2. Fixed Asset Depreciation:
Asset Number,
Period Number,
Period Depreciation ($)
The Period Depreciation is a value that is deducted from the asset's capital value, month after month, until the asset is fully depreciated.
The two tables join on Asset Number. There is a 1 to N cardinality from table 1 to table 2, as well as outer join because not all Fixed Assets will have depreciation recorded.
As assets come and go, when the report is run for period from/to, not all assets have depreciation records for each period in range.
Report prompts are: Period Number From & Period Number To.
The report needs to display Grand Totals for:
Total Capital Costs from all assets that were on books in period from/to
Total depreciation period from/to
Simplified Report Format:
Reporting period From/To
Asset Number | Description | Capital Cost | Depreciation
nnnnnnnnnn | xxxxxxx | 99999999 | 99999999
========================================================
Grand Totals: Count Asset: 99999 | 99999999 | 99999999
Universe Objects for Capital Cost and Period Depreciation are defined as Measures.
I have defined a second object in the Universe for Capital Cost as a Dimension, [Capital Cost dim], which allows to report correct Capital Cost value against the fixed asset item in the detail row of the deport.
In the report Grand Total I need to display sum([Capital Cost dim]). The problem I have is that this Grand Total includes duplication of amounts for Capital Cost, when reported for Perid From <> Period To, and where more than one period depreciation is recorded for the asset.
I realise the reason for the problem is in the joining of the two tables as a 1-N and so the Capital Cost is duplicated. I was not able to find a work around. In other reporting tools I could solve the problem in the report design, by naming the break variable used to report Capital Cost against the asset, and then summing up from that variable to obtain the Grand Total. In BO & Webi this does not seem to be available, the variable definitions for sum([object]) are global and appear to work the same on all breaking levels up to grand total.
Your help is much appreciated.
Edited by: Calator on Jun 2, 2010 8:18 AMTwo ways to over come this situation,
1. Create two data providers. One for the Depreciation and the second on for Fixed cost.
In the report merge asset Number and have the measure objects do the magic for you.
2. Kind of complex, but worth trying. This works in the table column, Try and see if it works in the footer of the table
Create a varible for the table column.
Asset# count=Count([(Merged)Asset Number])
Actual value=Sum(If([Asset# count]>1; ([Fixed Cost]/[Asset# count]);[Fixed Cost]))-Sum([Depreciation]) -
Sum of average in report with many joins
hello all. i have read a few other threads that are similar to my situation but nothing i've found that helps my specific situation. it is probably in part to my lack of expertise but i am pretty much a newbie here so go easy on me.
in summary, i have an employee table (em), a rooms table (rm), and an organizational hierarchy table (org_hier). em and rm tables are joined on the building, floor, and room fields that are in each table. org_hier table can be linked to either em or rm.
basically i am just trying to take the average area of each room (rm.area). here may be multiple occupants in a room and i don't want rm.area to be counted more than once which is the reason for the average. i then want a sum of that average at each level of the org hierarchy by using groups and a grand total at the end. the trick is that i am only looking for rooms that house certain employees, restricted by the em.em_id. that is the only reason for the em table being included.
would you all suggest using subreports somehow or is there a SQL function that would work best? let me know if i am being too vague here. what should my joins be?
thanks in advance,
jsthanks Sharon. i think i'm getting closer to what i need.
should i use the same running total in each group or will i need to create a new running total for each grouping? should the running total evaluate on each record and reset on change of rm.rm_id? is a manual running total different?
right now i am getting the right values at the room level but it is totalling all records of the room area at the floor level, not just the one instance.
i can email a screenshot if it is helpful. thanks for your help so far! -
Many-to-many performance issue
I realize that many-to-many joins have been discussed before (yes, I looked through many threads), but I'm having a slight variation on the issue. Our data warehouse has been functioning for a couple of years now, but we're now experiencing a dramatic degradation in report performance. I'll tell you everything I know and what I've tried. My hope is that someone will have an idea that hasn't occurred to me yet.
The troubling data links deal with accounts and account_types. Each transaction will have one account, but each account can have multiple account_types and each account_type is made up of multiple accounts. It ends up looking like this:
Transaction_cube --< account_dimension >--< account_type_table
Given the many-to-many relationship between account and account_type, this is the only architecture I could come up with that will maintain data integrity in the transaction cube.
I know that this is the cause of the performance issues because the reports run normally when this is removed. The volume of data obviously increases over time, but the problem appeared very suddenly -- not a gradual degradation that one would expect from a volume issue. The cube is partitioned by year and we're a little below last year's growth.
The other fact to throw in is that the account_type table did increase in size by an additional 30% when we first noticed the problem. However, the business was able to go back and remove half of the account_types (unused types) so now the table has fewer rows than it had before we noticed the problem (~15k rows in the account_type table).
We have tried pinning the table so that it remain in memory, but that did not help. I tried creating a materialized view combining accounts and account_types with a similar lack of improvement. I've tried adding indexes, but there is still a full-table scan. All database objects are analyzed nightly after the data load is completed.
I'm fresh out of ideas at this point. Any suggestions and/or ideas would be greatly appreciated.I've thought about that. What it would mean would be aprox. 20 additional columns for each of the different account_types. Unfortunately, that would also mean that all the reports that use the account_type would have to have a condition:
WHERE acct_type1='Income Stmt." OR acct_type2='Income Stmt." OR ....
Since the account_types are not set up in a hierarchy and there must be only one row for account, I'm not sure that this is a feasible solution.
Thank you for the suggestion. -
Select from (too many) tables
Hi all,
I'm a proud Oracle Apex developer. We have developed an Interactive Report that is generated from many joined tables in a remote system. I've read that to improve performances we can do the following:
1) Create a temporary table on our system that stores the app_user id and the colmun as a result of the query
2) Create a procedure that does:
declare
param1:= :PXX_item
param2:= :PXY_item.
param3:= :V('APP_USER')
insert into <our_table>
(select param3, <query from remore system>)
commit;
3) Rediresct to a query page where IR reads from this temp table
On "Exit" button there's a procedure that purge table data of that user (delete from temp where user=V('app_user'), so the temp table is only filled with necessary data.
Do you see any inconvenience? Application will be used from about 500 users, about 50 concurrent users at a time.
Thank you!1) We don't have a control on source syste, we can only perform query on itI was referring to a materialized view on the system where Apex is installed, not on the source database.
2) There are many tables involvedI don't understand why this is a problem. Too much data I can see, but too many tables... not so much.
3) Data has to be in real time, with no delayThis would a problem for MV or collections. The collections would store the data as of the initial query. Any IRs using the collection after the fact would be using stale data. If you absolutely have to have the data as of right now every time, then the full query must run on the remote system every time. Tuning that query is the only option to make it faster.
4) There are many transactions on the source tables (they are the core of the source system) and so MV could not be refreshed so fastProbably could be with fast refresh enabled, but not necessarily practical to do so. As I indicated in 3, you have painted yourself into a corner here. You have indicated a need for a real-time query and that eliminates a number of possibilities for query-once use-many performance solutions. -
Post Author: Don
CA Forum: Formula
Hello Everyone,
I need some assistance. I have a one to many relationship...
Example...
TABLE 1
FieldName = RecordID
DATA, RecordID= 10
TABLE 2, linked one to many to RecordID in TABLE1
FieldNames = RecordID, Name, ContactType
DATA, RecordID= 10, Name= Tom, ContactType= Sales
DATA, RecordID= 10, Name= Dan, ContactType= Service
DATA, RecordID=10, Name= Jon, ContactType= Sales
What I am looking for is to create a formula that would return something that looks like this....
Sales Contact Name
Tom, Jon
So... I want to grab all the "Contact Types" of "Sales" from TABLE 2 then pass in the "Name" field from TABLE 2 and if there is more then one "Name" of the sames "Contact Type" then comma seperate it.
And... I don't want to do this in a sub report. I do know I can make a sub report and return both values but to my knowledge the values would be on top of one another and not beside each other comma separated.
Ideas?Post Author: Don
CA Forum: Formula
That may work using a subreport...
I think the root of this my problem is the fact I have a table relationship, left outer... one to many join. So even if I drop your suggested formula in my report I still get repeating record details with blank names where all the other contact types would be.
Ticket Number Contact Name Contact Type
111111 Dan, Jim Sales
111111 <---- where the other contact type appear
111111 <---- where the other contact type appear
I was trying to avoid having to create several subreports for each data field I need on the report. However, I think I can use your formula in a subreport to allow the data to display in a comma separated row rather then a vertical list.
I thought about suppressing but that won't work because I have other contact types I need to list.
Thank you for responding. -
hi
i am a fresher and i have a question. how many joins can program have.Hi Jaya,
ABAP has two Joins.
INNER JOIN and OUTER JOIN.
Check out the post :
JOINS and Matchcodes
IF you press F1 on JOIN statement ,it has explained really good.I am pasting the same for you.
... FROM tabref1 [INNER] JOIN tabref2 ON cond
Effect
The data is to be selected from transparent database tables and/or views determined by tabref1 and tabref2. tabref1 and tabref2 each have the same form as in variant 1 or are themselves Join expressions. The keyword INNER does not have to be specified. The database tables or views determined by tabref1 and tabref2 must be recognized by the ABAP Dictionary.
In a relational data structure, it is quite normal for data that belongs together to be split up across several tables to help the process of standardization (see relational databases). To regroup this information into a database query, you can link tables using the join command. This formulates conditions for the columns in the tables involved. The inner join contains all combinations of lines from the database table determined by tabref1 with lines from the table determined by tabref2, whose values together meet the logical condition (join condition) specified using ON>cond.
Inner join between table 1 and table 2, where column D in both tables in the join condition is set the same:
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Inner Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a4
b4
c4
3
3
e2
f2
g2
h2
|--||||||||--|
Example
Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
Note
In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
Example
Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
DATA: DATE LIKE SFLIGHT-FLDATE,
CARRID LIKE SFLIGHT-CARRID,
CONNID LIKE SFLIGHT-CONNID.
SELECT FCARRID FCONNID F~FLDATE
INTO (CARRID, CONNID, DATE)
FROM SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID
WHERE FCONNID = PCONNID
AND P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / DATE, CARRID, CONNID.
ENDSELECT.
Note
Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
Only a table or view may appear to the right of the JOIN operator, not another join expression.
Only AND is possible in the ON condition as a logical operator.
Each comparison in the ON condition must contain a field from the right-hand table.
If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
Note
In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
Variant 3
... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
Effect
Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
Left outer join between table 1 and table 2 where column D in both tables set the join condition:
Table 1 Table 2
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
3
e2
f2
g2
h2
a3
b3
c3
2
4
e3
f3
g3
h3
a4
b4
c4
3
|--|||--|
Left Outer Join
A
B
C
D
D
E
F
G
H
a1
b1
c1
1
1
e1
f1
g1
h1
a2
b2
c2
1
1
e1
f1
g1
h1
a3
b3
c3
2
NULL
NULL
NULL
NULL
NULL
a4
b4
c4
3
3
e2
f2
g2
h2
|--||||||||--|
Example
Output a list of all custimers with their bookings for October 15th, 2001:
DATA: CUSTOMER TYPE SCUSTOM,
BOOKING TYPE SBOOK.
SELECT SCUSTOMNAME SCUSTOMPOSTCODE SCUSTOM~CITY
SBOOKFLDATE SBOOKCARRID SBOOKCONNID SBOOKBOOKID
INTO (CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID)
FROM SCUSTOM LEFT OUTER JOIN SBOOK
ON SCUSTOMID = SBOOKCUSTOMID AND
SBOOK~FLDATE = '20011015'
ORDER BY SCUSTOMNAME SBOOKFLDATE.
WRITE: / CUSTOMER-NAME, CUSTOMER-POSTCODE, CUSTOMER-CITY,
BOOKING-FLDATE, BOOKING-CARRID, BOOKING-CONNID,
BOOKING-BOOKID.
ENDSELECT.
If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or using an alias.
Note
For the resulting set of a SELECT command with a left outer join in the FROM clause, it is generally of crucial importance whether a logical condition is in the ON or WHERE condition. Since not all of the database systems supported by SAP themselves support the standard syntax and semantics of the left outer join, the syntax has been restricted to those cases that return the same solution in all database systems:
Only a table or view may come after the JOIN operator, not another join statement.
The only logical operator allowed in the ON condition is AND.
Each comparison in the ON condition must contain a field from the right-hand table.
Comparisons in the WHERE condition must not contain a field from the right-hand table.
The ON condition must contain at least one "real" JOIN condition (a condition in which a field from tabref1 as well as from tabref2 occurs).
Note
In some cases, '*' may be specivied as the field list in the SELECT clause, and an internal table or work area is entered in the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the llen in der FROM clause, according to the structure of each table work area. There can be gaps between the table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, as in the following example (not simply by counting the total number of fields).
Example
Example of a JOIN with more than two tables: Select all flights from Frankfurt to New York between September 10th and 20th, 2001 where there are available places, and display the name of the airline.
DATA: BEGIN OF WA,
FLIGHT TYPE SFLIGHT,
PFLI TYPE SPFLI,
CARR TYPE SCARR,
END OF WA.
SELECT * INTO WA
FROM ( SFLIGHT AS F INNER JOIN SPFLI AS P
ON FCARRID = PCARRID AND
FCONNID = PCONNID )
INNER JOIN SCARR AS C
ON FCARRID = CCARRID
WHERE P~CITYFROM = 'FRANKFURT'
AND P~CITYTO = 'NEW YORK'
AND F~FLDATE BETWEEN '20010910' AND '20010920'
AND FSEATSOCC < FSEATSMAX.
WRITE: / WA-CARR-CARRNAME, WA-FLIGHT-FLDATE, WA-FLIGHT-CARRID,
WA-FLIGHT-CONNID.
ENDSELECT.
Regards,
Priyanka. -
BIEE Physical and Business joins
Hi
I have about 10 table in database that I join. almost all table are interconnected. I have made many joins but that is not woking properly. some time it gives error and some time it gives double result.
So can anyone tell me what are the precaution i have to take to join these table. I am verymuch frustated because lat 4 days I am trying to do this but i cant.
Thanks
Siddhartha PHi Daan Bakboord
I got little bit. As I have seen this Aggregation rules we must have apply only in fact table and not in other table that are present in Business Model And Mapping. Actually If we try to apply Aggregation rules on other table then it is showing following error
View Display Error
Odbc driver returned an error (SQLExecDirectW).
Error Details
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 14026] Unable to navigate requested expression: TARGET_UTILIZATION:[DAggr(WORKSTATION_MASTER.TARGET_UTILIZATION [ ] by [ WORKSTATION_MASTER.WORKSTATION_ID [ ] ] SB WORKSTATION_MASTER)]. Please fix the metadata consistency warnings. (HY000)
SQL Issued: SELECT WORKSTATION_MASTER.TARGET_UTILIZATION saw_0 FROM LMW
but if I apply it in Fact table then it is working properly.
So I want to know that this aggregation rule we can apply only in Fact table"As I think" or we can apply it any where?
Thanks
Siddhartha P
Maybe you are looking for
-
What is (ParamErr: error in user parameter list)
I get the following error message when I try to send my imovie '11 project to iDvd: Unable to prepare project for publishing. The project could not be prepared for publishing because an error occurred. (ParamErr: error in user parameter list) Anybody
-
I don't know whether to get a new MacBook or not.....
I have a 2007 MacBook. Cheapest one you could get, with the small screen. Specs are: - 2GHz Intel Core 2 Duo Processor - 1GB 667 MHz DDR2 SDRAM - Snow Leopard 10.6.8 When I go to get HD information it says this: Capacity: 79 GB Available: 47 GB Used:
-
Fault policy files in MDS repository is not working 11g
Hi All, I have created my fault policy and fault bindings file and tested in my local project. It worked fine. To make it available in MDS, I added the files under JDeveloperHome/jdeveloper/integration/seed/apps/faulthandling I deployed this MDS repo
-
Use of Class Vs Interface for defining application constants
I want to use some constants through out the application. For that I found two ways to do that as given below 1. We can define constants in a class as public class ConstantClass { public static final String applConstant = "Some Constant"; and use it
-
IPhone won't connect to wifi at all!! Please help.
I have an iPhone 4 and I don't use it as a phone any more but I do use it for downloading songs and stuff of wifi, kinda like an iPod touch but I dropped it in water(not the first time I have done this) and as usual it will come back alive after dryi