Use Pivot & Unpivot in SQL
Dear All,
I have a data under Table in below shape..
1 - means this user is setup on that feature, & 0 means not.
But, I want to see this output in that way..
Means - If
multiple e-mails are configure on same feature, it should come with semi colon in pivot mode..
Pls Help..
Look at example 4 in the following blog:
http://www.sqlusa.com/bestpractices/training/scripts/commadelimitedlist/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012
Similar Messages
-
Hello,
I have table T1 which has three columns col1, col2 col3 with values sachin, ramesh, tendulkar resp. I want output same as shown in the screenshot. I want to achieve this using pivot/unpivot operators. Please help.Hi Naomi,
The query you suggested will work of the scenarios where the number of columns are not fixed? I have just given an example but In practicle there can be many more columns to my table like col1,col2,col3.....coln. Please let me know the dynamic query.
Thanks!
Sachin
Naomi's Solution is perfect. If your table does not have fixed columns then there is a design problem. And BTW, In this case how can you have variable columns.
I mean, there is FirstName, MiddelName and LastName. What is left? All the attributes of a name are considered in these three attributes. Apart from these you have Title, Sex and others but those are not part of a Name.
Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real.
The climb is all there is. -
SQL Query without using Pivot...
Hi Guys,
Need help with a query... I think pivot table is the way to go but don't wanna to use it as it is not supported in Oracle 10g.
Sample data set...
Part
Section
A001
AC
A001
AY
A001
AN
A001
AX
A015
AC
A015
AR
A007
AC
A008
AN
A008
AX
A008
AE
A008
AT
A008
AY
Required output... (Please note that I cannot hard code the Section column as the data is dynamic)
Part
AC
AY
AN
AX
AR
AE
AT
A001
Y
Y
Y
Y
A015
Y
Y
A007
Y
A008
Y
Y
Y
Y
Y
Can you help me out with this without using pivot tables?
Thanks,
NapsterHi Napster, Try this
select part,
max(decode(section,'AC','Y',NULL)) AC,
max(decode(section,'AY','Y',NULL)) AY,
max(decode(section,'AN','Y',NULL)) AN,
max(decode(section,'AX','Y',NULL)) AX,
max(decode(section,'AC','Y',NULL)) AC,
max(decode(section,'AR','Y',NULL)) AR,
max(decode(section,'AT','Y',NULL)) AT
from sple group by part
SQL> /
Output will be
PART A A A A A A A
A001 Y Y Y Y Y
A007 Y Y
A008 Y Y Y Y
A015 Y Y Y -
Hello,
I have a table with 3 columns, where person_id is unique id.
<person_id> <event_type> <number_events>
1. I need to transform this into a table with <person_id> <event_type1> <event_type2>.... <event_type-n>
And under each column I need to fill the number_events for each event_type for that person_id
2. Next step is to use that table and convert the same into % of number_events under each event_type, as % of total number_events for each id_member
Thanks1. I need to transform this into a table with <person_id> <event_type1> <event_type2>.... <event_type-n>Problem as a SQL projection cannot be of an-unknown-number-of-columns-we-will-figure-it-out-at-run-time. Unless you use some funky PL/SQL coding to create an Advance SQL Data Type that sports a RTTI interface. And this is typically t0o complex for the "normal" PL/SQL developer that almost never use Advance SQL Data Types to create SQL classes, never mind using OCI calls to define PL/SQL methods for RTTI interfaces.
You can of course have a column that is a collection - and a collection can contain any number of elements.
Example:
SQL> -- create a collection type of strings
SQL> create or replace type TStrings as table of varchar2(4000);
2 /
Type created.
SQL>
SQL> col TYPE format a15
SQL> col NAME_LIST format a100
SQL>
SQL> -- now perform a pivot using a collection where
SQL> -- the collection can be 1..n
SQL> select
2 t.object_type as "TYPE",
3 cast( multiset(
4 select object_name from user_objects n where n.object_type = t.object_type
5 )
6 as TStrings
7 ) as "NAME_LIST",
8 count(*) as "TOTAL"
9 from user_objects t
10 group by
11 t.object_type
12 order by 1
13 /
TYPE NAME_LIST TOTAL
FUNCTION TSTRINGS('TESTPIPE', 'TO_TMINOR', 'TO_SUB', 'AUTHENTICATE', 'CHECKSUM', 'FOOPIPE', 'WEBBROWSER', 'PR 19
EVENTDELETE', 'GETSTAT', 'GETHOSTNAME', 'FOOFUNC', 'TOKENISE', 'DYNAMICFUNCTION', 'STATS', 'POP3', '
CALC', 'VPDBPOLICY', 'LISTTONUMBERS', 'TCPPING')
INDEX TSTRINGS('SYS_C0046436', 'SYS_C0046439', 'SYS_IOT_TOP_125320', 'SYS_IOT_TOP_125322', 'SYS_IOT_TOP_12 23
5324', 'SYS_IOT_TOP_125327', 'PK_STUFF', 'SYS_C0055439', 'SYS_C0076868', 'PATIENT_PK', 'SYS_C0055021
', 'INPATIENT_PK', 'SYS_C0055023', 'BED_PK', 'PK_TAB11', 'PK_ROUTERS', 'SYS_C0055202', 'PK_FOO_TAB',
'PK_FOO_UPDATE', 'PK_SERIALISE', 'SYS_C0058353', 'PK_EMP', 'PK_ANYCHART_TEMPLATES')
LIBRARY TSTRINGS('LIBC') 1
LOB TSTRINGS('SYS_LOB0000125313C00031$$', 'SYS_LOB0000153382C00007$$', 'SYS_LOB0000141150C00002$$', 'SYS 6
_LOB0000205530C00001$$', 'SYS_LOB0000197183C00002$$', 'SYS_LOB0000209404C00002$$') -
Hi Team,
I need to write a SQL to cater the requirements. Below is my requirements:
pagename fieldname fieldvalue account_number consumerID
AFAccountUpdate ArrangementsBroken dfsdff 1234 1234
AFAccountUpdate ArrangementsBroken1 dfsdff 1234 1234
AFAccountUpdate ArrangementsBroken2 dfsdff 1234 1234
AFAccountUpdate ArrangementsBroken2 dfsdff 12345 12345
AFAccountUpdate ArrangementsBroken1 addf 12345 12345
Create table test_pivot_dynamic
pagename varchar(200),
fieldname Varchar(200),
fieldvalue varchar(500),
N9_Router_Account_Number bigint,
TC_Debt_Item_Reference bigint
--Input
insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken','addf',1234,1234)
insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken1','dfsdff',1234,1234)
insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken2','fder',1234,1234)
insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken2','dfdfs',12345,12345)
insert into test_pivot_dynamic Values('AFAccountUpdate','ArrangementsBroken1','dfdwe',12345,12345)
insert into test_pivot_dynamic Values('AFAccountUpdate1','Arrangements','addf',1234,1234)
insert into test_pivot_dynamic Values('AFAccountUpdate1','Test1','dfsdff',1234,1234)
--Expected output:
Select 1234,1234,'AFAccountUpdate','ArrangementsBroken','addf','ArrangementsBroken1','dfsdff','ArrangementsBroken2','fder','ArrangementsBroken2','fder'
Select 12345,12345,'AFAccountUpdate','ArrangementsBroken','addf','ArrangementsBroken1','dfdwe','ArrangementsBroken2','dfdfs'
Select 1234,1234,'AFAccountUpdate1','Arrangements','addf','Test1','dfsdff'
so basically we have to pivot and dynamic sql and insert the expected output to a common table which will have all the required fields
Thanks,Ram.
Please don't forget to Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful. It will helpful to other users.This should give you what you're looking for
SELECT N9_Router_Account_Number,TC_Debt_Item_Reference,PageName,
MAX(CASE WHEN SEQ = 1 THEN fieldname END) AS fieldname1,
MAX(CASE WHEN SEQ = 1 THEN fieldvalue END) AS fieldvalue1,
MAX(CASE WHEN SEQ = 2 THEN fieldname END) AS fieldname2,
MAX(CASE WHEN SEQ = 2 THEN fieldvalue END) AS fieldvalue2,
MAX(CASE WHEN SEQ = 3 THEN fieldname END) AS fieldname3,
MAX(CASE WHEN SEQ = 3 THEN fieldvalue END) AS fieldvalue3,
MAX(CASE WHEN SEQ = 4 THEN fieldname END) AS fieldname4,
MAX(CASE WHEN SEQ = 4 THEN fieldvalue END) AS fieldvalue4
FROM
SELECT *,ROW_NUMBER() OVER (PARTITION BY N9_Router_Account_Number,TC_Debt_Item_Reference,PageName ORDER BY PageName) AS SEQ,*
FROM test_pivot_dynamic
)t
GROUP BY N9_Router_Account_Number,TC_Debt_Item_Reference,PageName
To make it dynamic see
http://www.beyondrelational.com/modules/2/blogs/70/posts/10791/dynamic-crosstab-with-multiple-pivot-columns.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
ORA-56901: non-constant expression is not allowed for pivot|unpivot values
Getting following errors
ORA-56901: non-constant expression is not allowed for pivot|unpivot values
ORA-06512: at "APPS.PIVOT_AWARD", line 16
ORA-06512: at line 5
when i run the following function it is giving error as above.
can you please help me
create or replace
Function Pivot_award return sys_refcursor
IS
v_dept VARCHAR2 (20000);
v_query VARCHAR2 (1000);
op_rs sys_refcursor;
BEGIN
SELECT LISTAGG(award_number,',') WITHIN GROUP (ORDER BY award_id)
INTO V_DEPT FROM xxdl.XXDL_CD_SCHEDULE_K_GTT ;
v_query :=
'SELECT *
FROM (
select award_name, award_id,award_number from xxdl.XXDL_CD_SCHEDULE_K_GTT)
PIVOT(max(VAL) for award_number in ('||v_dept||'))';
OPEN op_rs FOR v_query;
return op_rs;
END;
SELECT LISTAGG(award_number,',') WITHIN GROUP (ORDER BY award_id)
INTO V_DEPT FROM xxdl.XXDL_CD_SCHEDULE_K_GTT ;
Result of 1st query is PPE_T_CAPITAL,XIBNG,XIABP,XIABQ,XIABR,XIABS,XIABT,XIABU,XIABV,XIABW,XIAAE,XIAAF,XIAAG,XIAAH,XIAAI,XIAAJ,XIAAK,XIAAL,XIAAM,XIAAN,XIAAO,XIAAP,XIAAQ,XIAAR,XIAAS,XIAAU,XIAAU,XIAAV,XIAAZ,XIABD,XIABE,XIABF,XIABG,XIABH,XIABI,XIABJ,XIABK,XIABL,XIABM,XIABN,XIAAA,XIAAB,XIAAC,XIAAD,XIABY,XIABZ,XIACA,XIACB,XIACC,XIACD,XIACE,XIACF,XIACG,XIACH,XIACI,XIABA,XIAAW,XIAAX,XIAAY,XIACN,XIACT,XIACU,XIACP,AAAEX,XIACW,XIADCHi Frank,
Here is the create table and insert script. This is needed for me to show in report rows to columns.
create table award_test(
AWARD_NUMBER VARCHAR2 (15) ,
AWARD_NAME VARCHAR2(30) ,
TOTAL_PROCEEDS NUMBER ,
EARNING_PROCS NUMBER ,
TOT_PROCS_EARNINGS NUMBER ,
GROSS_PROCS NUMBER ,
PROC_REF_DEF_ESCR NUMBER ,
OTH_UNSP_PROCS NUMBER ,
ISSUANCE_COST NUMBER ,
WORK_CAP_EXP NUMBER
--insert script
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAE','CEFA CP',300000000,200,300000200,300,500,600,0,700);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIABG','CEFA K',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAS','Escondido Village #3',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('AAAEX','SU2009A',801806000,null,801806000,null,null,null,1806000,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIABI','CEFA L-6',17815000,null,17815000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAP','CEFA R',115050508.15,null,115050508.15,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIACG','CEFA D',53150000,null,53150000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAB','Stu Union-1962',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAA','Notes Payable-Commercial Paper',350000000,null,350000000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIABZ','CEFA L-3',9840000,null,9840000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAV','CEFA B',18106540,null,18106540,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAI','Medium Term Notes - Tranche 3',50000000,null,50000000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAZ','Recycling Pool',473379904.44,null,473379904.44,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAY','CEFA T2',187550000,null,187550000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAM','GMAC',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAU','CEFA A/K',16922982,null,16922982,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAC','SU TB 2002A - PARS',50000000,null,50000000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIABL','CEFA L-9',15490000,null,15490000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIABY','CEFA L-2',8775000,null,8775000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAJ','Frat 1&2',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAW','CEFA S',180727500,null,180727500,null,null,null,-472500,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAQ','Escondido Village #1',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIACW','CEFA U',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIACF','CEFA E',19753227.34,null,19753227.34,null,null,null,-106772.66,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIACN','CEFA T3',27562758.96,null,27562758.96,null,null,null,-47941.04,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAG','Medium Term Notes - Tranche 1',50000000,null,50000000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('PPE_T_CAPITAL','PPE_T_CAPITAL',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAK','Frat 3',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAF','Tresidder',0,null,0,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIABH','CEFA L',5055000,null,5055000,null,null,null,0,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAU','CEFA A/K',6605655,null,6605655,null,null,null,-74345,null);
Insert into "award_test" (AWARD_NUMBER,AWARD_NAME,TOTAL_PROCEEDS,EARNING_PROCS,TOT_PROCS_EARNINGS,GROSS_PROCS,PROC_REF_DEF_ESCR,OTH_UNSP_PROCS,ISSUANCE_COST,WORK_CAP_EXP) values ('XIAAD','SU 2024 Bonds',150000000,null,150000000,null,null,null,0,null);Expected output rows to columns (i took first two insert statements)
'XIAAE','CEFA CP',300000000,200,300000200,300,500,600,0,700
'XIABG','CEFA K',0,null,0,null,null,null,0,null
I need to have awardnumber and corresponding details below
'XIAAE' 'XIABG'
'CEFA CP' 'CEFA K'
300000000 0
200 null
300000200 0
This way i need to get all the information vertically with awardnumber. I have written following code but it is not working.
create or replace
Function Pivot_award return sys_refcursor
IS
v_dept VARCHAR2 (20000);
v_query VARCHAR2 (1000);
op_rs sys_refcursor;
BEGIN
SELECT LISTAGG('''' || award_number || '''',',') WITHIN GROUP (ORDER BY award_number)
INTO V_DEPT FROM award_test ;
v_query :=
'SELECT * from award_test
UNPIVOT(VAL for operator in(
AWARD_NAME,
TOTAL_PROCEEDS,
EARNING_PROCS ,
TOT_PROCS_EARNINGS ,
GROSS_PROCS ,
PROC_REF_DEF_ESCR ,
OTH_UNSP_PROCS ,
ISSUANCE_COST ,
WORK_CAP_EXP ))
PIVOT(max(VAL) for award_number in ('||v_dept||'))';
OPEN op_rs FOR v_query;
return op_rs;
END;throwing an error ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "APPS.PIVOT_AWARD", line 11
ORA-06512: at line 5
also when i run simple query
SELECT * from award_test
UNPIVOT(VAL for operator in(
AWARD_NAME,
TOTAL_PROCEEDS,
EARNING_PROCS ,
TOT_PROCS_EARNINGS ,
GROSS_PROCS ,
PROC_REF_DEF_ESCR ,
OTH_UNSP_PROCS ,
ISSUANCE_COST ,
WORK_CAP_EXP ))
PIVOT(max(VAL) for award_number in ('PPE_T_CAPITAL','XIBNG','XIABP')) Throwing an error
ora-01790 Expression must have same datatype as correspoding expression
Edited by: 893185 on Nov 10, 2011 2:00 PM -
View API for Pivot/Unpivot - information is missing
Hi,
I'm trying to prepare a report in order to show the column mappings over multiple mapping operators usin the view API. Each operator has its particular problems when crossing from out to in, but most of them can be solved using the view API except of the following:
The Pivot/Unpivot expressions seem not to be documented. ALL_IV_XFORM_MAP_PARAMETERS.transformation_expression is empty for the out parameters (probably due to the 1:n cardinality with the row locator). But where else to look up? I'm unable to cross the bridge from outgroup to ingroup.
With Join operator there is the problem that the transformation expression doesn't contain the ingroup qualification, so, the true source cannot be identified uniquely when the attribute name is repeated in several ingroups.
Both informations must be buried somewhere in the repository. I would be satisfied the receive an "undocumented" solution if it is a real deficit in the view API. Maybe some privileged person could post an enhencement request.
best regards
ThomasNot got a single answer , surprise whether the question is too dumb to ask or JAXB doesn't support feature or my requirement is weird :-) ... in any case let me know please
regards -
Missing expression Error using pivot function
Hi,
When i am running the query:
The query needs to display name and total:
{select *}
{ from (select name,nvl(sal,0) tot from tablea }
{ GROUP BY name,nvl(sal,0) }
{ pivot(SUM(tot) for name in (select ltrim(sys_connect_by_path(''''||name||'''', ','), ',') str}
{from ( select row_number() over(order by name) rn}
{ , name}
{ from tablea}
{where connect_by_isleaf=1}
{start with rn=1}
{connect by rn=prior rn+1);}
When running the above query its giving error:
ORA-00936: missing expression at line select ltrim(sys_connect_by_path
Any help will be needful for meIf you use pivot, you have to hardcode all your values in the FOR IN clause.
SQL> select *
2 from (select ename,nvl(sal,0) tot from emp
3 GROUP BY ename,nvl(sal,0)
4 )
5 pivot(SUM(tot) for ename in ( 'SCOTT' ,'KING') )
6 ;
'SCOTT' 'KING'
3000 5000You can't substitute the literal list of values (in my example ('SCOTT','KING') with a subquery producing similar result.
Only with pivot xml you can put there a subquery, in that case, the result however doesn't have to be in form of comma separated values (like you try to achieve with sys_connect_by_path)
SQL> select *
2 from (select ename,nvl(sal,0) tot from emp
3 GROUP BY ename,nvl(sal,0)
4 )
5 pivot xml (SUM(tot) for ename in ( select ename from emp where ename like 'S%' ) )
6 ;
ENAME_XML
<PivotSet><item><column name = "ENAME">SCOTT</column><column name = "SUM(TOT)">3000</column></item><
item><column name = "ENAME">SMITH</column><column name = "SUM(TOT)">800</column></item></PivotSet>Best regards
Maxim -
How to pivot using pivot clause of sqlserver 2005 for three values
Dear all
Is it possible to formulate the query using pivote clause of sqlserver 2005.
( Table name is) BridgeHawra
ReportDate, , Pole, DiameterCost,Flag,OuterDiaCost
01 jan 2014, ,1 , 4.5 ,yes,6
01 jan 2014, ,2 , 4.5 ,no,6
01 jan 2014, ,3 , 5.5 ,no,6
02 jan 2014, ,4 , 5.5 ,no,5.9
02 jan 2014, ,5 , 5.5 ,no,6
1)Pole Col will have unique value.
o2)One pole will have one DiameterCost, but n number of DiameterCost can be there.
I have to show a report which should show , count of poles and cost(DiameterCost* pole count of the day of each DiameterCost) for each date and DiameterCost.
as following
DateOfReport , PoleCountofDiameterCost4.5, DiameterCost4.5, PoleCountOfDiameterCost5.5,DiameterCost5.5
01 jan 2014 , 2
,(2*4.5) ,1
,(1*5.5)
02 jan 2014 , 0/null ,0/null
,2
,(2*5.5)
yours sincerelyYes it is possible though you need to use dynamic pivot technique. Dynamic pivot allow you to select/display column names dynamically.
Below example does not use dynamic pivot,
--create table #temp(ReportDate datetime,Pole int, DiameterCost decimal(5,2),Flag varchar(3),OuterDiaCost decimal(5,2))
--insert into #temp values('01 jan 2014',1,4.5,'yes',6)
--insert into #temp values('01 jan 2014',2,4.5,'no',6)
--insert into #temp values('01 jan 2014',3,5.5,'no',6)
--insert into #temp values('02 jan 2014',4,5.5,'no',5.9)
--insert into #temp values('02 jan 2014',5,5.5,'no',6)
;with cte as (
select ReportDate,
DiameterCost * PoleCount as DiameterCost,
PoleCount ,
'PoleCountofDiameterCost'+cast(DiameterCost as varchar) column1,
'DiameterCost'+cast(DiameterCost as varchar) column2
from (
select ReportDate,DiameterCost,Count(Pole) as PoleCount from #temp
group by ReportDate,DiameterCost
) x
),cte1 as (
select * from cte
pivot( max(PoleCount) for column1 in ([PoleCountofDiameterCost4.50],[PoleCountofDiameterCost5.50])
) pvt
pivot( max(DiameterCost) for column2 in ([DiameterCost4.50],[DiameterCost5.50])
) pvt1
select ReportDate,
Max([PoleCountofDiameterCost4.50]) [PoleCountofDiameterCost4.50],
Max([DiameterCost4.50]) [DiameterCost4.50],
Max([PoleCountofDiameterCost5.50]) [PoleCountofDiameterCost5.50],
Max([DiameterCost5.50]) [DiameterCost5.50] from cte1
group by ReportDate
Regards, RSingh -
XML Publisher Report Fails While using Pivot Table in R12 Oracle EBS
Hello All,
Need your help. I am trying to create a report with a Pivot table. I have created the .rtf file using the Oracle BI Publisher Template Builder for word 10.1.3.4.1. the data comes correctly in preview but when i register it in EBS and run the concurrent program it competes in warning and no output is displayed.
The error message looks like as follows.
[9/3/10 4:03:17 PM] [19934:RT444621] Executing post-processing actions for request 444621.
[9/3/10 4:03:17 PM] [19934:RT444621] Starting XML Publisher post-processing action.
[9/3/10 4:03:17 PM] [19934:RT444621]
Template code: XXECOHCGEN
Template app: XXECO
Language: en
Territory: 00
Output type: EXCEL
[9/3/10 4:03:31 PM] [19934:RT444621] Output file was found but is zero sized - Deleted
[9/3/10 4:03:31 PM] [UNEXPECTED] [19934:RT444621] java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:599)
at oracle.apps.xdo.common.xml.XSLT10gR1.invokeNewXSLStylesheet(XSLT10gR1.java:611)
at oracle.apps.xdo.common.xml.XSLT10gR1.transform(XSLT10gR1.java:239)
at oracle.apps.xdo.common.xml.XSLTWrapper.transform(XSLTWrapper.java:182)
at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:1044)
at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:997)
at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(FOUtility.java:212)
at oracle.apps.xdo.template.FOProcessor.createFO(FOProcessor.java:1665)
at oracle.apps.xdo.template.FOProcessor.generate(FOProcessor.java:975)
at oracle.apps.xdo.oa.schema.server.TemplateHelper.runProcessTemplate(TemplateHelper.java:5936)
at oracle.apps.xdo.oa.schema.server.TemplateHelper.processTemplate(TemplateHelper.java:3459)
at oracle.apps.xdo.oa.schema.server.TemplateHelper.processTemplate(TemplateHelper.java:3548)
at oracle.apps.fnd.cp.opp.XMLPublisherProcessor.process(XMLPublisherProcessor.java:302)
at oracle.apps.fnd.cp.opp.OPPRequestThread.run(OPPRequestThread.java:176)
Caused by: oracle.xdo.parser.v2.XPathException: Namespace prefix 'crosstab' used but not declared.
at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:806)
at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:571)
... 17 more
would appreciate some pointers to fix this issue.
Regards,
Abhijeet K
Edited by: Abhijeet K on Sep 3, 2010 8:10 AMHI, was there a Solution Ever found for this post other than the Workaround.
I am at the Same issue now, Any Valuable inputs will Help me finish my Report ASAP, becos currently this is my only Show stopper
we have Oracle Apps R12 realease 12.1.3 we use XMLpublisher built in R12
The issue i have is .
I created a XMLPublisher Report using PIVOT TABLE i would like to have my output to be in Excel, When i Preview it works fine, when i execute via Concurrent Program it gives the Following Log file
XXTPC Custom Application: Version : UNKNOWN
Copyright (c) 1979, 1999, Oracle Corporation. All rights reserved.
TPC_ITEM_COUNT_RPT module: TPC ITEM COUNT RPT
Current system time is 25-JUN-2012 11:00:39
XDO Data Engine Version No: 5.6.3
Resp: 21676
Org ID : 101
Request ID: 2149483
All Parameters: report_name=RUN BY ORDER TYPE:org_name=HQF:org_choice=TPC US:item_selection=1001:order_type=k-us:pstatus=entered,waved,notwaved,shipped:transit_days=:first_receipt_date=01-jun-2012:last_receipt_date=22-jun-2012
Data Template Code: TPC_ITEM_COUNT_RPT
Data Template Application Short Name: XXTPC
Debug Flag: N
{first_receipt_date=01-jun-2012, org_choice=TPC US, item_selection=1001, report_name=RUN BY ORDER TYPE, pstatus=entered,waved,notwaved,shipped, org_name=HQF, last_receipt_date=22-jun-2012, order_type=k-us, transit_days=}
Calling XDO Data Engine...
Start of log messages from FND_FILE
End of log messages from FND_FILE
Executing request completion options...
Output file size:
29148
------------- 1) PUBLISH -------------
Beginning post-processing of request 2149483 on node HQTERPAS1LX at 25-JUN-2012 11:00:51.
Post-processing of request 2149483 failed at 25-JUN-2012 11:00:52 with the error message:
One or more post-processing actions failed. Consult the OPP service log for details.
------------- 2) PRINT -------------
Not printing the output of this request because post-processing failed.
Finished executing request completion options.
Concurrent request completed
Current system time is 25-JUN-2012 11:00:52
I have requested my DBA to get me the OPP file..
Thanks in advance for any solution. -
Using MapViewer from PL/SQL vs Java
Hi group!
The MapViewer User's Guide has this to say about using MapViewer from PL/SQL:
"The usage model for the SDO_MVCLIENT package is almost identical to that of
MapViewer JavaBean-based API" etc etc .. "For usage and reference information about specific functions or procedures, see the description of the associated JavaBean-Based API. methods and interfaces in Chapter 4"
If I don't misunderstand the basic concept, in a Java Web App (using the MapViewer Bean) you create a MapViewer object for each HTTP-user-session, like so:
MapViewer mv = new MapViewer("http://my_corp.com:8888/mapviewer/omserver");
... which you would then store in the user's session object, so that the MapViewer Bean conveniently holds the map's state on the user's behalf.
To do the equivalent in PL/SQL, the User's Guide suggests:
"connect scott/tiger
call sdo_mvclient.createmapviewerclient(
'http://www.mycorp.com:8888/mapviewer/omserver') ;
The preceding example creates, in the current session, a unique MapViewer client
handle to the MapViewer service URL"
Does "current session" refer to the HTTP-user-session? While I've used PL/SQL before, I've not used the PL/SQL Web Toolkit. Is the session handling implicit here (and invisible?) or should the sdo_mvclient be subsequently stored in the PL/SQL equivalent of a (J2EE) HttpSession object?
YTPart of the answer will depend on how you plan to deploy the application. If you have a few, local clients you could go with the traditional client/server model. If you have a lot of clients and/or they are spread out over a relatively large area (like a campus setting), a web front-end will save you a lot of hassels down the road when it comes time to upgrade.
Regardless of the the front end, I can tell you that I have been greatly impressed with the throughput you can get by moving most of the code to PL/SQL packages. A few years ago we reworked a VB/Oracle app by moving a lot of the code out of VB and into packages, leaving the client to essentially call procedures and format the output. We had more than a 3x performance increase on the same hardware and our network utilization decreased noticably.
I am now in the process of replacing the client code with Java servlets/JSP, primarily because of the maintenance hassles I mentioned earlier. There are some limitations with an HTML page but most of these have been cosmetic so far.
We are still relying heavily on PL/SQL packages. The servlet code basically gets a request, calls a package to get the data, then hands the results to a JSP page. The JSP then formats the output and sends it to the client. We are little more than halfway through the re-write, but it appears performance will increase again. Not as noticably as before, but I will take what I can get. As you have seen, once something is rolled out it always ends up getting used more than you anticipated. Better to over-engineer now than have to patch it once it is live.
HTH -
Can we use different Databases (Oracle & SQL Server) in one report?
Post Author: venki5star
CA Forum: .NET
Hi there.
Can we use different databases (Oracle & SQL Server) in a same report?
If possible how?
Another question,
Can we change the Provider Name at runtime of the given report. If so the above question is useless...
Thanks in Advance.I tried this using Oracle Provider for OLEDB (the one that supplied by Oracle Client) and Crystal Reports 9. you can drag the column into designer but the image does not appear in preview.
I guess it's because CR does not recognized it as image, and there are no information that the blob data is an image at all. -
How to get multiple records using fn-bea:execute-sql()
Hi,
I created Proxy service(ALSB3.0) to get records from DB table. I have used Xquery function(fn-bea:execute-sql()). Using simple SQL query I got single record, but my table having multiple records. Please suggest how to get multiple records using fn-bea:execute-sql() and how to assign them in ALSB variable.
Regards,
Nagaraju
Edited by: user10373980 on Sep 29, 2008 6:11 AMHi,
Am facing the same issue stated above that I couldnt get all the records in the table that am querying in the Proxyservice.
For example:
fn-bea:execute-sql('EsbDataSource', 'student', 'select Name from StudentList' ) is the query that am using to fetch the records from the table called StudentList which contains more than one records like
Id Name
01 XXX
02 YYY
03 ZZZ
I tried to assign the result of the above query in a variable and while trying to log the variable, I can see the below
<student>
<Name>XXX</Name>
</student>
I want to have all the records from my table in xml format but it's not coming up. I get the value only from the first row of my table.
Please suggest.
regards,
Venkat -
Using a custom PL/SQL to populate the primary key in a tabular form
I want to use a Custom PL/SQL Function to populate the primary key when I insert a new record into a tabular form. I want to get the value from a hidden page Item. The code I am using for the primary key source is:
BEGIN
INSERT INTO TEAM_MEMBERS(TEAM_ID)
VALUES(:P75_TEAM_ID);
END;
When I try to insert a new record I get the following error:
Error ERR-1904 Unable to compute item default: type = Function Body computation_type= BEGIN INSERT INTO TEAM_MEMBERS(TEAM_ID) VALUES(:P75_TEAM_ID); END; .
ORA-06550: line 5, column 2: PLS-00103: Encountered the symbol ";" when expecting one of the following: begin case declare end exception exit for goto if loop mod null pragma raise return select update while with << close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe The symbol "exit" was substit
Any ideas what I am doing wrong?
Thanks!Brian - Sometimes whitespace at the end of the block causes this. Be sure to trim everything after the last semicolon including tabs and newlines.
Scott -
Hi,
This is similar - yet different - to a few of the old postings about performance
problems with using jdbc drivers against Sql Server 7 & 2000.
Here's the situation:
I am running a standalone java application on a Solaris box using BEA's jdbc driver
to connect to a Sql Server database on another network. The application retrieves
data from the database through joins on several tables for approximately 40,000
unique ids. It then processes all of this data and produces a file. We tuned
the app so that the execution time for a single run through the application was
24 minutes running against Sql Server 6.5 with BEA's jdbc driver. After performing
a DBMS conversion to upgrade it to Sql Server 2000 I switched the jDriver to the
Sql Server 2000 version. I ran the app and got an alarming execution time of
5hrs 32 min. After some research, I found the problem with unicode and nvarchar/varchar
and set the "useVarChars" property to "true" on the driver. The execution time
for a single run through the application is now 56 minutes.
56 minutes compared to 5 1/2 hrs is an amazing improvement. However, it is still
over twice the execution time that I was seeing against the 6.5 database. Theoretically,
I should be able to switch out my jdbc driver and the DBMS conversion should be
invisible to my application. That would also mean that I should be seeing the
same execution times with both versions of the DBMS. Has anybody else seen a
simlar situation? Are there any other settings or fixes that I can put into place
to get my performance back down to what I was seeing with 6.5? I would rather
not have to go through and perform another round of performance tuning after having
already done this when the app was originally built.
thanks,
mikeMike wrote:
Joe,
This was actually my next step. I replaced the BEA driver with
the MS driver and let it run through with out making any
configuration changes, just to see what happened. I got an
execution time of about 7 1/2 hrs (which was shocking). So,
(comparing apples to apples) while leaving the default unicode
property on, BEA ran faster than MS, 5 1/2 hrs to 7 1/2 hrs.
I then set the 'SendStringParametersAsUnicode' to 'false' on the
MS driver and ran another test. This time the application
executed in just over 24 minutes. The actual runtime was 24 min
16 sec, which is still ever so slightly above the actual runtime
against SS 6.5 which was 23 min 35 sec, but is twice as fast as the
56 minutes that BEA's driver was giving me.
I think that this is very interesting. I checked to make sure that
there were no outside factors that may have been influencing the
runtimes in either case, and there were none. Just to make sure,
I ran each driver again and got the same results. It sounds like
there are no known issues regarding this?
We have people looking into things on the DBMS side and I'm still
looking into things on my end, but so far none of us have found
anything. We'd like to continue using BEA's driver for the
support and the fact that we use Weblogic Server for all of our
online applications, but this new data might mean that I have to
switch drivers for this particular application.Thanks. No, there is no known issue, and if you put a packet sniffer
between the client and DBMS, you will probably not see any appreciable
difference in the content of the SQL sent be either driver. My suspicion is
that it involves the historical backward compatibility built in to the DBMS.
It must still handle several iterations of older applications, speaking obsolete
versions of the DBMS protocol, and expecting different DBMS behavior!
Our driver presents itself as a SQL7-level application, and may well be treated
differently than a newer one. This may include different query processing.
Because our driver is deprecated, it is unlikely that it will be changed in
future. We will certainly support you using the MS driver, and if you look
in the MS JDBC newsgroup, you'll see more answers from BEA folks than
from MS people!
Joe
>
>
Mike
The next test you should do, to isolate the issue, is to try another
JDBC driver.
MS provides a type-4 driver now, for free. If it is significantly faster,
it would be
interesting. However, it would still not isolate the problem, because
we still would
need to know what query plan is created by the DBMS, and why.
Joe Weinstein at BEA
PS: I can only tell you that our driver has not changed in it's semantic
function.
It essentially send SQL to the DBMS. It doesn't alter it.
Maybe you are looking for
-
Ipod on Xbox 360, some songs don't show up
I recently bought an Xbox 360, I have been using my Ipod to listen to music but some songs don't show up in Xbox playlist, particularly the music I have bought and downloaded from Itunes music store, Is it some kind of protected format, what can I do
-
Playlist is not playing songs in order
I recently synched my ITouch with my IMAC. After the synch process, I noticed when playing a playlist on my ITouch that the songs were being played at random. I did not press shuffle. I did not have this issues when I synched the ITouch previously
-
hi I need help please. I've got problems in reaching servlets from a jsp page. Here are files: jsp1.jsp servlet1.java servle2.java 1)I call servlet1 from jsp1 by <form method="post" action="./servlet1 path/servlet1"> (servlet1 is mapped in web.xml )
-
Play button not reacting - can't play arrangement
Anyone know what's happening? The play button on my transport bar doesn't respond and pressing space bar doesn't get the track going either. The bar count row at the top of the arrange page has a blue overlay on it that I haven't seen before.
-
Free Screen Recording Software
I need a free screen recording software. Anyone know of any good ones? I have been looking at CamStudio.org but I can't find anyone to really vouch for it yet and the download package is sketchy at best. It's a zip file with a single .exe so I tried