Need suggestions with massive query
I have a huge report that gathers data about all facets of the company to display in one place. I have built a procedure to calculate and store the data (as it gets processed once and viewed often), but the query to display it is huge - about 1950 lines or 104 KB. I can run the report fine in SQL developer, but I need it in APEX, which is limited in its report area to 32KB per query. The report is basically the same chunk over and over referencing each of the saved calculations in a particular order. Here's a sample of a report section:
union
select 833 as SCTN_ID, 'Efficiency' as SCTN
, 'Variance' as TTL
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-6) as WK1
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-13) as WK2
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-20) as WK3
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-27) as WK4
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-34) as WK5
, 'var' as CLASS
from vf_run_byweek p
where p.org_id = :P2007_ORG_ID
and p.last_day = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')
...There are about 20 report areas - not all the same format - and each area usually has the target, actual, variance, and variance as % displayed for 5 weeks at a time on a rolling basis - so a 5x9 grid for each area once you add in variable column headers, etc. The sample above gives me one line of the 5 or so in a section.
I need some way to get around the 32K limit. I've tried building this as a view, but I need to pass in the parameters to select the correct date and organization. Can someone suggest a solution? (PS, I am trying to stay away from a stored procedure if possible as a standard report format will download to csv.)
Duplicate - Need help with massive query
Similar Messages
-
I have a huge report that gathers data about all facets of the company to display in one place. I have built a procedure to calculate and store the data (as it gets processed once and viewed often), but the query to display it is huge - about 1950 lines or 104 KB. I can run the report fine in SQL developer, but I need it in APEX, which is limited in its report area to 32KB per query. The report is basically the same chunk over and over referencing each of the saved calculations in a particular order. Here's a sample of a report section:
union
select 833 as SCTN_ID, 'Efficiency' as SCTN
, 'Variance' as TTL
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-6) as WK1
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-13) as WK2
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-20) as WK3
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-27) as WK4
, (select to_char(GOAL-ACTUAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'HARD_BRAKES'
and a.period_start = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')-34) as WK5
, 'var' as CLASS
from vf_run_byweek p
where p.org_id = :P2007_ORG_ID
and p.last_day = to_date(:P2007_LAST_DAY,'MM/DD/YYYY')
...There are about 20 report areas - not all the same format - and each area usually has the target, actual, variance, and variance as % displayed for 5 weeks at a time on a rolling basis - so a 5x9 grid for each area once you add in variable column headers, etc. The sample above gives me one line of the 5 or so in a section.
I need some way to get around the 32K limit. I've tried building this as a view, but I need to pass in the parameters to select the correct date and organization. Can someone suggest a solution? (PS, I am trying to stay away from a stored procedure if possible as a standard report format will download to csv.)Okay, so this is my first foray into parameterized views, so if someone could help me understand. I created a page process to fire AFTER HEADER, BEFORE REGIONS containing the following:
-- Set the context for Min and max dates.
DBMS_SESSION.set_context (namespace => 'VF_PARAMS',
ATTRIBUTE => 'org',
VALUE => :P2007_ORG_ID
DBMS_SESSION.set_context(namespace => 'VF_PARAMS',
ATTRIBUTE => 'last_day',
VALUE => :P2007_LAST_DAY
);I created a sample view to get this working as such:
CREATE OR REPLACE VIEW V_VF (SECTION_NUM, SECTION, TITLE, WK1, WK2, WK3, WK4, WK5, CLASS)
as (
--100 Safety
select 110 as SCTN_ID, 'Safety' as SCTN
, '# of Safety Audits' as TTL
, 'Week of '||to_char(to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-06,'Mon dd') as WK1
, 'Week of '||to_char(to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-13,'Mon dd') as WK2
, 'Week of '||to_char(to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-20,'Mon dd') as WK3
, 'Week of '||to_char(to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-27,'Mon dd') as WK4
, 'Week of '||to_char(to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-34,'Mon dd') as WK5
, 'colhdr' as CLASS
from dual
union
select 111 as SCTN_ID, 'Safety' as SCTN
, 'Goal' as TTL
, (select to_char(GOAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'AUDITS'
and a.period_start = to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-6) as WK1
, (select to_char(GOAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'AUDITS'
and a.period_start = to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-13) as WK2
, (select to_char(GOAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'AUDITS'
and a.period_start = to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-20) as WK3
, (select to_char(GOAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'AUDITS'
and a.period_start = to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-27) as WK4
, (select to_char(GOAL) from vf_run_byweek_dtl a
where a.run_id = p.run_id and a.section = 'AUDITS'
and a.period_start = to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')-34) as WK5
, 'gl' as CLASS
from vf_run_byweek p
where p.org_id = SYS_CONTEXT('VF_PARAMS', 'org')
and p.last_day = to_date(SYS_CONTEXT('VF_PARAMS', 'last_day'),'MM/DD/YYYY')
)But when I try to run the page, I get this error:
Error ORA-01031: insufficient privileges
Technical Info (only visible for developers)
is_internal_error: false
ora_sqlcode: -1031
ora_sqlerrm: ORA-01031: insufficient privileges
component.type: APEX_APPLICATION_PAGE_PROCESS
component.id: 376623425929869335
component.name: Set SYS_CONTEXT parameters for view
error_backtrace:
ORA-06512: at "SYS.WWV_DBMS_SQL", line 904
ORA-06512: at "APEX_040100.WWV_FLOW_DYNAMIC_EXEC", line 618
ORA-06512: at "APEX_040100.WWV_FLOW_PROCESS", line 128I tried granting CREATE ANY CONTEXT to several users including APEX_PUBLIC_USER and APEX_040100, but this didn't seem to work. I've read through several blog posts and documents, but I must be doing something wrong in my implementation of trying to set the SYS_CONTEXT values. I would greatly appreciate some enlightenment, as the documentation I have read kind of skips over the set of the context in the first place and goes right into use. I fear this is the piece I am missing, or I have read over it and it just isn't clicking. There is some mention of having to reference SYS_CONTEXT via a package, but this went straight over my head. -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Please, need help with a query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_dateTake a look on the syntax :
max(...) keep (dense_rank last order by ...)
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#i1000901
Nicolas. -
Please need help with this query
Hi !
Please need help with this query:
Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
order by a.create_datePerhaps something like this...
select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
from (
select distinct a.id,
create_date,
a.loanid,
a.rate,
a.pays,
a.gracetime,
a.emailtosend,
d.first_name,
d.last_name,
a.user_id,
max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
from CLAL_LOANCALC_DET a,
loan_Calculator b,
bv_user_profile c,
bv_mr_user_profile d
where b.loanid = a.loanid
and c.NET_USER_NO = a.resp_id
and d.user_id = c.user_id
and a.is_partner is null
and a.create_date between
TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
where create_date = max_create_date
order by create_date -
Need help with conditional query
guys this is just an extension of this post that Frank was helping me with. im reposting because my requirements have changes slightly and im having a hell of a time trying to modify the query.
here is the previous post.
need help with query that can look data back please help.
CREATE TABLE "FGL"
"FGL_GRNT_CODE" VARCHAR2(60),
"FGL_FUND_CODE" VARCHAR2(60),
"FGL_ACCT_CODE" VARCHAR2(60),
"FGL_ORGN_CODE" VARCHAR2(60),
"FGL_PROG_CODE" VARCHAR2(60),
"FGL_GRNT_YEAR" VARCHAR2(60),
"FGL_PERIOD" VARCHAR2(60),
"FGL_BUDGET" VARCHAR2(60)
)data
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');
I need to find the greatest grant year for the grant by a period parameter.
once i find the greatest year i need to check the value of period 14 for that grant for the previous year and add it to the budget amount for that grant. however if their is an entry in the greatest year for period 00 then i need to ignore the period 14 of previous year and do this calculation current period +(current period - greatest year 00)
hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
period 2 amount $ 600
period 0 amount $ 400 - period 2 amount of $600 = 200
600+200 = $800
if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
can you please help me out.
here is the query supplied by frank kulash who gracefully put this together for me.
WITH got_greatest_year AS
SELECT fgl.* -- or whatever columns are needed
, MAX ( CASE
WHEN fgl_period = :given_period
THEN fgl_grnt_year
END
) OVER () AS greatest_year
FROM fgl
SELECT SUM (fgl_budget) AS total_budget -- or SELECT *
FROM got_greatest_year
WHERE ( fgl_grnt_year = greatest_year
AND fgl_period = :given_period
OR ( fgl_grnt_year = greatest_year - 1
AND fgl_period = 14
;MiguelHi, Miguel,
Are you waying that, when the greatest year that has :given_period also has period='00' (or '0', or whatever you want to use), then you want to double the budget from the given_period (as well as subtract the budget from the '00', and not count the pevious year's '14')? If so, add another condition to the CASE statement which decides what you're SUMming:
WITH got_greatest_year AS
SELECT TO_NUMBER (fgl_grnt_year) AS grnt_year
, fgl_period
, TO_NUMBER (fgl_budget) AS budget
, MAX ( CASE
WHEN fgl_period = :given_period
THEN TO_NUMBER (fgl_grnt_year)
END
) OVER () AS greatest_year
FROM fgl
, got_cnt_00 AS
SELECT grnt_year
, fgl_period
, budget
, greatest_year
, COUNT ( CASE
WHEN grnt_year = greatest_year
AND fgl_period = '00'
THEN 1
END
) OVER () AS cnt_00
FROM got_greatest_year
SELECT SUM ( CASE
WHEN grnt_year = greatest_year -- New
AND fgl_period = :given_period -- New
AND cnt_00 > 0 THEN budget * 2 -- New
WHEN grnt_year = greatest_year
AND fgl_period = :given_period THEN budget
WHEN grnt_year = greatest_year
AND fgl_period = '00' THEN -budget
WHEN grnt_year = greatest_year - 1
AND fgl_period = '14'
AND cnt_00 = 0 THEN budget
END
) AS total_budget
FROM got_cnt_00
;You'll notice this is the same as the previous query I posted, except for 3 lines maked "New". -
Hi,
I need help with the following query. I want the balance (bal) with the latest exchange rate available.
Sample table & data
with
FX_RATE as
select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
select 12, 1, 48 from dual union
select 13, 2, 54 from dual union
select 14, 2, 55 from dual union
select 15, 3, 56 from dual union
select 15, 2, 49 from dual),
TBL_NM as
select 13 as p_date, 2 as p_curr, 200 as bal from dual union
select 14, 2, 200 from dual union
select 15, 2, 200 from dual union
select 16, 2, 200 from dual union
select 17, 2, 200 from dual union
select 11, 5, 100 from dual
select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1 on (id_curr = p_curr and F1.id_date = T.p_Date)In the above query for p_date 16 & 17 and p_curr 2 it returns just balance multiplied by exchange rate 1"default". But i want the balance to have data as per latest exchange rate which is of exchange rate 15.
I tried this but returns error ORA-01799: a column may not be outer joined to a subquery ..
with
FX_RATE as
select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
select 12, 1, 48 from dual union
select 13, 2, 54 from dual union
select 14, 2, 55 from dual union
select 15, 3, 56 from dual union
select 15, 2, 49 from dual),
TBL_NM as
select 13 as p_date, 2 as p_curr, 200 as bal from dual union
select 14, 2, 200 from dual union
select 15, 2, 200 from dual union
select 16, 2, 200 from dual union
select 17, 2, 200 from dual union
select 11, 5, 100 from dual
select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1
on (id_curr = p_curr and F1.id_date = (select max(F2.id_date) from FX_RATE F2 where F2.id_curr = T.p_curr and F2.id_Date <= T.p_date))Please advice on how i can achieve this ..The entire query wud be like this .. I've to incorporate in here
CREATE MATERIALIZED VIEW MV_DUMMY
BUILD IMMEDIATE
REFRESH FORCE ON DEMAND
AS
SELECT T.ID_TSACTION_RELEASED
BAL.ID_CONTRACT_BALANCE AS ID_CONTRACT_BALANCE,
T.N_REFERENCE_NUMBER
T.INSTRUMENT_N_REFERENCE
T.ITEM_NUMBER
T.EXTERNAL_SYSTEM_ID
T.SEQUENCE_NUMBER
T.ID_RELEASED_DATE
ROUND(BAL.LC_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)
BAL.LIABILITY_BALANCE
BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
BAL.LIABILITY_CHANGE_USD
BAL.MEMO_LIABILITY_BALANCE
BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
BAL.MEMO_LIABILITY_CHANGE_USD
BAL.ORIGINAL_FACE_AMOUNT
decode(T.TENOR_CODE,'Time','T','Sight','S','Split Sight Time','SST','Split Multiple Time','SMT',T.TENOR_CODE)
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN T.ID_LIABILITY_CIF
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN T.Id_Beneficiary
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN T.ID_Applicant
END PRIMARY_CUSTOMER_ID,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN plbcif.EXTERNAL_SYSTEM_ID
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN PBCIF.EXTERNAL_SYSTEM_ID
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN pappcif.EXTERNAL_SYSTEM_ID
END PRIMARY_CUSTOMER_EXT_SYS_ID,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN plbcif.CIF_NAME
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN PBCIF.CIF_NAME
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN pappcif.CIF_NAME
END PRIMARY_CUSTOMER_NAME,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN plbbac.BAC
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN pbbac.BAC
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN pappbac.BAC
END PRIMARY_CUST_BAC_CODE,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN nvl(plbmg.MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN nvl(pbmg.MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN nvl(pappmg.MARKET,'NOT APPLICABLE')
END PRIMARY_CUST_MARKET,
CASE
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
THEN nvl(plbmg.SUB_MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
THEN nvl(pbmg.SUB_MARKET,'NOT APPLICABLE')
WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
THEN nvl(pappmg.SUB_MARKET,'NOT APPLICABLE')
END PRIMARY_CUST_SUB_MARKET
FROM F_TSACTION_RELEASED T
LEFT OUTER JOIN D_BAC_CODE BAC
ON (T.BAC_CODE_LIABILITY = BAC.BAC_CODE)
LEFT OUTER JOIN REF_BAC_SORT_CODE REF_BAC
ON (T.BAC_CODE_LIABILITY = REF_BAC.BAC)
LEFT OUTER JOIN F_CONTRACT_BALANCE BAL
ON (T.ID_TSACTION_RELEASED = BAL.ID_TSACTION_RELEASED)
LEFT OUTER JOIN D_MARKET_SEGMENT MG
ON (T.ID_MARKET_SEGMENT = MG.ID_MARKET_SEGMENT)
LEFT OUTER JOIN D_DATE DT
ON (DT.ID_DATE = T.ID_RELEASED_DATE)
LEFT OUTER JOIN D_DATE DB
ON (DB.ID_DATE = BAL.ID_RELEASED_DATE)
LEFT OUTER JOIN D_PROCESSING_UNIT PU
ON (PU.ID_PROCESSING_UNIT = T.ID_PROCESSING_UNIT)
LEFT OUTER JOIN D_BIR_PRODUCT BIRPROD
ON (BIRPROD.ID_BIR_PRODUCT=T.ID_BIR_PRODUCT)
LEFT OUTER JOIN D_GTS_PRODUCT_TYPE GTSPROD
ON (GTSPROD.ID_GTS_PRODUCT_TYPE= T.ID_GTS_PRODUCT_TYPE)
LEFT OUTER JOIN D_GTS_TSACTION_TYPE GTST
ON (GTST.ID_GTS_TSACTION_TYPE = T.ID_GTS_TSACTION_TYPE)
LEFT OUTER JOIN D_CURRENCY CCYT
ON (CCYT.ID_CURRENCY = T.ID_TSACTION_CURRENCY)
LEFT OUTER JOIN d_cif lcif
ON (lcif.id_cif = T.id_liability_cif)
LEFT OUTER JOIN d_cif lbcif
ON (lbcif.id_cif = bal.id_liability_cif)
LEFT OUTER JOIN d_cif bcif
ON (bcif.id_cif = T.id_BENEFICIARY)
LEFT OUTER JOIN d_cif icif
ON (icif.id_cif = T.id_ISSUING_BANK)
LEFT OUTER JOIN d_cif acif
ON (acif.id_cif = T.id_ADVISING_BANK)
LEFT OUTER JOIN d_cif appcif
ON (appcif.id_cif = T.id_applicant)
LEFT OUTER JOIN d_state astate
ON (astate.id_state = acif.id_state)
LEFT OUTER JOIN d_state bstate
ON (bstate.id_state = bcif.id_state)
LEFT OUTER JOIN d_state lstate
ON (lstate.id_state = lcif.id_state)
LEFT OUTER JOIN d_state lbstate
ON (lbstate.id_state = lbcif.id_state)
LEFT OUTER JOIN d_state istate
ON (istate.id_state = icif.id_state)
LEFT OUTER JOIN d_state appstate
ON (appstate.id_state = appcif.id_state)
LEFT OUTER JOIN D_TSACTION_SOURCE TSrc
ON (T.ID_TSACTION_SOURCE = TSrc.ID_TSACTION_SOURCE)
LEFT OUTER JOIN D_COUNTRY LCTRY
ON (LCTRY.ID_COUNTRY = lcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY LBCTRY
ON (LBCTRY.ID_COUNTRY = lbcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY BCTRY
ON (BCTRY.ID_COUNTRY = bcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY ICTRY
ON (ICTRY.ID_COUNTRY = icif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY ACTRY
ON (ACTRY.ID_COUNTRY = acif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY APPCTRY
ON (APPCTRY.ID_COUNTRY = appcif.ID_COUNTRY)
LEFT OUTER JOIN D_COUNTRY PCTRY
ON (PCTRY.ID_COUNTRY = T.ID_PRESENTER_COUNTRY)
LEFT OUTER JOIN D_LOCATION LOC
ON (LOC.ID_LOCATION = T.ID_PROCESSING_LOCATION)
LEFT OUTER JOIN D_CURRENCY BCCYT
ON (BCCYT.ID_CURRENCY = BAL.ID_LIABILITY_CURRENCY)
LEFT OUTER JOIN D_CURRENCY BALCYT
ON (BALCYT.ID_CURRENCY = BAL.ID_BALANCE_CURRENCY)
LEFT OUTER JOIN d_liability_type li
ON (li.id_liability_type = BAL.id_liability_type)
LEFT OUTER JOIN d_cif plbcif
ON (plbcif.id_cif = T.id_liability_cif)
LEFT OUTER JOIN REF_BAC_SORT_CODE plbbac
ON (plbcif.bac_code=plbbac.bac)
LEFT OUTER JOIN D_MARKET_SEGMENT plbmg
ON (plbbac.SORT_CODE=plbmg.MARKET_SEGMENT)
LEFT OUTER JOIN d_cif pbcif
ON (pbcif.id_cif = T.id_BENEFICIARY)
LEFT OUTER JOIN REF_BAC_SORT_CODE pbbac
ON (pbcif.bac_code=pbbac.bac)
LEFT OUTER JOIN D_MARKET_SEGMENT pbmg
ON (pbbac.SORT_CODE=pbmg.MARKET_SEGMENT)
LEFT OUTER JOIN d_cif pappcif
ON (pappcif.id_cif = T.id_applicant)
LEFT OUTER JOIN REF_BAC_SORT_CODE pappbac
ON (pappcif.bac_code=pappbac.bac)
LEFT OUTER JOIN D_MARKET_SEGMENT pappmg
ON (pappbac.SORT_CODE=pappmg.MARKET_SEGMENT)
LEFT OUTER JOIN D_CURRENCY LOCALCYT
ON (LOCALCYT.alpha_code = PU.local_ccy)
LEFT OUTER JOIN D_BRANCH Branch
ON (T.ID_BRANCH = Branch.ID_BRANCH )
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
ON (LOCALCYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCALCYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Note the lines
ROUND(BAL.MN_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)
BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)
And
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
ON (LOCAMNYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCAMNYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Thsi is where I need to incorporate the change -
I am trying to build a query that sums up 12 columns depending on some accounting variables.
example:
SELECT gbmcu, gbco, gbfy,'',SUM(gban01 gban02 gban03 gban04 gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12) AS Oil_Volumes
FROM PRODDTA.F0902
WHERE GBCO = '00099'
AND GBFY = 5
AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
GROUP BY gbmcu, gbco, gbfy
The condition that changes is :AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
I need to do this for 17 different conditions - I need to make the query as optimized as possible.
I tried using a case statement but that takes forever (the table is over 4 million records to scan through).
Please let me know if anyone has any suggestions on how to create something to perform these calculations.
thanks,
PamI think I would tend to write that query as:
SELECT gbmcu, gbco, gbfy,
SUM(CASE WHEN gblt = 'QA' AND gbobj = 5015 AND gbsub = '105' THEN
gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Sales
SUM(CASE WHEN gblt = 'QU' AND gbobj = 5015 AND gbsub = '105' THEN
gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Volumes
FROM proddta.f0902
WHERE gbco = '00099' and
gbfy = 5 and
gblt IN ('QA', 'QU') and
gbpbj = 5015 and
gbsub = '105'
GROUP BY gbmcu, gbco, gbfySUM the CASE rather than CASE SUM. Also, as written, your query will look at all of the records in f0902 whether or not they meet one of the Case criteria, so I would put the required values in the WHERE clause as well. Your samples only show gblt changing, so you may need to make the gbpbj and gbsub predicates IN lists as well.
If the query runs in 1.5 hours calculating one value, I would expect it to be about the same calculating 17 values, since I would bet that most of the run time is accessing the table rather than doing the math. It would almost certainly be faster than running essentially the same query 17 times.
Indexes on some or all of the columns in the WHERE clause may help, depending on how selective the columns are. At a guess, I would suggest that gbco and gbfy would be good candidates.
Finally, are you sure that gbsub is a character field? The only example we have is a number.
HTH
John -
Hi,
I have column which is having values like
EMEA/MEA/IT
EMEA/WE/GE
EMEA/MEA/SA
EMEA/WE/jk
but i need to get all these rows based on some front selected values where we will select like EMEA/MEA & EMEA/WE.But that value will be ';' separated like EMEA/MEA%;EMEA/WE%.Based on this value l need to retrieve all the rows based on this value (Note ';' as the delimiter) .I tried with INSTR , but not able to sort out.
Could some one please me on this one how to make this condition in my query.
Thanks,Thanks Frank for your response.
Table will have thousands of rows where column which I comparing(OU_DIV_REG) will be like with many combination's.I am attaching some data for reference.
EMEA/DIV/
EMEA/DIV/HYP
EMEA/EE
EMEA/EE&CIS
EMEA/EE&CIS/
EMEA/EE&CIS/CENT
EMEA/EE&CIS/CIS
EMEA/EE&CIS/GR
EMEA/EE&CIS/RO
EMEA/EE&CIS/RTG
EMEA/EE&CIS/SBL
EMEA/EE&CIS/SEES
EMEA/EE&CIS/TR
EMEA/EMEA_OTM/
EMEA/FMEA/FR
EMEA/FMEA/MEA
EMEA/IL
EMEA/MEA
EMEA/MEA/
EMEA/MEA/EG
EMEA/MEA/SA
EMEA/MEA/ZA
EMEA/NE/BLX
EMEA/SE
EMEA/SE/ALPS
EMEA/SE/IBE
EMEA/UK
EMEA/UK/
But I am using this condition in APEX.Actually I have a report with return query and that will execute. I need this condition to be in where clause.I am attaching my APEX report query for your reference. I updating that where clause condition in BOLD letters where i need to add this condition that will consider all the rows from the table wherever input from APEX page will be like fallowing with ';' as delimter.
EMEA/MEA%;EMEA/EE&CIS%
Considering this input values, I need to consider all the rows above where that column value us having EMEA/MEA% and EMEA/EE&CIS%.
I tried adding the where clause which in BOLD letter (cluster condition).Please let me know will it work or also I need to how to add these XMLtable separation based on ',' in where clause.
For you reference I am just my full report query(which is not needed i know - but just have the full understanding).
DECLARE
lc_query VARCHAR2(4000);
BEGIN
lc_query := 'SELECT INITCAP(SUBSTR(end_cli_name,1,20)) Customer
,DECODE(cps_id,NULL,INITCAP(SUBSTR(title,1,20)),''<a href="http://cpotsi.oraclecorp.com/pls/cpotsiweb/CPOTSI.EP_WITHDRDTA_RAG_L.show_cps?p_cps_id=''||cps_id||''&p_uptodate=''||:P_DD||''" target=_blank>''||INITCAP(SUBSTR(title,1,20))||''</a>'') Project
,ou_ctry_code
,funding_amnt
,budgeted_margin_amnt
,TO_NUMBER(eac_margin_amnt)
,decode(substr(PREV_CPS_RAGU_L_1,1,1),
''R'',''<img src="#APP_IMAGES#red.jpg" alt="Red">'',
''A'',''<img src="#APP_IMAGES#amber.jpg" alt="Amber">'',
''G'',''<img src="#APP_IMAGES#green.jpg" alt="Green">'',
''U'',''<img src="#APP_IMAGES#unknown.jpg" alt="Unknown">'',
''<img src="#APP_IMAGES#unknown.jpg" alt="Unknown">'') RAGU
FROM emea_pmr_disco_input WHERE
month=:P_SELECTED_MONTH
AND year=:P_SELECTED_YEAR
AND region IN (SELECT region_code
FROM emea_pmr_regions
START WITH ( INSTR('':''||:P_SELECTED_REGION||'':'','':''||region_code||'':'',1,1) > 0 )
CONNECT BY PRIOR region_code=parent_region_code)
AND prof_com_text LIKE :P_SELECTED_INDUSTRY ';
IF :P_SELECTED_CLUSTER <> '%' THEN
lc_query := lc_query ||
*' AND upper(ou_div_reg) LIKE ''*
SUBSTR(:P_SELECTED_CLUSTER,1,INSTR(:P_SELECTED_CLUSTER,'';'',1,1)-1 )'' OR
upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,1)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,2) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,1)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,2)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,3) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,2)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,3)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,4) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,3)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,4)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,5) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,4)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,5)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,6) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,5)-1) ) ) ''
OR upper(ou_div_reg) LIKE ''
SUBSTR(:P_SELECTED_CLUSTER,INSTR(:P_SELECTED_CLUSTER,'';'',1,6)+1,(INSTR(:P_SELECTED_CLUSTER,'';'',1,7) - (INSTR(:P_SELECTED_CLUSTER,'';'',1,6)-1) ) ) ''
END IF;
IF :P1_TIER2 <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier2)||'';'','';''||upper(T2)||'';'',1,1) > 0 ';
END IF;
IF :P1_TIER3 <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier3)||'';'','';''||upper(T3)||'';'',1,1) > 0 ';
END IF;
IF :P1_TIER4 <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:p1_tier4)||'';'','';''||upper(T4)||'';'',1,1) > 0 ';
END IF;
IF :P_SELECTED_COUNTRY <> '%' THEN
lc_query := lc_query || ' AND INSTR('';''||upper(:P_SELECTED_COUNTRY)||'';'','';''||upper(ou_ctry_code)||'';'',1,1) > 0 ';
ELSE
IF :P_IS_ADMIN = 'N' THEN
lc_query := lc_query || 'AND ou_ctry_code IN (SELECT country_code
FROM emea_pmr_user_countries
WHERE INSTR('':''||:P_SELECTED_REGION||'':'','':''||region_code||'':'',1,1) > 0
AND user_id = :P_SELECTED_USER_ID
AND view_access = ''Y'') ';
END IF;
END IF;
IF :P_TOPMARLOV='Current' THEN
lc_query := lc_query || ' AND UPPER(ep_state_name)=''STARTED''';
ELSIF :P_TOPMARLOV='Closed' THEN
lc_query := lc_query || ' AND UPPER(ep_state_name)=''CLOSED''';
END IF;
IF:P1_MARGIN_STATUS='R' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''R''';
ELSIF:P1_MARGIN_STATUS='G' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''G''';
ELSIF:P1_MARGIN_STATUS='A' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''A''';
ELSIF:P1_MARGIN_STATUS='U' THEN
lc_query := lc_query || ' AND
UPPER(substr(PREV_CPS_RAGU_L_1,1,1))=''U''';
END IF;
htp.p(lc_query);
RETURN lc_query;
END; -
Hi.. need help with a query
hello guys :)
I need help with this exercise:
Find the most common cooking method in recipes that contain tomatoes.
the 4 tables:
t_recipes
--recipe_no
--recipe_name
t_products
--product_no
-product_name [tomatoes,cucumbers, onions]
t_integration
--product_no
--recipe_no
t_cooking_mode
recipe_no
mode [Frying,baking]
I am realy lost :S
thank youHi,
851072 wrote:
Thank you for your comment :)
But... I didn`t understand the first partSorry, what part is that? You probably understood "Welcome to the forum!" It looks like you understood most of what I said, perhaps before I said it. You seem to be on the right track.
Unlike talking to a co-worker in the next cube, exchanging messages with someone on this forum takes a fair amount of time, so it's worth the time it takes to explain things very clearly, more than you would in conversation. Post all the relevant information, and say exactly what the problem is.
amm i tried to do this:
select t_recipes.recipe_name, count(t_cooking_mode.cooking_mode)
from (t_cooking_mode INNER JOIN t_integration ON t_cooking_mode.recipe_no = t_integration.recipe_no )
INNER JOIN t_products ON t_integration.product_no = t_products.product_no)
WHERE t_products.product_name = 'tomatoes'
GROUP BY t_recipes.recipe_name
help?Please help by posting whatever you know about the problem. For example, if there's a error message, post the complete error message, including the line number.
Help the people who want to help you by formatting your code and making it easy to read and understand. This will help you, too.
For example, here's exactly what you posted, with only the white-space changed to make parallel items, such as parentheses, line up nicely:
select t_recipes.recipe_name
, count(t_cooking_mode.cooking_mode)
from ( t_cooking_mode
INNER JOIN t_integration ON t_cooking_mode.recipe_no = t_integration.recipe_no
INNER JOIN t_products ON t_integration.product_no = t_products.product_no
WHERE t_products.product_name = 'tomatoes'
GROUP BY t_recipes.recipe_nameWhen you format your code like this, it can be very easy to spot errors like unbalanced parentheses. In this case, the ')' right before the WHERE clause has no matching '('. You don't need to use any parentheses at all in the FROM clause. You can simply say:
FROM t_cooking_mode
JOIN t_integration ON t_cooking_mode.recipe_no = t_integration.recipe_no
JOIN t_products ON t_integration.product_no = t_products.product_no
WHERE ...INNER JOIN is the default kind of join, which makes sense, since the majority of all joins are inner joins. I usually say JOIN (instead of INNER JOIN) because it makes the code more compact and easier to read (at least for me), but I won't be maintaining your code, so do what's best for you.
What are you trying to find in this problem? Is it a recipe name or a cooking mode? If it's a cooking mode, the why do you have t_recipes.reciple_name in the SELECT (and GROUP BY) clause? Shouldn't you be using some other column, from some other table?
If I understand the problem correctly, the t_recipes table is not needed in this problem. You won't necessarily use every table in every query.
When you post formatted text on this site, type these 6 characters:
\(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing. -
Need help with named query for 1-to-many entities
Hi all,
I'm in desperate need of a query and I can't seem to figure it out.
Here's the situation:
I have 2 entities in a one-to-many relationship. One ServerInstance to Many AppUrl's related by a join table
@Entity
public class ServerInstance implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
private String instancename;
private String description;
private String home;
private String hostname;
private String hostname_front;
private String ipfront;
private String ipback;
private String os;
private String layer;
@OneToMany (fetch = FetchType.EAGER, cascade = {CascadeType.ALL})
private List<AppUrl> appUrl = new ArrayList<AppUrl>();
@Entity
public class AppUrl implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Integer id;
private String appurl;
private String description;
private String keyword;
private Integer priority;
private String curlresult;
In the underlying database they are mapped by the table T_SERVERINSTANCE_T_APPURL
What I need is a named query in the ServerInstance entity to find any AppUrl where curlresult = 'down'
I tried the following:
@NamedQuery
(name = "findDownInstances", query = "SELECT i FROM ServerInstance i WHERE i.appUrl.result = 'down')
This gave me the following error:
invalid navigation expression [i.appUrl.result], cannot navigate collection valued association field [appUrl].
Is there any way to create a query which will do what I want?
Thanx in advance!can you provide the equivalent SQL (not JPQL!) query that you want, based on tables T_SERVERINSTANCE and T_APPURL, so that there are no misunderstandings ?
-
Need help with SQL Query (query for certain IDs in a table and then IDs not in result set)
OK. This is hard to explain but that may be my problem in constructing the query.
I have a table that has a list of jobs. The jobs information in this table, among other things, is a short description of the job itself (think "title" in phrase form), date, and ID.
So I can query the table to get all the jobs for a particular grouping of IDs (the only ones I am interested in) that ran successfully for a given time period. But what I want are all the jobs that did not succeed (or therefore are not present in the table) for this group of jobs and for a certain date range. But these are not the only job id's in the table.
To get the successful ones I do the following:
SELECT id,short_desc FROM my_table where
id IN('1230', '1231', '1232', '1239', '1244', '1245',
'1246', '1247', '1248', '1272', '1280', '1281', '1282',
'1283', '1284', '1285', '1286', '1249', '1250', '1251',
'1252', '1253', '1255', '1233', '1234', '1235', '1236',
'1237', '1238', '1256', '1257','1258', '1254', '1290','1310')
AND the_date > = SYSDATE - 23/24
AND to_char(the_date, 'DD-MON-YYYY') = TO_CHAR(CURRENT_DATE, 'DD-MON-YYYY')
I have tried to use another AND clause with NOT IN and the group or NOT EXISTS but that doesn't work as there are other jobs captured in this table with id's of course. I am only concerned with these id's:
IN('1230', '1231', '1232', '1239', '1244', '1245',
'1246', '1247', '1248', '1272', '1280', '1281', '1282',
'1283', '1284', '1285', '1286', '1249', '1250', '1251',
'1252', '1253', '1255', '1233', '1234', '1235', '1236',
'1237', '1238', '1256', '1257','1258', '1254', '1290','1310')
Someone said to use a temp table. I don't think I have permission and I haven't tried as I want to do this in one query if possible.
After thinking about this I am at a loss. I tried to do this in the front end but it just became too messy.You do not need a physical temp table. You need an in-line view:
WITH list as (
SELECT '1230' id FROM DUAL UNION ALL
SELECT '1231' FROM DUAL UNION ALL
SELECT '1232' FROM DUAL UNION ALL
SELECT '1239' FROM DUAL UNION ALL
SELECT '1244' FROM DUAL UNION ALL
SELECT '1245' FROM DUAL UNION ALL
SELECT '1246' FROM DUAL UNION ALL
SELECT '1247' FROM DUAL UNION ALL
SELECT '1248' FROM DUAL UNION ALL
SELECT '1272' FROM DUAL UNION ALL
SELECT '1280' FROM DUAL UNION ALL
SELECT '1281' FROM DUAL UNION ALL
SELECT '1282' FROM DUAL UNION ALL
SELECT '1283' FROM DUAL UNION ALL
SELECT '1284' FROM DUAL UNION ALL
SELECT '1285' FROM DUAL UNION ALL
SELECT '1286' FROM DUAL UNION ALL
SELECT '1249' FROM DUAL UNION ALL
SELECT '1250' FROM DUAL UNION ALL
SELECT '1251' FROM DUAL UNION ALL
SELECT '1252' FROM DUAL UNION ALL
SELECT '1253' FROM DUAL UNION ALL
SELECT '1255' FROM DUAL UNION ALL
SELECT '1233' FROM DUAL UNION ALL
SELECT '1234' FROM DUAL UNION ALL
SELECT '1235' FROM DUAL UNION ALL
SELECT '1236' FROM DUAL UNION ALL
SELECT '1237' FROM DUAL UNION ALL
SELECT '1238' FROM DUAL UNION ALL
SELECT '1256' FROM DUAL UNION ALL
SELECT '1257' FROM DUAL UNION ALL
SELECT '1258' FROM DUAL UNION ALL
SELECT '1254' FROM DUAL UNION ALL
SELECT '1290' FROM DUAL UNION ALL
SELECT '1310' FROM DUAL
SELECT l.id,
nvl(short_desc,'This job failed') short_desc
FROM my_table m
WHERE RIGTH JOIN
list
ON (
m.id = l.id
AND
the_date > = SYSDATE - 23/24
AND
the_date < TRUNC(SYSDATE) + 1
SY. -
with t1 as
select 1406 cid, 21 nid, 121 loc, 'Page' attrib from dual
union all
select 1406, 21, 122, 'Page' from dual
union all
select 1406, 21, 123, 'Page' from dual
union all
select 1406, 21, 124, 'Page' from dual
union all
select 1406, 21, 125, 'Page' from dual
union all
select 1406, 24, 121, 'Page' from dual
union all
select 1406, 24, 121, 'Sizzler' from dual
union all
select 1407 cid, 25 nid, 121 loc, 'Page' attrib from dual
union all
select 1407, 25, 122, 'Page' from dual
union all
select 1407, 25, 123, 'Page' from dual
union all
select 1407, 25, 124, 'Page' from dual
union all
select 1407, 25, 125, 'Page' from dual
union all
select 1407, 20, 121, 'Page' from dual
union all
select 1407, 20, 121, 'Sizzler' from dual
Select * from t1;
Expected output :
1406 125 21 Page 1
1406 124 21 Page 1
1406 123 21 Page 1
1406 122 21 Page 1
1406 121 24 Page 1
1406 121 24 Sizzler 1
1407 121 20 Page 1
1407 121 20 Sizzler 1
1407 122 25 Page 1
1407 123 25 Page 1
1407 125 25 Page 1
1407 124 25 Page 1
I have written below query
For this quuery when order by is asc, am getting correct data set for 1407 and for 1406 expected result set is not comming
select cid,loc, nid, attrib, dense_rank() over (partition by cid, loc order by nid) from t1 order by cid, nid, attrib;
For this quuery when order by is asc, am getting correct data set for 1406 and for 1407 expected result set is not comming
select cid,loc, nid, attrib, dense_rank() over (partition by cid, loc order by nid desc) from t1 order by cid, nid, attrib;
Requirement
For the same cid, loc and attrib I want to show the record which is having different nodekey id
for example, for the same 1406, 121, Page I have two records with different nid 21 and 24 (as there are more number of rows with 21, I need in the output of a record with 24 instead of 21 and remaining should be same.
adv thx for your help
version : 11gr2Like this?
SQL> with ranked as
2 (
3 select cid,loc,nid,attrib,
4 row_number()
5 over(partition by cid,loc,attrib
6 order by cnt ) rn
7 from
8 (
9 select cid,nid,loc,attrib,
10 count(*) over(partition by nid) cnt
11 from t1
12 )
13 )
14 select cid,loc,nid,attrib,rn
15 from ranked
16 where rn= 1
17 order by cid,nid,loc desc;
CID LOC NID ATTRIB RN
1406 125 21 Page 1
1406 124 21 Page 1
1406 123 21 Page 1
1406 122 21 Page 1
1406 121 24 Sizzler 1
1406 121 24 Page 1
1407 121 20 Page 1
1407 121 20 Sizzler 1
1407 125 25 Page 1
1407 124 25 Page 1
1407 123 25 Page 1
1407 122 25 Page 1
12 rows selected.Edited by: jeneesh on Mar 14, 2013 1:16 PM
ORDER BY added -
Need Help With Java Query String
I'm new to Java and I'm passing data via a URL to another page(I'm not using a form). I have been succesfull in decoding the string to return the name value below:
<SCRIPT LANGUAGE="JavaScript">
function decodeSearchString() {
var nameValue = new Array();
var searchStr = unescape(location.search.substring(1));
if (searchStr) {
var formElement = searchStr.split("&");
var tmpArray = new Array();
for (k = 0; k < formElement.length; k++) {
tmpArray = formElement[k].split("=");
nameValue[tmpArray[0]] = tmpArray[1];
return nameValue
var srchData = decodeSearchString();
</SCRIPT>
However, now I need to add the value returned from the above srcipt to the Java script listed below:
<SCRIPT Language="Javascript" SRC="#srchData.link#?open&pID=PAR"> </SCRIPT>
This above script if working will add the HTML from the URL query to the page, but I keep getting a Java Error with this script. Please Help !I assume you are using a JSP page and not just solely doing Javascript. IF you are using JSP, then read on. Otherwise, I can revisit your script.
To obtain the value of the query string, you would use a method call such as:
String strQuery = request.getQueryString()
Or, to get a single parameter off the query string, you can call:
String strSearchData = request.getParameter("paramname");
Or, if you want all the parameters and values instead of just one long string you can call:
Enumeration enumParamNames = request.getParameterNames();
You can use the above enumeration in combination with getParameter() to get the values.
In order to build your script line and add the query string, you would then do something like this:
<SCRIPT Language="Javascript" SRC="#<%=strSearchData%>.link#?open&pID=PAR"> </SCRIPT>
Notice the <%= %> block in the above code.
I hope that is what you were looking for. Your example is somewhat confusing so I may have answered wrong.
Mike -
Need help with comparing Query data
See Attached query
I need to only show Sales Employee Name that does NOT match Email
Example: Sales Employee Name KSLM-130
E-Mail does NOT start with the same KSLM-130 @ XXX.com
In other words need to report on unmatched Sales Employee Name to Email Name.
Thank you!Hi!
Try this. It might work for you.
SELECT
T0.[CardCode], T0.[CardName], T2.[SlpCode], T1.[Name], T1.[E_MailL], T2.[SlpName]
FROM OCRD T0
INNER JOIN OCPR T1 ON T0.CardCode = T1.CardCode
INNER JOIN OSLP T2 ON T0.SlpCode = T2.SlpCode
WHERE LEFT(T1.[E_MailL],LEN(T2.[SlpName])) <> T2.[SlpName]
Regards,
Maybe you are looking for
-
Mac OS 10.4.8 - 10..4.10 crash apps on print
The second time I print from an application (without shutting it down) inevitably causes a crash. Can anyone figure out what this message from Console means: CFPropertyListCreateFromXMLData(): Old-style plist parser: missing semicolon in dictionary.
-
Solaris 10/08 LUCREATE fails to exclude directories
OK: I am trying to exclude the /usr1 filesystem when I create a new boot environment: Here is what I have tried so far without any luck: lucreate -c S1008-orig -m /:c0t0d0s7:ufs -z /tmp/exclude -n S10NEW09 /tmp/exclude x /usr1 lucreate -c S1008-orig
-
Url Type Field in List - Visualization
Hi, I have a sharepoint list with a url type field. The field is displayed has a link but with the whole url string visible. How can I control the "link" text like its done on a gridview where I can choose the field for text and field for the link? i
-
HELP, NEW TO LOGIC PRO X, HOW DO I USE THIS THING???!
I just downloaded Logic Pro X, thanks to the update of Mavericks disabling my ProTools which I've been using for 4 yrs. So I dont even really know where to go from there as far as Protools. Anyway, I downloaded Logic Pro X, so how do I record on it,
-
Finder and header bar icons disappear
Hello everyone, Some icons disappear from my header bar and the finder, please see the screenshot: MacOS: Version 10.8.4 Short before that happen, my disk was full and I removed some video/music in order to get some free space again. I don't know if