11g pivot query syntax question
I searched the forums and I have seen questions similiar to the one I am asking, but its not the exact same issue.
I need 3 fields in my 'for' clause. I get 'column ambiguously defined. I think I get this error for a different reason that other people asking the question.
The others seem to be doing more than 1 function in the pivot clause and those need an alias. I give an alias with my 1 function and still get an error.
ORA-00918: column ambiguously defined
I used aliases like the recommendation in other posts and I still get the same error. I think I need 3 columns in the for clause.
--note that this is just a test table. These are not real names going into production
create table pivot_tab (
pk1 number,
pk2 number,
myElement varchar2(30),
myElementDate date);
pk1,pk2 are the unique key.
I need this to return as: the vlaues after pk2, can be any alias. This is just an example.
pk1 pk2 MY1_DATE, MY2_DATE, MY3_DATE
select *
from pivot_tab
PIVOT ( max(myElementDate) for myElement
in (''MY1','MY2','MY3'))
I saw a couple of references to this syntax, but I get syntax errors.
ora--00906: missing parentheses. So I dont think this syntax works.
select *
from pivot_tab
PIVOT ( max(myElementDate) for (pk1,pk2,myElement)
in (''MY1','MY2','MY3'))Edited by: Guess2 on May 6, 2013 6:50 AM
don't have any sample data or expected results to test this with maybe
SELECT *
FROM (SELECT pk1,
pk2,
myelement,
myelementdate
FROM pivot_tab) PIVOT (MAX (myElementDate)
FOR myElement
IN ('MY1' AS MY1, 'MY2' AS MY2, 'MY3' AS MY3));or maybe you are trying to pivot by the first part of the pk?
with pivot_tab as (select 1 pk1, 2 pk2, 'MY1' myelement, sysdate myelementdate from dual union all
select 1 pk1, 3 pk2, 'MY2' myelement, add_months(sysdate,2) myelementdate from dual union all
select 1 pk1, 4 pk2, 'MY3' myelement, add_months(sysdate,3) myelementdate from dual union all
select 2 pk1, 5 pk2, 'MY1' myelement, sysdate myelementdate from dual union all
select 2 pk1, 6 pk2, 'MY2' myelement, add_months(sysdate,6) myelementdate from dual union all
select 2 pk1, 7 pk2, 'MY3' myelement, add_months(sysdate,7) myelementdate from dual )
SELECT *
FROM (SELECT pk1,
myelement,
myelementdate
FROM pivot_tab) PIVOT (MAX (myElementDate)
FOR myElement
IN ('MY1' AS MY1, 'MY2' AS MY2, 'MY3' AS MY3));
PK1 MY1 MY2 MY3
1 5/6/2013 10:07:40 AM 7/6/2013 10:07:40 AM 8/6/2013 10:07:40 AM
2 5/6/2013 10:07:40 AM 11/6/2013 10:07:40 AM 12/6/2013 10:07:40 AMEdited by: pollywog on May 6, 2013 10:08 AM
Similar Messages
-
11G Pivot Query with Oracle EBS
Hello all,
We are trying to use the 11G pivot query function with data from Oracle E-Business Suite. We have an 11G database installed with our Oracle APEX. We cannot seem to get the pivot function to work. At a glance, would anyone be able to see any glaring errors in our syntax. I am not certain it is possible to provide test data so...
We are trying to have column headings with the Period Names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as the dataset.
When we run the sql we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or insight would be greatly appreciated.
select * from (
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751')
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
group by segment2, period_namelilhelp wrote:
Hello all,
We are trying to use the 11G pivot query function with data from Oracle E-Business Suite. We have an 11G database installed with our Oracle APEX. We cannot seem to get the pivot function to work. At a glance, would anyone be able to see any glaring errors in our syntax. I am not certain it is possible to provide test data Why not?
>
We are trying to have column headings with the Period Names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as the dataset.
When we run the sql we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or insight would be greatly appreciated.
select * from (
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751')
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
group by segment2, period_nameDon't use GROUP BY. When you use PIVOT, the grouping is implied by what is in the PIVOT clause and what is not.
Try this:
select *
from (
select segment2
, accounted_dr
, period_name
from gl_je_lines a
, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751'
pivot (
sum (accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
;which is just your posted query without the GROUP BY clause. -
11G Pivot Query with parameters
Hello all,
I would like to find some way, any way to pass parameters to a pivot query. The following pivot query works, but I would like segment2 to be a variable as well as the period names so....
select * from
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 >='007611' and segment2 <='007751' AND period_name in ('SEP-08','OCT-08','NOV-08'))
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08') )
....would be something like....
select * from
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 >= :P4_OBJECT_FROM AND and segment2 <=:P4_OBJECT_TO AND period_name in &P4_EPSB_PERIOD_HOLD.)
pivot
sum(accounted_dr)
for period_name in (&P4_EPSB_PERIOD_HOLD.) )
It is our understanding that we have to hardcode period names and objects, but we would like to get around that. Does anyone have any ideas or tricks?
Thankslilhelp wrote:
Hello all,
We are trying to use the 11G pivot query function with data from Oracle E-Business Suite. We have an 11G database installed with our Oracle APEX. We cannot seem to get the pivot function to work. At a glance, would anyone be able to see any glaring errors in our syntax. I am not certain it is possible to provide test data Why not?
>
We are trying to have column headings with the Period Names SEP-08 OCT-08 NOV-08, with rows of segment2 007751 and accounted_dr as the dataset.
When we run the sql we get an error ORA-00904: "PERIOD_NAME": invalid identifier.
Any help or insight would be greatly appreciated.
select * from (
select segment2, accounted_dr, period_name
from gl_je_lines a, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751')
pivot
sum(accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
group by segment2, period_nameDon't use GROUP BY. When you use PIVOT, the grouping is implied by what is in the PIVOT clause and what is not.
Try this:
select *
from (
select segment2
, accounted_dr
, period_name
from gl_je_lines a
, gl_code_combinations b
where b.code_combination_id = a.code_combination_id
and segment2 = '007751'
pivot (
sum (accounted_dr)
for period_name in ('SEP-08','OCT-08','NOV-08')
;which is just your posted query without the GROUP BY clause. -
Using multiple 'for' statements in an 11g pivot query
oracle: 11.2.0.3
Basically I need to pivot around 2 different columns (I think I need to 'for' clauses').
See below.
Below is pseudo code from non-11g pivot statement.
I am trying to figure out how to do with pivot.
-- note field names are pseudo code and not real values
-- note that the field after 'then' in the case statement is different for the 2 pivots
select my_id,
max( (case when myfield = 'MYVALUE1' then mydate_date else null end)) as MYVALUE1,
to_number(max( (case when myfield = 'MYVALUE' then myfieldvalue else null end))) as MYVALUE2,
min (insert_date ) insert_date
from mytable
group by myidso if I'm doing this in 11g pivot syntax I am stuck at:
-- if I add max(fieldvalue), I think I will pivot too many times. I just want 2 extra columns. Can I add a second 'for' statement?
select *
from mytable
pivot (
max(mydate)
for myfield in ('MYVALUE1' as MYVALUE1)
)My concern about trying that is that SQL will do extra pivots that I won't use. Which means more work. I saw a blog entry by someone in the oak table (I can't remember who or the link) that showed an example that the pivot clause has about the same logical IOs as using the old max(case statement) but the response time was much better. This was a very rare case where performance is significantly improved without affecting LIOs. So there isn't a good measure. I wish I had the link and generally people in the oak table are very good. So I trust posts by them.
so basically I am not sure how to measure whether doing the extra pivots are using extra resources. This is going to be a fairly performance intensive query due to the volume of data it has to feed through.
I'll give it a try, but my inability to measure it is a bit concerning. -
11g SQL query syntax/results differ from 10g
Hello,
A bit of an odd situation. We have a report in 10g that is working as expected and when we run the same report in 11g we slightly different results. The same physical tables and columns are being used between each report and the number of records (17) returned to OBI are the same. Both queries are pulling from the same database with the same user id. As there are differences in how 10g runs queries vs 11g, are there any odd behaviors that I should keep an eye out for in how 11g assembles the data that's returned from the db prior to presenting it on the Analysis?
10g Results (correct):
Region...............Actuals (Prior Qtr).....Up...........Plan Amount....................% of Plan
AP...........................10,489..............8,965..............................................................
Americas................114,208...........110,779..................6...........................1969411%
EMEA.....................26,799..............23,976..............................................................
UNASSIGNED....................................................149,957...........................0%
Grand Total.............151,496...........143,721..........149,962.........................96%
11g Results (incorrect):
Region...............Actuals (Prior Qtr).....Up...........Plan Amount....................% of Plan
AP...........................10,180..............8,965............................................................
Americas.................90,878...........110,779............................................................
EMEA.....................24,978.............23,976............................................................
UNASSIGNED....................................................149,957...........................0%
Grand Total.............126,037..........143,721..........149,957.........................96%
Thank you!
Mike
-------------------- 10g query--------------------------
-------------------- Sending query to database named EBS Rapid Data Store (id: <<5087545>>):
WITH
SAWITH0 AS (select T28761.PERIOD_NAME as c2,
T28761.PERIOD_START_DATE as c3,
T28761.QUARTER_RANK as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH1 AS (select Case when case SAWITH0.c5 when 1 then SAWITH0.c3 else NULL end is not null then Rank() OVER ( ORDER BY case SAWITH0.c5 when 1 then SAWITH0.c3 else NULL end ASC NULLS LAST ) end as c1,
SAWITH0.c2 as c2,
SAWITH0.c4 as c3
from
SAWITH0),
SAWITH2 AS (select min(SAWITH1.c1) over (partition by SAWITH1.c3) as c1,
SAWITH1.c2 as c2
from
SAWITH1),
SAWITH3 AS (select distinct SAWITH2.c1 + 1 as c1,
SAWITH2.c2 as c2
from
SAWITH2),
SAWITH4 AS (select T28761.QUARTER_RANK as c2,
T28761.QUARTER_YEAR_NAME as c3,
T28761.PERIOD_START_DATE as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH5 AS (select Case when case SAWITH4.c5 when 1 then SAWITH4.c4 else NULL end is not null then Rank() OVER ( ORDER BY case SAWITH4.c5 when 1 then SAWITH4.c4 else NULL end ASC NULLS LAST ) end as c1,
SAWITH4.c2 as c2,
SAWITH4.c3 as c3
from
SAWITH4),
SAWITH6 AS (select distinct min(SAWITH5.c1) over (partition by SAWITH5.c2) as c1,
SAWITH5.c2 as c2,
SAWITH5.c3 as c3
from
SAWITH5),
SAWITH7 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6
from
(select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
SAWITH6.c3 as c2,
T41894.ICN_GROUP as c3,
SAWITH6.c2 as c4,
T41894.ICN_GROUP_CODE as c5,
T30728.PARENT_REGION as c6,
ROW_NUMBER() OVER (PARTITION BY T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, SAWITH6.c2 ORDER BY T30728.PARENT_REGION ASC, T41894.ICN_GROUP_CODE ASC, SAWITH6.c2 ASC) as c7
from
SAWITH3 left outer join (
XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */ On T37838.OVERRIDE_ICN = T41894.ICN_CODE) On SAWITH3.c2 = T37838.PERIOD_NAME,
SAWITH6
where ( SAWITH6.c1 = SAWITH3.c1 and SAWITH6.c3 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
group by T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP, SAWITH6.c2, SAWITH6.c3
) D1
where ( D1.c7 = 1 ) ),
SAWITH8 AS (select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c2,
T30728.PARENT_REGION as c3,
T28761.QUARTER_YEAR_NAME as c6,
T41894.ICN_GROUP as c7,
T28761.QUARTER_RANK as c8,
T41894.ICN_GROUP_CODE as c9
from
XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ left outer join
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ On T28761.PERIOD_NAME = T37838.PERIOD_NAME) left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */ On T37838.OVERRIDE_ICN = T41894.ICN_CODE
where ( T28761.QUARTER_YEAR_NAME = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
SAWITH9 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9
from
(select sum(SAWITH8.c1) over (partition by SAWITH8.c3) as c1,
sum(SAWITH8.c2) over (partition by SAWITH8.c3) as c2,
SAWITH8.c3 as c3,
sum(SAWITH8.c1) over (partition by SAWITH8.c8, SAWITH8.c9, SAWITH8.c3) as c4,
sum(SAWITH8.c2) over (partition by SAWITH8.c8, SAWITH8.c9, SAWITH8.c3) as c5,
SAWITH8.c6 as c6,
SAWITH8.c7 as c7,
SAWITH8.c8 as c8,
SAWITH8.c9 as c9,
ROW_NUMBER() OVER (PARTITION BY SAWITH8.c3, SAWITH8.c8, SAWITH8.c9 ORDER BY SAWITH8.c3 ASC, SAWITH8.c8 ASC, SAWITH8.c9 ASC) as c10
from
SAWITH8
) D1
where ( D1.c10 = 1 ) ),
SAWITH10 AS (select sum(T34877.AMOUNT) as c1,
T28761.QUARTER_YEAR_NAME as c3,
T30728.PARENT_REGION as c4,
T41894.ICN_GROUP as c5,
T28761.QUARTER_RANK as c6,
T41894.ICN_GROUP_CODE as c7
from
XXFI.XXFI_REVENUE_BUDGET_ACCUM T34877 /* Fact_Revenue_Budgets */ left outer join
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ On T28761.PERIOD_NAME = T34877.PERIOD_NAME) left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T34877.SHIP_TO_COUNTRY_CODE2) left outer join
XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */ On T34877.OVERRIDE_ICN = T41894.ICN_CODE
where ( T28761.QUARTER_YEAR_NAME = '2010-Q2' )
group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
SAWITH11 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7
from
(select sum(SAWITH10.c1) over (partition by SAWITH10.c4) as c1,
sum(SAWITH10.c1) over (partition by SAWITH10.c6, SAWITH10.c7, SAWITH10.c4) as c2,
SAWITH10.c3 as c3,
SAWITH10.c4 as c4,
SAWITH10.c5 as c5,
SAWITH10.c6 as c6,
SAWITH10.c7 as c7,
ROW_NUMBER() OVER (PARTITION BY SAWITH10.c4, SAWITH10.c6, SAWITH10.c7 ORDER BY SAWITH10.c4 ASC, SAWITH10.c6 ASC, SAWITH10.c7 ASC) as c8
from
SAWITH10
) D1
where ( D1.c8 = 1 ) ),
SAWITH12 AS (select T28761.PERIOD_NAME as c2,
T28761.PERIOD_START_DATE as c3,
T28761.QUARTER_RANK as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH13 AS (select Case when case SAWITH12.c5 when 1 then SAWITH12.c3 else NULL end is not null then Rank() OVER ( ORDER BY case SAWITH12.c5 when 1 then SAWITH12.c3 else NULL end ASC NULLS LAST ) end as c1,
SAWITH12.c2 as c2,
SAWITH12.c4 as c3
from
SAWITH12),
SAWITH14 AS (select min(SAWITH13.c1) over (partition by SAWITH13.c3) as c1,
SAWITH13.c2 as c2
from
SAWITH13),
SAWITH15 AS (select distinct SAWITH14.c1 + 1 as c1,
SAWITH14.c2 as c2
from
SAWITH14),
SAWITH16 AS (select T28761.QUARTER_YEAR_NAME as c2,
T28761.PERIOD_START_DATE as c3,
T28761.QUARTER_RANK as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH17 AS (select Case when case SAWITH16.c5 when 1 then SAWITH16.c3 else NULL end is not null then Rank() OVER ( ORDER BY case SAWITH16.c5 when 1 then SAWITH16.c3 else NULL end ASC NULLS LAST ) end as c1,
SAWITH16.c2 as c2,
SAWITH16.c4 as c3
from
SAWITH16),
SAWITH18 AS (select distinct min(SAWITH17.c1) over (partition by SAWITH17.c3) as c1,
SAWITH17.c2 as c2
from
SAWITH17),
SAWITH19 AS (select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
T30728.PARENT_REGION as c2
from
SAWITH15 left outer join (
XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) On SAWITH15.c2 = T37838.PERIOD_NAME,
SAWITH18
where ( SAWITH18.c1 = SAWITH15.c1 and SAWITH18.c2 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
group by T30728.PARENT_REGION),
SAWITH20 AS (select T28761.PERIOD_NAME as c2,
T28761.PERIOD_START_DATE as c3,
T28761.QUARTER_RANK as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH21 AS (select Case when case SAWITH20.c5 when 1 then SAWITH20.c3 else NULL end is not null then Rank() OVER ( ORDER BY case SAWITH20.c5 when 1 then SAWITH20.c3 else NULL end ASC NULLS LAST ) end as c1,
SAWITH20.c2 as c2,
SAWITH20.c4 as c3
from
SAWITH20),
SAWITH22 AS (select min(SAWITH21.c1) over (partition by SAWITH21.c3) as c1,
SAWITH21.c2 as c2
from
SAWITH21),
SAWITH23 AS (select distinct SAWITH22.c1 + 1 as c1,
SAWITH22.c2 as c2
from
SAWITH22),
SAWITH24 AS (select T28761.QUARTER_YEAR_NAME as c2,
T28761.PERIOD_START_DATE as c3,
T28761.QUARTER_RANK as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH25 AS (select Case when case SAWITH24.c5 when 1 then SAWITH24.c3 else NULL end is not null then Rank() OVER ( ORDER BY case SAWITH24.c5 when 1 then SAWITH24.c3 else NULL end ASC NULLS LAST ) end as c1,
SAWITH24.c2 as c2,
SAWITH24.c4 as c3
from
SAWITH24),
SAWITH26 AS (select distinct min(SAWITH25.c1) over (partition by SAWITH25.c3) as c1,
SAWITH25.c2 as c2
from
SAWITH25),
SAWITH27 AS (select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1
from
SAWITH23 left outer join XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ On SAWITH23.c2 = T37838.PERIOD_NAME,
SAWITH26
where ( SAWITH26.c1 = SAWITH23.c1 and SAWITH26.c2 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') ) ),
SAWITH28 AS (select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c2
from
XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ left outer join
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ On T28761.PERIOD_NAME = T37838.PERIOD_NAME
where ( T28761.QUARTER_YEAR_NAME = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') ) ),
SAWITH29 AS (select sum(T34877.AMOUNT) as c1
from
XXFI.XXFI_REVENUE_BUDGET_ACCUM T34877 /* Fact_Revenue_Budgets */ left outer join
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ On T28761.PERIOD_NAME = T34877.PERIOD_NAME
where ( T28761.QUARTER_YEAR_NAME = '2010-Q2' ) )
select case when SAWITH7.c2 is not null then SAWITH7.c2 when SAWITH9.c6 is not null then SAWITH9.c6 when SAWITH11.c3 is not null then SAWITH11.c3 end as c1,
case when SAWITH9.c3 is not null then SAWITH9.c3 when SAWITH19.c2 is not null then SAWITH19.c2 when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH11.c4 is not null then SAWITH11.c4 end as c2,
case when SAWITH7.c3 is not null then SAWITH7.c3 when SAWITH9.c7 is not null then SAWITH9.c7 when SAWITH11.c5 is not null then SAWITH11.c5 end as c3,
SAWITH9.c5 / nullif( 1000, 0) as c4,
SAWITH7.c1 / nullif( 1000, 0) as c5,
SAWITH11.c2 / nullif( 1000, 0) as c6,
nvl(SAWITH9.c4 , 0) / nullif( nvl(SAWITH11.c2 , 0), 0) * 100 as c7,
case when SAWITH7.c4 is not null then SAWITH7.c4 when SAWITH9.c8 is not null then SAWITH9.c8 when SAWITH11.c6 is not null then SAWITH11.c6 end as c16,
case when SAWITH11.c7 is not null then SAWITH11.c7 when SAWITH9.c9 is not null then SAWITH9.c9 when SAWITH7.c5 is not null then SAWITH7.c5 end as c17,
SAWITH27.c1 as c19,
SAWITH28.c2 as c20,
SAWITH29.c1 as c21,
SAWITH28.c1 as c22,
SAWITH19.c1 as c23,
SAWITH9.c2 as c24,
SAWITH11.c1 as c25,
SAWITH9.c1 as c26
from
SAWITH7 full outer join SAWITH9 On SAWITH7.c5 = SAWITH9.c9 and nvl(SAWITH7.c4 , 88.0) = nvl(SAWITH9.c8 , 88.0) and nvl(SAWITH7.c4 , 99.0) = nvl(SAWITH9.c8 , 99.0) and nvl(SAWITH7.c6 , 'q') = nvl(SAWITH9.c3 , 'q') and nvl(SAWITH7.c6 , 'z') = nvl(SAWITH9.c3 , 'z')) full outer join SAWITH11 On SAWITH11.c7 = case when SAWITH7.c5 is not null then SAWITH7.c5 when SAWITH9.c9 is not null then SAWITH9.c9 end and nvl(SAWITH11.c4 , 'q') = nvl(case when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 end , 'q') and nvl(SAWITH11.c4 , 'z') = nvl(case when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 end , 'z') and nvl(SAWITH11.c6 , 88.0) = nvl(case when SAWITH7.c4 is not null then SAWITH7.c4 when SAWITH9.c8 is not null then SAWITH9.c8 end , 88.0) and nvl(SAWITH11.c6 , 99.0) = nvl(case when SAWITH7.c4 is not null then SAWITH7.c4 when SAWITH9.c8 is not null then SAWITH9.c8 end , 99.0)) full outer join SAWITH19 On nvl(SAWITH19.c2 , 'q') = nvl(case when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 when SAWITH11.c4 is not null then SAWITH11.c4 end , 'q') and nvl(SAWITH19.c2 , 'z') = nvl(case when SAWITH7.c6 is not null then SAWITH7.c6 when SAWITH9.c3 is not null then SAWITH9.c3 when SAWITH11.c4 is not null then SAWITH11.c4 end , 'z'),
SAWITH27,
SAWITH28,
SAWITH29
order by c2
+++:cfa20000:cfa20015:----2013/08/14 10:31:12
-------------------- Query Status: Successful Completion
+++:cfa20000:cfa20015:----2013/08/14 10:31:12
-------------------- Rows 21, bytes 34272 retrieved from database query id: <<5087545>>
+++:cfa20000:cfa20015:----2013/08/14 10:31:12
-------------------- Physical query response time 27 (seconds), id <<5087545>>
+++:cfa20000:cfa20015:----2013/08/14 10:31:12
-------------------- Physical Query Summary Stats: Number of physical queries 1, Cumulative time 27, DB-connect time 0 (seconds)
+++:cfa20000:cfa20015:----2013/08/14 10:31:12
-------------------- Rows returned to Client 17
--------------------------------------------- 11g Query ----------------------------------------------------------
Sending query to database named EBS Rapid Data Store (id: <<2779207>>), connection pool named EBS XXFI Connection Pool, logical request hash 1334563, physical request hash 292e1532: [[
WITH
OBICOMMON0 AS (select T28761.PERIOD_NAME as c2,
T28761.PERIOD_START_DATE as c3,
T28761.QUARTER_RANK as c4,
ROW_NUMBER() OVER (PARTITION BY T28761.QUARTER_RANK ORDER BY T28761.QUARTER_RANK DESC) as c5,
T28761.QUARTER_YEAR_NAME as c6
from
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ ),
SAWITH0 AS (select Case when case D1.c5 when 1 then D1.c3 else NULL end is not null then Rank() OVER ( ORDER BY case D1.c5 when 1 then D1.c3 else NULL end ASC NULLS LAST ) end as c1,
D1.c2 as c2,
D1.c4 as c3
from
OBICOMMON0 D1),
SAWITH1 AS (select min(D1.c1) over (partition by D1.c3) as c1,
D1.c2 as c2
from
SAWITH0 D1),
SAWITH2 AS (select distinct D1.c1 + 1 as c1,
D1.c2 as c2
from
SAWITH1 D1),
SAWITH3 AS (select Case when case D1.c5 when 1 then D1.c3 else NULL end is not null then Rank() OVER ( ORDER BY case D1.c5 when 1 then D1.c3 else NULL end ASC NULLS LAST ) end as c1,
D1.c6 as c2,
D1.c4 as c3
from
OBICOMMON0 D1),
SAWITH4 AS (select distinct min(D1.c1) over (partition by D1.c3) as c1,
D1.c2 as c2,
D1.c3 as c3
from
SAWITH3 D1),
SAWITH5 AS (select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
D4.c2 as c2,
T41894.ICN_GROUP as c3,
T30728.PARENT_REGION as c4,
D4.c3 as c5,
T41894.ICN_GROUP_CODE as c6
from
SAWITH2 D6 left outer join (
XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */ On T37838.OVERRIDE_ICN = T41894.ICN_CODE) On D6.c2 = T37838.PERIOD_NAME,
SAWITH4 D4
where ( D4.c1 = D6.c1 and D4.c2 = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
group by T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP, D4.c2, D4.c3),
SAWITH6 AS (select sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 50 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c1,
sum(case when T37838.POL_VERSION_FLAG = 'C' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 then nvl(T37838.AMOUNT , 0) when T37838.PERIOD_NAME <> 'March-13' and T37838.FORECAST_PROBABILITY_PERCENT >= 75 and T37838.POL_VERSION_FLAG is null then nvl(T37838.AMOUNT , 0) else 0 end ) as c2,
T28761.QUARTER_YEAR_NAME as c3,
T41894.ICN_GROUP as c4,
T30728.PARENT_REGION as c5,
T28761.QUARTER_RANK as c6,
T41894.ICN_GROUP_CODE as c7
from
XXFI.XXFI_REVFCST_POL_REPORTING_V T37838 /* Fact_POL_Snapshot */ left outer join
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ On T28761.PERIOD_NAME = T37838.PERIOD_NAME) left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T37838.SHIP_TO_COUNTRY_CODE2) left outer join
XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */ On T37838.OVERRIDE_ICN = T41894.ICN_CODE
where ( T28761.QUARTER_YEAR_NAME = '2010-Q2' and (T37838.PROSPECT_NUMBER is null or T37838.PROSPECT_NUMBER not like '%Budget%') )
group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
SAWITH7 AS (select sum(T34877.AMOUNT) as c1,
T28761.QUARTER_YEAR_NAME as c2,
T41894.ICN_GROUP as c3,
T30728.PARENT_REGION as c4,
T28761.QUARTER_RANK as c5,
T41894.ICN_GROUP_CODE as c6
from
XXFI.XXFI_REVENUE_BUDGET_ACCUM T34877 /* Fact_Revenue_Budgets */ left outer join
XXFI.XXFI_GL_FISCAL_MONTHS_V T28761 /* Dim_Periods */ On T28761.PERIOD_NAME = T34877.PERIOD_NAME) left outer join
XXFI.XXFI_GEO_REGION_ACCUM T30728 /* Dim_Regions */ On T30728.COUNTRY_CODE = T34877.SHIP_TO_COUNTRY_CODE2) left outer join
XXFI.XXFI_ICN_OWNERS_V T41894 /* Dim_ICN_Override */ On T34877.OVERRIDE_ICN = T41894.ICN_CODE
where ( T28761.QUARTER_YEAR_NAME = '2010-Q2' )
group by T28761.QUARTER_YEAR_NAME, T28761.QUARTER_RANK, T30728.PARENT_REGION, T41894.ICN_GROUP_CODE, T41894.ICN_GROUP),
SAWITH8 AS (select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c18 as c18,
D1.c19 as c19,
D1.c20 as c20,
D1.c21 as c21,
D1.c22 as c22
from
(select 0 as c1,
case when D1.c2 is not null then D1.c2 when D2.c3 is not null then D2.c3 when D3.c2 is not null then D3.c2 end as c2,
case when D1.c3 is not null then D1.c3 when D2.c4 is not null then D2.c4 when D3.c3 is not null then D3.c3 end as c3,
case when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 when D3.c4 is not null then D3.c4 end as c4,
case when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 when D3.c5 is not null then D3.c5 end as c5,
nvl(D2.c2 , 0) / nullif( nvl(D3.c1 , 0), 0) * 100 as c6,
D3.c1 / 1000 as c7,
D1.c1 / 1000 as c8,
D2.c1 / 1000 as c9,
case when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 when D3.c6 is not null then D3.c6 end as c18,
D2.c2 as c19,
D3.c1 as c20,
D1.c1 as c21,
D2.c1 as c22,
ROW_NUMBER() OVER (PARTITION BY case when D1.c2 is not null then D1.c2 when D2.c3 is not null then D2.c3 when D3.c2 is not null then D3.c2 end , case when D1.c3 is not null then D1.c3 when D2.c4 is not null then D2.c4 when D3.c3 is not null then D3.c3 end , case when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 when D3.c4 is not null then D3.c4 end , case when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 when D3.c5 is not null then D3.c5 end , case when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 when D3.c6 is not null then D3.c6 end ORDER BY case when D1.c2 is not null then D1.c2 when D2.c3 is not null then D2.c3 when D3.c2 is not null then D3.c2 end ASC, case when D1.c3 is not null then D1.c3 when D2.c4 is not null then D2.c4 when D3.c3 is not null then D3.c3 end ASC, case when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 when D3.c4 is not null then D3.c4 end ASC, case when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 when D3.c5 is not null then D3.c5 end ASC, case when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 when D3.c6 is not null then D3.c6 end ASC) as c23
from
SAWITH5 D1 full outer join SAWITH6 D2 On D1.c6 = D2.c7 and SYS_OP_MAP_NONNULL(D1.c4) = SYS_OP_MAP_NONNULL(D2.c5) and SYS_OP_MAP_NONNULL(D1.c5) = SYS_OP_MAP_NONNULL(D2.c6) ) full outer join SAWITH7 D3 On D3.c6 = case when D1.c6 is not null then D1.c6 when D2.c7 is not null then D2.c7 end and SYS_OP_MAP_NONNULL(D3.c4) = SYS_OP_MAP_NONNULL(case when D1.c4 is not null then D1.c4 when D2.c5 is not null then D2.c5 end ) and SYS_OP_MAP_NONNULL(D3.c5) = SYS_OP_MAP_NONNULL(case when D1.c5 is not null then D1.c5 when D2.c6 is not null then D2.c6 end )
) D1
where ( D1.c23 = 1 ) )
select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c18 as c19,
D1.c19 as c21,
D1.c20 as c22,
D1.c21 as c23,
D1.c22 as c24
from
SAWITH8 D1
order by c4, c2, c5, c19, c3
[2013-08-14T10:38:15.000-05:00] [OracleBIServerComponent] [TRACE:2] [USER-34] [] [ecid: 54a0696aeaefab88:-d74da91:1406506ef2a:-8000-00000000000151e6,0:1:9:6:1] [tid: a093e700] [requestid: cc480014] [sessionid: cc480000] [username: ] -------------------- Query Status: Successful Completion [[
[2013-08-14T10:38:15.000-05:00] [OracleBIServerComponent] [TRACE:2] [USER-26] [] [ecid: 54a0696aeaefab88:-d74da91:1406506ef2a:-8000-00000000000151e6,0:1:9:6:1] [tid: a093e700] [requestid: cc480014] [sessionid: cc480000] [username: ] -------------------- Rows 17, bytes 27200 retrieved from database query id: <<2779207>>check the report for the columns which has incorrect values for any calculation, null handling.
also check whether there is a difference in logical SQL between 10g and 11g.
also check whether they are pointing to same db.
check for null handling or default value not being set in 11g.
try rebuilding the same report, to check the metrics individually verify they match with 10g. -
Simple database query syntax question
Hi experts,
I am just stucked here...
e.g.
String Name = "John Doe";
String query =
"select * from table where NameCol = "+Name;
ResultSet rs =stmt.executeQuery(query);
while (rs.next()) {
System.out.println(rs.getString(NameCol);
The complier complains that "Syntax error !" at
" NameCol = ....." ?!?!
Why this is happening ? What is the correct syntax ?
Thanks in advance !
Philipfinally figured it out. thanks...
-
Pl/sql function returning query - syntax question
Hi,
I'm trying to figure out the syntax for the following query:
BEGIN
RETURN 'select name from table1 where name like '%' || :p1_name';
END;
It doesn't work because of the single-quotes around the % sign, plus the quotes for the query itself. How can I handle the % sign quotes? Any suggestions would be appreciated!
Thanks,
NoraNora,
If you want to use quotes within a quoted string, you have to duplicate the quotes.
BEGIN
RETURN 'select name from table1 where name like ''%'' || :p1_name';
END;
Fred. -
Hi Folks.
Have had a read of the documentattion but maybe I'm missing something subtle.
Given the following XML (Extract)
<?xml version="1.0" ?>
- <IndividualAnnex xmlns="https://infocentre.gsm.org/TADIG-RAEX-AA14" xmlns:tadig-gen="https://infocentre.gsm.org/TADIG-GEN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://infocentre.gsm.org/TADIG-RAEX-AA14 tadig-raex-aa14-3.0.xsd">
- <ContactInformationList>
- <Contact contactInformationID="111">
- <ContactPerson>
<tadig-gen:GivenName>Joe</tadig-gen:GivenName>
<tadig-gen:FamilyName>Bloggs</tadig-gen:FamilyName>
- <tadig-gen:PhoneFixList>
<tadig-gen:PhoneFix>888888888888</tadig-gen:PhoneFix>
</tadig-gen:PhoneFixList>
- <tadig-gen:FaxList>
<tadig-gen:Fax>9999999999999</tadig-gen:Fax>
</tadig-gen:FaxList>
- <tadig-gen:EmailList>
<tadig-gen:Email>[email protected]</tadig-gen:Email>
</tadig-gen:EmailList>
</ContactPerson>
</Contact>I am issuing the following SQL but not getting any value returned.
SELECT extract(v2.individual_annex,'IndividualAnnex/ContactInformationList[Contact/@contactInformationID="111"]/ContactPerson/@GivenName')
FROM raex_annex_3_0_v2 v2
WHERE v2.agreement_id = 1What should the SQL be if, for instance I wanted to return the "GivenName" of Joe?
Any assistance greatly appreciated.
Many thanks
Kind regards
Simon GaddHi,
the following works in 11.1.0.6
SQL> with t as (select xmltype('<?xml version="1.0" ?>
2 <IndividualAnnex xmlns="https://infocentre.gsm.org/TADIG-RAEX-AA14" xmlns:tadig-gen="https://infocentre.gsm.org/TADIG-GEN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://infocentre.gsm.org/TADIG-RAEX-AA14 tadig-raex-aa14-3.0.xsd">
3 <ContactInformationList>
4 <Contact contactInformationID="111">
5 <ContactPerson>
6 <tadig-gen:GivenName>Joe</tadig-gen:GivenName>
7 <tadig-gen:FamilyName>Bloggs</tadig-gen:FamilyName>
8 <tadig-gen:PhoneFixList>
9 <tadig-gen:PhoneFix>888888888888</tadig-gen:PhoneFix>
10 </tadig-gen:PhoneFixList>
11 <tadig-gen:FaxList>
12 <tadig-gen:Fax>9999999999999</tadig-gen:Fax>
13 </tadig-gen:FaxList>
14 <tadig-gen:EmailList>
15 <tadig-gen:Email>[email protected]</tadig-gen:Email>
16 </tadig-gen:EmailList>
17 </ContactPerson>
18 </Contact></ContactInformationList></IndividualAnnex>') xcol from dual)
19 select extractValue(
20 t.xcol
21 ,'/IndividualAnnex/ContactInformationList[Contact/@contactInformationID="111"]/Contact/ContactPerson/t:GivenName'
22 ,'xmlns="https://infocentre.gsm.org/TADIG-RAEX-AA14" xmlns:t="https://infocentre.gsm.org/TADIG-GEN"')
23 from t;
EXTRACTVALUE(T.XCOL,'/INDIVIDUALANNEX/CONTACTINFORMATIONLIST[CONTACT/@CONTACTINF
JoeAnts -
Dynamic SQL and Pivot Query in 11G
Hello all,
I am using APEX and 11G I am trying to create a report based on the results of a pivot query. Below is the code to build the query string. The :P4_EPSB_PERIOD_HOLD holds data like (SEP-08') for example.
declare
q varchar2(4000);
begin
q:=q ||' select * FROM';
q:=q ||' ( ';
q:=q ||' select segment2, ';
q:=q ||' accounted_dr, ';
q:=q ||' period_name ';
q:=q ||' from gl_je_lines a, ';
q:=q ||' gl_code_combinations b';
q:=q ||' where b.code_combination_id = a.code_combination_id';
q:=q ||' and segment2 >= :P4_EPSB_OBJECT_FROM';
q:=q ||' and segment2 <= :P4_EPSB_OBJECT_TO';
q:=q ||' and period_name IN :P4_EPSB_PERIOD_HOLD';
q:=q ||' and segment4 >= :P4_EPSB_LOCATION_FROM';
q:=q ||' and segment4 <= :P4_EPSB_LOCATION_TO';
q:=q ||' )';
q:=q ||' PIVOT';
q:=q ||' (';
q:=q ||' sum(accounted_dr)';
q:=q ||' for period_name IN :P4_EPSB_PERIOD_HOLD';
q:=q ||' )';
return q;
end;
I get the missingfailed to parse SQL query:
ORA-00906: missing left parenthesis
If I print the sql statement that the query generates, I get the following code, which, if the varaibles are hard-coded, works fine.
select * FROM ( select segment2, accounted_dr, period_name from gl_je_lines a, gl_code_combinations b where b.code_combination_id = a.code_combination_id and segment2 >= :P4_EPSB_OBJECT_FROM and segment2 <= :P4_EPSB_OBJECT_TO and period_name IN :P4_EPSB_PERIOD_HOLD and segment4 >= :P4_EPSB_LOCATION_FROM and segment4 <= :P4_EPSB_LOCATION_TO ) PIVOT ( sum(accounted_dr) for period_name IN :P4_EPSB_PERIOD_HOLD )
Any advice as to how to tackle this would be most welecome and appreciated.
ThanksP4_EPSB_PERIOD_HOLDcome with single quotes? like 'SEP-08' or SEP-08
-
Question about WebLogic query syntax
Hello,
I am using WebLogic Server 6.0, which came as part of the WebGain
Studio SE 4.5 development kit. My question regards the Web Logic query
syntax, which I have not yet mastered.
I am trying to create a finder method that takes a single argument
of type "char" and finds all matching fields of the column "keyword" in
which the argument is the first letter of keyword. That is, if I were
only looking for fields beginning with the letter "M", I'd use:
(like keyword 'M%')
However, I'm looking for all fields beginning with the first letter
defined by the first argument. Sadly, this syntax:
(like keyword '$0%')
doesn't seem to be working. Any suggestions on the correct syntax?
If this is not the right forum for this question, could someone
suggest an appropriate newsgroup?
Thanks, Dave962466 wrote:
Hi all,
I have an issue I need help with. I have created a script for an automated partition create on a monthly basis. It creates a monthly partition containing all dates within the respective month. The script is essentially this:
ALTER TABLE SCHEMA.TABLE
ADD PARTITION &&1
VALUES LESS THAN (to_number(to_char(to_date('&&2', 'DD-MON-YY'), 'YYYYMMDD')))
TABLESPACE LARGE_DATA94 COMPRESS;
I continually get this error message "ORA-14019: partition bound element must be one of: string, datetime or interval literal, number, or MAXVALUE"
The variable &&2 is passing in character data for the first of the month (E.G. '01-SEP-12'). &&1 passes character data for the month in MONYY (AUG12) I can run this query:
select
(to_number(to_char(to_date('&&2', 'DD-MON-YY'), 'YYYYMMDD')))
from dual;
With the output of 20120801. I cannot understand why I am able to run this partition create statement by hardcoding 20120901 but passing it in as a variable I receive the error. Note that I am not having problems with the &&1 variable. If anyone has any ideas please let me know. Thanks!I don't understand why you are taking a string, converting it to a date, then converting the date BACK TO a string ... then trying to convert that string to a number.
What is the data type of the partitioning key? It appears that it is a NUMBER, but actually represents a DATE. If so, that is a fundamentally flawed design. -
Hello,
I have a single row of data showing school term start and end dates in 2011/12. I need to convert this single row of data (containing 16 columns) into 5 rows comprised of just 4 columns (year, term, term_start, term_end).
Is it possible to use just Oracle 11g's unpivot function_ to convert the following 16 columns of data:
select * from
(select 2012 as terms_year,
1 as T1,'05-SEP-2011' as T1_SD, '21-OCT-2011' as T1_ED,
2 as T2,'31-OCT-2011' as T2_SD, '16-DEC-2011' as T2_ED,
3 as T3,'03-JAN-2012' as T3_SD, '10-FEB-2012' as T3_ED,
4 as T4,'20-FEB-2012' as T4_SD, '30-APR-2012' as T4_ED,
5 as T5,'16-APR-2012' as T5_SD, '01-JUN-2012' as T5_ED
from dual) mytable
aka
TERMS_YEAR T1 T1_SD T1_ED T2 T2_SD T2_ED T3 T3_SD T3_ED T4 T4_SD T4_ED T5 T5_SD T5_ED
2012 1 05-SEP-2011 21-OCT-2011 2 31-OCT-2011 16-DEC-2011 3 03-JAN-2012 10-FEB-2012 4 20-FEB-2012 30-APR-2012 5 16-APR-2012 01-JUN-2012 into the following 4 columns of data (year, term, term_start, term_end):
select terms_year, term, t1_sd as term_start, t1_ed as term_end from
(select 2012 as terms_year, 1 as term, '05-SEP-2011' as T1_SD, '21-OCT-2011' as T1_ED from dual union all
select 2012 as terms_year, 2 as term, '31-OCT-2011' as T2_SD, '16-DEC-2011' as T2_ED from dual union all
select 2012 as terms_year, 3 as term, '03-JAN-2012' as T3_SD, '10-FEB-2012' as T3_ED from dual union all
select 2012 as terms_year, 4 as term, '20-FEB-2012' as T4_SD, '30-APR-2012' as T4_ED from dual union all
select 2012 as terms_year, 5 as term, '16-APR-2012' as T5_SD, '01-JUN-2012' as T5_ED from dual) mytable
aka
TERMS_YEAR TERM TERM_START TERM_END
2012 1 05-SEP-2011 21-OCT-2011
2012 2 31-OCT-2011 16-DEC-2011
2012 3 03-JAN-2012 10-FEB-2012
2012 4 20-FEB-2012 30-APR-2012
2012 5 16-APR-2012 01-JUN-2012 Much obliged if anyone can teach me how - I can't get my head around the pivot/unpivot syntax! E.g.
Select *
From mytable
UNPIVOT (
unpivot_clause
unpivot_for_clause
unpivot_in_clause)
Thanks,
TP.Hi,
Using the SELECT ... PIVOT feature:
SELECT terms_year
, term
, term_start
, term_end
FROM mytable
UNPIVOT ( ( term
, term_start
, term_end
) FOR num_col
IN ( (t1, t1_sd, t1_ed) AS 1
, (t2, t2_sd, t2_ed) AS 2
, (t3, t3_sd, t3_ed) AS 3
, (t4, t4_sd, t4_ed) AS 4
, (t5, t5_sd, t5_ed) AS 5
ORDER BY terms_year -- If needed
, num_col
;The basic syntax for UNPIVOTing to 1 column (plus a label column) is
UNPIVOT ( outcol
FOR label IN ( incol_1 AS label_val_1
, incol_2 AS label_val_2
, incol_n AS label_val_n
)where
outcol is the pivoted output column, containing values from the original table,
label is a label column, which will contain values hard-coded in the query,
incol_1, incol_2, ..., incol_n are the columns from the origianl table to be unpivoted
label_val_1, label_val_2, ..., label_val_n are the hard-coded values that will go in the label column.
The syntax for pivoting to m columns (m > 1) is like that for pivoting 1 column, but
instead of outcol, you give a comma-delimited list of m outcols, enclosed in parentheses, and
instead of incol_1, incol_2, ... incol_n, you give a comma-delimited list of m columns, enclosed in parentheses.
By the way, storing dates in VARCHAR2 columns is not a very good idea. Use DATE columns instead.
Edited by: Frank Kulash on Jul 16, 2012 6:11 PM -
Pivot query, phantom behavior, possible bug?
Hi experts,
Oracle 11g
We are trying to construct a binary type table using a pivot query. (I know there will be no 0's, I will fill that in later.)
The query to create this table is as follows:
create table TEMP_T1 as
select * from (
select master_id, mbr_id
sub_id,
NVL(max(den_flag),0) DF,
NVL(max(num_flag),0) NF,
NVL(sum(den_flag),0) DXF,
NVL(sum(num_flag),0) NXF
from MEM_SUM
group by master_id, mbr_id,
sub_id
pivot ( max(DF) D_FLAG,
max(NF) N_FLAG,
sum(DXF) D_COUNT,
sum(NXF) N_COUNT
FOR sub_id in
( 'MEAS-1' AS "MEAS1",'MEAS-2' AS "MEAS2",'MEAS-3' AS "MEAS3",'MEAS-4' AS "MEAS4"))I am seeing unusual results when I run this query, and am unsure why. Wanted to get some thoughts.
First issue:
Although the query selects master_id and mbr_id, I only get master_id with the pivoted results (when it should be master_id, mbr_id & pivot results). Not sure why.
Second issue:
And this is where it gets even more strange, if I
1) do something to the code to make it have a syntax problem, re-run, it will fail, naturally.
then
2) fix the syntax back to the original query above, it will run and return master_id, mbr_id & the pivoted results.
Has anyone encountered such a strange issue before? Any suggestions on a solution welcome.
Edited by: chris001 on Feb 22, 2013 8:09 AMI've experienced a similar problem with my FaderPort controller but only under odd circumstances.
If I accidentally unplugged my FaderPort and then plugged it back in, the Control Surfaces preferences that I had assigned it would get deleted and the MIDI messages would come through as note data and other really weird stuff depending on what track I had selected in the arrange window...
What I noticed was that when I just went in and re-did my Control Surfaces stuff for that controller it would reset and work perfectly.
Eventually I had to contact PreSonus and let them know what was happening. Turns out it was a problem with the driver, and the driver had to be updated to accomodate 8.0.2.
I can only imagine that this is still the case for many companies (including the ones who made your volume pedal) since Logic 9 came so suddenly, without even a 8.1 ever being released....Try contacting that company and seeing if there are any known issues with the driver for the device and Logic 9... might help, can't hurt. -
Help in Pivot Query- To change the column data to rows data!
Hello Gurus -
I have to change the row to Column -
When i use the query -
select NVL (T2.NAME, ' Grand Total') AS State,count(T2.NAME) as Total
from Defect T1,statedef T2,repoproject T3
WHERE T1.STATE=T2.ID AND T1.repoproject = T3.dbid AND T3.name like '%Compass Juice' GROUP BY ROLLUP (T2.NAME)
Then i have got the following data -
STATE TOTAL
Analysis 17
Closed 1302
Development 9
Duplicate 24
Failed 2
OnHold 4
Opened 146
QA 1
ReadyForQA 1
Withdrawn 335
Grand Total 1841
But i want the data in following format -
State Analysis Closed Development Duplicate Failed OnHold Opened QA ReadyForQA Withdrawn GrandTotal
Total 17 1302 9 24 2 4 146 1 1 335 1841
Kindly help me with this. I searched the forum and saw the usage of Max and NVL, Decode but i am unable to understand it to use in my query. kindly help me with this.Hi,
In 11g you can use pivot.
[http://www.oracle.com/technology/pub/articles/oracle-database-11g-top-features/11g-pivot.html]
example
SQL> desc customers
Name Null? Type
CUST_ID NUMBER(10)
CUST_NAME VARCHAR2(20)
STATE_CODE VARCHAR2(2)
TIMES_PURCHASED NUMBER(3)
When this table is selected:
select cust_id, state_code, times_purchased
from customers
order by cust_id;
The output is:
CUST_ID STATE_CODE TIMES_PURCHASED
1 CT 1
2 NY 10
3 NJ 2
4 NY 4
... and so on ...
Note how the data is represented as rows of values: For each customer, the record shows the customer's home state and how many times the customer purchased something from the store. As the customer purchases more items from the store, the column times_purchased is updated.
Now consider a case where you want to have a report of the purchase frequency each state�that is, how many customers bought something only once, twice, thrice and so on, from each state. In regular SQL, you can issue the following statement:
select state_code, times_purchased, count(1) cnt
from customers
group by state_code, times_purchased;
Here is the output:
ST TIMES_PURCHASED CNT
CT 0 90
CT 1 165
CT 2 179
CT 3 173
CT 4 173
CT 5 152
... and so on ...
This is the information you want but it's a little hard to read. A better way to represent the same data may be through the use of crosstab reports, in which you can organized the data vertically and states horizontally, just like a spreadsheet:
Times_purchased
CT NY NJ ... and so on ...
1 0 1 0 ...
2 23 119 37 ...
3 17 45 1 ...
... and so on ...
Prior to Oracle Database 11g, you would do that via some sort of a decode function for each value and write each distinct value as a separate column. The technique is quite nonintuitive however.
Fortunately, you now have a great new feature called PIVOT for presenting any query in the crosstab format using a new operator, appropriately named pivot. Here is how you write the query:
select * from (
select times_purchased, state_code
from customers t
pivot
count(state_code)
for state_code in ('NY','CT','NJ','FL','MO')
order by times_purchased
Here is the output:
. TIMES_PURCHASED 'NY' 'CT' 'NJ' 'FL' 'MO'
0 16601 90 0 0 0
1 33048 165 0 0 0
2 33151 179 0 0 0
3 32978 173 0 0 0
4 33109 173 0 1 0
... and so on ... -
Can't edit and re-Save Power Pivot query with Teradata connection (using LDAP security mechanism) unless "Save my password" option was checked. Without this option I receive this error upon attempt to Save changes made to the query ...
The following exception occurred while the managed IDbConnection interface was being used: [TeraGSS Security Library] [115022] Exception occurred in TERAGSS layer. See inner exception for details.;TdgssAuthenticationTokenExchange delegate threw an exception.
See the inner exception for details.
ErrorCode: -452984642 Severity: Error Facility: DotNet
[Teradata Database] [8017] The UserId, Password or Account is invalid..
A connection could not be made to the data source with the DataSourceID of '6a06124c-496f-4887-bf39-d2582173d499', Name of 'Teradata fsltdprd'.
An error occurred while processing table 'Query'.
The current operation was cancelled because another operation in the transaction failed.Sorry you're right, the Office category isn't currently accepting bug reports in which case Olaf's suggestion to use the smiley face is the way to go. In Excel please go to File > Options > Trust Centre > 'Trust Centre Settings...' and check
that the Feeeback Tool is enabled.
If the option is greyed out like this...
... then you should be able to enable it by changing the value of the 'Enabled' registry key from a 0 to a 1 which you will find under: HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Common\Feedback. You will then need to close all Office applications
and re-launch Excel 2013.
Once the Feeback Tool has been enabled, you should see the smile face(s) in the top right hand corner of the Excel window and be able to send your feedback.
Regards,
Michael
Please remember to mark a post that answers your question as an answer...If a post doesn't answer your question but you've found it helpful, please remember to vote it as helpful :)
Website: nimblelearn.com, Blog:
nimblelearn.com/blog, Twitter:
@nimblelearn -
APEX 3.2 -ORACLE 10G - PIVOT QUERY
Hello, i searched around the forum and i cound't find an answer to this specific matter, although i saw some replies that were close...
i need to creat a form based on a pivot query. but oracle 10g doesn't support that feature so i hope someone can help me.
my problem is that the number of columns will be variable. here's an example:
ORIGINAL TABLE
NAME KMS VEHICLE
Joe 100 AUDI
Tom 300 VW
Mark 150 FORD
Ann 250 FORD
Joe 200 VW
Tom 123 AUDI
Mark 345 AUDI
Ann 45 VW
Joe 6 FORD
Tom 67 FORD
Mark 46 VW
Ann 99 AUDI
DESIRED RESULT
Joe Tom Mark Ann Vehicle
100 123 345 99 AUDI
6 67 150 250 FORD
200 300 46 45 VW
the new columns will be the values in the old NAME column. BUT these values are variable. today its joe,tom,mark and ann tomorrow it could be silvia, tony,richard,harry , william and jane. this means the usuall replies i saw, using MAX and DECODE will not apply because i never know what values or how many values are in this column. with pivot i can get this done.... how can i do this in oracle 10g? is there a way to creat a ser function Pivot somehow? ideas?
thanks!
Mark Pereira
Edited by: 899716 on Jul 18, 2012 12:02 PMThis is the Oracle Forms forum. Post your question in the SQL forum.
Tip: check the latest Oracle Magazine (July/August 2012). There is an article by Tom Kyte about the same question.
http://www.oracle.com/technetwork/oramag/magazine/home/index.html
Maybe you are looking for
-
I can no longer sync my iPhone 4S IMac 10.8.5
iTunes says: "iTunes could not connect to this iPhone. Could not allocate a resource."
-
Windows 8.1 update attempt bricked the machine in bootloop and now automatic repair loop
Hi, I attempted the windows 8.1 update w. failure. =============1st part============ the machine is stuck in bootloop initially, searched the forum and tried several things like the "recovery" options and making a install USB drive to do repairs. No
-
Using an iMac with a mac pro laptop
I have a 24 inch iMac 2.8 Ghz Intel Core 2 Duo which I find great for my photographs with Aperture. I am looking at a MacBook Pro to carry with me. My question is can I connect the MacBook Pro to the iMac in order to use its large screen? Thanks
-
Hello After the latest update a new print dialog is available which includes the option to 'Print on both sides of the paper'. Our printer (available via a print server in a Windows domain environment), is capable of printing duplexed copies of docum
-
I was using the arrange by function to select different arrangements of the files and folders in Finder (column view) but now that I want to return to having them arranged by Name, it is not rearranging the files/folders by name. Instead they stay i