Converting rows in a column
Hi,
I've records like:
Officer ID Qualification Id Qualification Type Qualification
1 1 Academic 10th
1 2 Academic 12th
1 3 Academic B.Sc.
2 1 Academic 10th
2 2 Academic I.Sc.
2 3 Academic B.A.
I need to rotate the rocards and make it like:
Officer ID Qualification1 Qualification2 Qualification3
1 10th 12th B.Sc.
2 10th I.Sc. B.A.
The system accepts 60 different possible values of qualifications, but out of them an officer can have at max 6 different qualifications.
Can you please suggest me , how to acheive this conversion of rows into
columns.
Thanks And regards
Rajeev Ranjan
You can use unpivot for that purpose.
Jörg
Similar Messages
-
How to convert Rows to different columns
Hi All,
I am having a table address with the following data.
ID REL_NAME REL_RELATION REL_PHONE
1--- kish_rel1--- wife--- 1111
1--- kish_rel2--- sister--- 2222
1--- kish_rel3--- brother--- 3333
2--- ram_rel1--- brother--- 4444
Now i want to display rows data into columns. See the output i want. Exactly, I dont know how many rows are there for each ID. It may increase or decrease.
ID REL_NAME REL_RELATION REL_PHONE
1---kish_rel1--- wife--- 1111---kish_rel2--- sister--- 2222---kish_rel3--- brother--- 3333
2---ram_rel1--- brother--- 4444
Thanks in advance,
PalHi,
I have found this is useful. But it is static. It wont work if we dont know the maximum number of rows present when grouped by ID.
Is there any other solution, which will give correct values, if we dont know the row count when grouped by ID.
SELECT hrid,
MAX(case when seq=1 then rel_name end) AS "rel_name1",
MAX(case when seq=1 then rel_relation end) AS "rel_relation1",
MAX(case when seq=1 then rel_phone end) AS "rel_phone1",
MAX(case when seq=2 then rel_name end) AS "rel_name2",
MAX(case when seq=2 then rel_relation end) AS "rel_relation2",
MAX(case when seq=2 then rel_phone end) AS "rel_phone2",
MAX(case when seq=3 then rel_name end) AS "rel_name3",
MAX(case when seq=3 then rel_relation end) AS "rel_relation3",
MAX(case when seq=3 then rel_phone end) AS "rel_phone3",
MAX(case when seq=4 then rel_name end) AS "rel_name4",
MAX(case when seq=4 then rel_relation end) AS "rel_relation4",
MAX(case when seq=4 then rel_phone end) AS "rel_phone4"
FROM (SELECT hrid, rel_name, rel_relation, rel_phone, ROW_NUMBER() over(partition by hrid ORDER BY hrid) AS seq FROM address)
GROUP BY hrid
Thanks,
Pal -
How to convert row data into columns without using pivot table?
Hello guys
I have a report that has several columns about sales call type and call counts
It looks like this:
Calls Type Call Counts
Missed 200
Handled 3000000
Rejected 40000
Dropped 50000
Now I wanna create a report that look like this:
Missed call counts Handled Call counts Rejected Counts Drop counts Other Columns
200 300000000 40000 50000 Data
So that I can perform other calculations on the difference and comparison of handled calls counts vs other call counts..
I know pivot table view can make the report look like in such way, but they cant do further calculations on that..
So I need to create new solid columns that capture call counts based on call types..
How would I be able to do that on Answers? I don't have access to the RPD, so is it possible to do it sololy on answers? Or should I just ask ETL support on this?
Any pointers will be deeply appreciated!
Thank youThanks MMA
I followed your guidance and I was able to create a few new columns of call missed count, call handled counts and call abandoned counts.. Then I create new columns of ave missed counts, ave handled counts and so forth..
Then I went to the pivot view, I realized there is a small problem.. Basically the report still includes the column "call types" which has 3 different types of call "miss, abandon and handled". When I exclude this column in my report, the rest of the measures will return wrong values. When I include this column in the report, it shows duplicate values by 3 rows. It looks like this:
Queue name Call types Call handled Call missed Call abondoned
A Miss 8 10 15
A Handled 8 10 15
A Abandoned 8 10 15
in pivot table view, if I move call type to column area, the resulted measures will become 8X3, 10X3 and 15X3
So is there a way to eliminate duplicate rows or let the system know not to mulitply by 3?
Or is this as far as presentation service can go in terms of this? Or should I advice to provide better data from the back end?
Please let me know, thanks -
Convert rows to single column using t-sql
Hi All,
I have a table with 7 columns, et say..
ID ,PatientName,Date,Time,Room_Num ,Specialized, DoctorName
My source date looks like this..
ID PatientName Date Time Room_Num Specialized DoctorName
1 Sam 10/02/2010 10:00 4 Heart
John
1 Sam 10/02/2010 10:00 4 Lungs
Harris
2 Jones 11/12/2011 11:00 1 Lungs
Bob
3 Jim 12/05/2001 01:00 2 Kidney
Greg
3 Jim 12/05/2001 09:00 2 Eye
Roby
1 Sam 12/22/2010 11:00 1 Heart
John
1 Sam 12/22/2010 11:00 1 Lungs
Harris
My out put should look like this..
ID PatientName Date DoctorName
1 Sam 10/02/2010 John,Harris ( Need to be in 1 row because - ID, PatientName, Date is same)
2 Jones 11/12/2011 Bob ( Need to show as it is due to no repeatition
of ID)
3 Jim 12/05/2001 Greg,Roby ( Need to be in 1 row because - ID, PatientName,
Date is same)
1 Sam 12/22/2010 John,Harris ( Need to be in 1 row because - ID, PatientName, Date is same)
I am using below query to get above results but I am getting wrong results..Need some help in tweaking the query...
SELECT DISTINCT ID ,PatientName , Date
,STUFF(( SELECT ',' + DoctorName
FROM SampleTable ST1
WHERE ST1.ID=ST2.ID
FOR XML PATH('')),1,1,' ') AS DoctorName
FROM SampleTable1 ST2
GROUP BY ID ,PatientName , Date
With above query I am getting results like this...
ID PatientName Date DoctorName
1 Sam 10/02/2010 John,Harris ,John,Harris ( here John,Harris are repeating twice because of 4th row)
2 Jones 11/12/2011 Bob
3 Jim 12/05/2001 Greg,Roby
1 Sam 12/22/2010 John,Harris ,John,Harris ( here John,Harris are repeating twice because of 1st row)
Create table statement:
Create table SampleTable
ID Int null, PatientName varchar(25) null, Date datetime null, Time varchar(10) null, Room_Num int null, Specialized varchar(20) null, DoctorName varchar(20) null
Insert statement:
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam','10/02/2010' ,'10:00',4 ,'Heart','John')
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1, 'Sam','10/02/2010' ,'10:00' , 4 , 'Lungs','Harris')
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 2, 'Jones' ,'11/12/2011' , '11:00',1, 'Lungs', 'Bob')
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 3,'Jim' ,'12/05/2001' , '01:00',2,'Kidney' , 'Greg')
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 3,'Jim' ,'12/05/2001' , '09:00',2,'Eye' , 'Roby')
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam' ,'12/22/2010' , '11:00',1,'Heart', 'John')
Insert into sampletable(ID,PatientName,Date,Time,Room_Num,Specialized,DoctorName) Values ( 1,'Sam', '12/22/2010' , '11:00',1 , 'Lungs','Harris')
I need help to tweak my query.
Thanks,
RH
sqlWITH cte AS(
SELECT [ID]
,[PatientName]
,[Date]
,[Time]
,[Room_Num]
,[Specialized]
,[DoctorName]
,ROW_NUMBER() OVER(PARTITION BY [ID],[PatientName],[Date] ORDER BY Time) as RowID
FROM [test].[dbo].[SampleTable]
SELECT
cte.[ID]
,cte.[PatientName]
,CAST(cte.[Date] as DATE) as [Date]
,STUFF((SELECT ',' + c.[DoctorName]
FROM cte c
WHERE c.ID=cte.ID AND c.PatientName=cte.[PatientName] AND c.[Date]=cte.[Date]
FOR XML PATH(''),TYPE).value('.','varchar(max)')
,1,1,'') AS [DoctorName]
FROM cte
WHERE cte.RowID=1 -
Hi All
Need some assistance, i have a table where i want the output to be a single column
ex: select from t1;*
query output_
rownum col_1
1 8217
2 6037
3 5368
4 5543
5 5232
i would like the result to be : *8217,6037,5368,5543,5232*
thanks for your help in advance.
i did look on the web but can't find a solution that is easily understood.Hi,
855161 wrote:
thanks for responding quickly.
the link example seems not to work for me:
below is the information you have requested:Below is some of what I requested. The CREATE TABLE and INSERT statements seem to be missing.
1. duplicate values have no effect
2. list doesn't need any order
3. Version 10.2.0.5.0 For that, I recommend the user-defined aggregate function called STRING_AGG in the Oracle Base page, but called STRAGG by most of the people who use it. You have to copy and run about 60 lines of code from the Oracle Base page, or from AskTom one time, but once you have it installed, the job is as simple as
SELECT MIN (rnum) AS rnum -- ROWNUM isn't a good column name, since it's the same as a pseudo-column
, STRAGG (count_1) AS count_1_list
FROM table_x
;Hundreds of other jobs you have in the future will be just as easy, and you won't have to go through the installation process again.
Relevant information:
1. table columns : count_1
all rows should become a single row with ',' in between
example:
select * from t1;
output:
Rownum count_1
1 8217
2 6037
3 5368
4 5543
5 5232
Desired results :
Rownum count_1
1 8217, 6037, 5368, 5543, 5232
Edited by: 855161 on Dec 11, 2012 1:25 PMThe main problem with STRAGG is that it doesn't create a list in order. You said that's not an issue in this case, but if you ever do need output in order, then the best option in Oracle 10 is the SYS_CONNECT_BY_PATH technique. The main Oracle-Base page shows how to use SYS_CONNECT_BY_PATH in Oracle 9. Of course, that works in all later versions too, but in version 10 a simpler way, using CONNECT_BY_ISLEAF, became available. See the Oracle-Base Comments Page for the eaiser Oracle 10 technique. -
Convert Rows into single column
Hi,
My employee details table has data like below,
employee_id position department
100 technician 50
100 IT 80
101 Accountant 60
101 Accounting Manager 70
Now i want to covert the rows into column. So my output should be like this.
output:
employee_id position department position1 department1
100 technician 50 IT 80
101 Accountant 60 Accounting Manager 70
Help me on this
Edited by: Vi on Mar 22, 2012 5:36 AM
Edited by: Vi on Mar 22, 2012 5:36 AMIgor.M wrote:
http:// website link removed /t_converting_rows_columns.htm
Please don't post links to commercial websites that are only trying to sell their products and services. It breaches the terms of use of the forums.
There are usually more suitable websites giving much more valuable information without all the self promotion (google adwords etc. are acceptable), or in the case of this particular question there is a FAQ post that relates to it...
{message:id=9360005} -
I have a SQL statement which outputs a two column table with a ProjectName and a MemberFullValue, both text types values:
SELECT proj.ProjectName, lt.MemberFullValue
FROM dbo.MSP_EpmProject_UserView AS proj
LEFT JOIN [dbo].[MSPCFPRJ_IT Pillar(s)_AssociationView] AS itpillar
ON proj.ProjectUID = itpillar.EntityUID
LEFT JOIN dbo.MSP_EpmLookupTable AS lt
ON itpillar.LookupMemberUID = lt.MemberUID
Both columns can contain duplicate values and both contain text.
When there are duplicate values for 'ProjectName' I want to convert the corresponding 'MemberFullValue' values to columns. I have looked at a lot of different solutions to questions already posted, but I am not a SQL genius so I cannot get any of them to work.
Can someone help me out? Thanks.
Sounds like this to me
SELECT ProjectName,
[1] AS Value1,
[2] AS value2,
[3] AS Value3,
[4] AS Value4,
[5] AS Value5,
[6] AS Value6
FROM
SELECT ROW_NUMBER() OVER (PARTITION BY proj.ProjectName ORDER BY proj.ProjectName) AS Seq,
proj.ProjectName, lt.MemberFullValue
FROM dbo.MSP_EpmProject_UserView AS proj
LEFT JOIN [dbo].[MSPCFPRJ_IT Pillar(s)_AssociationView] AS itpillar
ON proj.ProjectUID = itpillar.EntityUID
LEFT JOIN dbo.MSP_EpmLookupTable AS lt
ON itpillar.LookupMemberUID = lt.MemberUID
)t
PIVOT (MAX(MemberFullValue) FOR Seq IN ([1],[2],[3],[4],[5],[6]))p
to make it dynamic you can use this
http://beyondrelational.com/modules/2/blogs/70/posts/10840/dynamic-pivot-in-sql-server-2005.aspx
If this is not what you're after, post some sample data and explain the required output
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
How to convert rows into single columns in Oracle?
I have table with data like shown below in Oracle database.
P_COLUMN
COLUMN_1
COLUMN_2
COLUMN_3
COLUMN_ 4
COLUMN_5
COLUMN_6
COLUMN_7
COLUMN_8
COLUMN_9
COLUMN_10
1
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
1
B1
B2
B3
B4
B5
B6
B7
B8
B9
B10
1
C1
C2
C3
C4
C5
C6
C7
C8
C9
C10
2
AA1
AA2
AA3
AA4
AA5
AA6
AA7
AA8
AA9
AA10
2
BB1
BB2
BB3
BB4
BB5
BB6
BB7
BB8
BB9
BB10
I need a query to get one row based on P_COLUMN's value i.e. for P_COLUMN =1, below should be output :-
C_1
C_2
C_3
C_4
C_5
C_6
C_7
C_8
C_9
C_10
C_11
C_12
C_13
C_14
C_15
C_16
C_17
C_18
C_19
C_20
C_21
C_22
C_23
C_24
C_25
C_26
C_27
C_ 28
C_29
C_30
C_31
1
A1
A2
A3
A4
A5
A6
A7
A8
A9
A10
B1
B2
B3
B4
B5
B6
B7
B8
B9
B10
C1
C2
C3
C4
C5
C6
C7
C8
C9
C10
2
AA1
AA2
AA3
AA4
AA5
AA6
AA7
AA8
AA9
AA10
BB1
BB2
BB3
BB4
BB5
BB6
BB7
BB8
BB9
BB10
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
NULL
i searched google and found PIVOT, CROSS JOIN etc but could not use those keyword properly.
Thanks in advance.
Note - My DB client version is 11g.Since you have 11G, here's an alternative with the PIVOT clause.
First, set up test data with up to 10 rows:
CREATE TABLE T(P1,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10) AS SELECT
1,1,2,3,4,5,6,7,8,9,10 FROM DUAL;
INSERT INTO T
WITH DATA AS (SELECT LEVEL*10 N FROM DUAL CONNECT BY LEVEL <= 9)
SELECT P1, C1+N, C2+N, C3+N, C4+N, C5+N, C6+N, C7+N, C8+N, C9+N, C10+N
FROM T, DATA;
INSERT INTO T
SELECT P1+1,C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
FROM T
WHERE C1 <= 11;
select * from t order by p1,c1;
P1
C1
C2
C3
C4
C5
C6
C7
C8
C9
C10
1
1
2
3
4
5
6
7
8
9
10
1
11
12
13
14
15
16
17
18
19
20
1
21
22
23
24
25
26
27
28
29
30
1
31
32
33
34
35
36
37
38
39
40
1
41
42
43
44
45
46
47
48
49
50
1
51
52
53
54
55
56
57
58
59
60
1
61
62
63
64
65
66
67
68
69
70
1
71
72
73
74
75
76
77
78
79
80
1
81
82
83
84
85
86
87
88
89
90
1
91
92
93
94
95
96
97
98
99
100
2
1
2
3
4
5
6
7
8
9
10
2
11
12
13
14
15
16
17
18
19
20
Now the SELECT statement using PIVOT:
SELECT * FROM (
SELECT T.*,
ROW_NUMBER() OVER (
PARTITION BY P1
ORDER BY C1,C2,C3,C4,C5,C6,C7,C8,C9,C10
) RN
FROM T
PIVOT(
MAX(C1) C1, MAX(C2) C2, MAX(C3) C3, MAX(C4) C4, MAX(C5) C5,
MAX(C6) C6, MAX(C7) C7, MAX(C8) C8, MAX(C9) C9, MAX(C10) C10
FOR RN IN (1 R1,2 R2,3 R3,4 R4,5 R5,6 R6,7 R7,8 R8,9 R9,10 R10)
P1
R1_C1
R1_C2
R1_C3
R1_C4
R1_C5
R1_C6
R1_C7
R1_C8
R1_C9
R1_C10
R2_C1
R2_C2
R2_C3
R2_C4
R2_C5
R2_C6
R2_C7
R2_C8
R2_C9
R2_C10
R3_C1
R3_C2
R3_C3
R3_C4
R3_C5
R3_C6
R3_C7
R3_C8
R3_C9
R3_C10
R4_C1
R4_C2
R4_C3
R4_C4
R4_C5
R4_C6
R4_C7
R4_C8
R4_C9
R4_C10
R5_C1
R5_C2
R5_C3
R5_C4
R5_C5
R5_C6
R5_C7
R5_C8
R5_C9
R5_C10
R6_C1
R6_C2
R6_C3
R6_C4
R6_C5
R6_C6
R6_C7
R6_C8
R6_C9
R6_C10
R7_C1
R7_C2
R7_C3
R7_C4
R7_C5
R7_C6
R7_C7
R7_C8
R7_C9
R7_C10
R8_C1
R8_C2
R8_C3
R8_C4
R8_C5
R8_C6
R8_C7
R8_C8
R8_C9
R8_C10
R9_C1
R9_C2
R9_C3
R9_C4
R9_C5
R9_C6
R9_C7
R9_C8
R9_C9
R9_C10
R10_C1
R10_C2
R10_C3
R10_C4
R10_C5
R10_C6
R10_C7
R10_C8
R10_C9
R10_C10
1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 -
How to Convert Rows of the Columns in Multiple Columns
Hi,
I have Data in one of the table of Oracle Application.
Sample Data.....
Period_Start_date Period_Type Demand
09-22-2005 1 5
09-21-2005 1 10
09-20-2005 1 5
09-19-2005 1 2
09-18-2005 1 20
09-17-2005 1 19
09-16-2005 1 3
Output Required.
Period 6 Period 5 Period 4 Period 3 Period 2 Period 1 Current
3 19 20 2 5 10 5
This need to be Done in Using SQL Statement.
On the base of Current Date enter by the User ...it will pickup last six date and Demand on that Date in Required Format.
Pls Do let me know Any more Clarification
Pls can any body Help me
Regards
RoshanCREATE TABLE t1
( col1 VARCHAR2(10),
col2 VARCHAR2(100)
INSERT INTO t1 VALUES('A','123,456,789');
INSERT INTO t1 VALUES('B','012,345');
INSERT INTO t1 VALUES('C','678,901,234');
SELECT col1, col2, pos, pre, SUBSTR(col2, pre+1, pos-pre-1) token FROM (
SELECT row_num, col1, col2, decode(pos,0,LENGTH(col2)+1,pos) pos, pre FROM (
SELECT row_num, col1, col2, pos, nvl(LAG(pos) OVER (PARTITION BY col1 ORDER BY row_num),0) pre
FROM (
SELECT row_num, vw.col1, vw.col2, INSTR(vw.col2,',',1,row_num) pos
FROM (
SELECT ROWNUM row_num FROM (
SELECT LEVEL FROM dual connect by LEVEL <= 5
)) r,
(SELECT col1, col2 FROM t1) vw
WHERE pos <> 0 OR pre <> 0
i think some part it may be help u also -
Query to convert Row to column - Re-posting
Hi all,
i am re-posting the same requirement, please do the needful.
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarMost repeated question in the forum..
SQL> select id,max(ltrim(sys_connect_by_path(val,','),',')) res
2 from (select id,val,
3 row_number() over(partition by id order by val) rn
4 from tb_row_2_col)
5 start with rn = 1
6 connect by prior rn = rn -1
7 and prior id = id
8 group by id;
ID RES
1 col1,col2,col3
2 col4,col5<br>
Message was edited by:
jeneesh
Check here for variations.. -
Query to convert Row to column
Hi all,
I need a query to convert row value into column delimited by ','
create table tb_row_2_col (id number,val varchar2(100));
insert into tb_row_2_col values (1,'col1');
insert into tb_row_2_col values (1,'col2');
insert into tb_row_2_col values (1,'col3');
insert into tb_row_2_col values (2,'col4');
insert into tb_row_2_col values (2,'col5');
commit;
SQL> select * from tb_row_2_col;
ID VAL
1 col1
1 col2
1 col3
2 col4
2 col5
SQL>
if i execute a query the output should be like this
ID VAL
1 col1,col2,col3
2 col4,col5
Thanks in advance
S. Sathish KumarOr look for aggregation techniques against the forum helping by the search feature (top-right of the current page).
Nicolas. -
Converting each row in a column to an XML
Hi everyone,
Using Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit
I have a table where there is a comments column which is VARCHAR2. That column contains string data in the form of XML tags.
Like for eg. *<tag_name attr_name="10"/>* (sorry cant provide the exact values as I'm not allowed to)
There are many such rows. Now I want to use these strings and operate on them as XML like using XPath to find certain attributes etc.
I tried using the extract function and to use it i need a XMLType object. So I tried to create one using the XMLType() constructor.
But it gives me the error ORA-19032: Expected XML tag , got no content
When I looked it up on the net, I found that this error number doesn't correspond to the error message that I'm getting. The error msg found on the internet was Expected XML tag string got string
I used this query
SELECT XMLType (<column>) FROM <table>;But when I modified it (based on someone's hunch) to
SELECT XMLType (<column>)
FROM <table>
WHERE ROWNUM <= 1;The query worked fine. Like it can take only one row.
I also tried like this
SELECT XMLType ('<tag_name attr_name="10"/>')
FROM DUAL;This too worked fine.
So finally this has left me completely confused. Is there a way to convert every row in a column to an XMLType object so that I can use the extract function to gather information about it.
For the time being I have used REGEXes to write the code. But having the flexibility of xml would be better.
Any help would be appreciated.
Regards,
Arijit
Edited by: Arijit Kanrar on May 23, 2013 5:27 AMArijit,
The error message is correct. What you found is merely the generic message with string placeholders.
The error message is also pretty self-explanatory : you can't pass an empty string (NULL) to the XMLType constructor.
SQL> select xmltype('') from dual;
ERROR:
ORA-19032: Expected XML tag , got no content
ORA-06512: at "SYS.XMLTYPE", line 310
ORA-06512: at line 1
no rows selectedYou have to either add a WHERE clause to filter out NULL columns, or use a CASE statement to only convert strings that aren't empty :
SELECT XMLType (<column>)
FROM <table>
WHERE <column> IS NOT NULL ;
SELECT CASE WHEN <column> IS NOT NULL THEN XMLType (<column>) END
FROM ...And do not use EXTRACT if you want to access scalar values, use EXTRACTVALUE instead :
SQL> select extractvalue(xmltype('<tag_name attr_name="10"/>'), '/tag_name/@attr_name') from dual;
EXTRACTVALUE(XMLTYPE('<TAG_NAMEATTR_NAME="10"/>'),'/TAG_NAME/@ATTR_NAME')
10 -
Converting Rows into Column in Oracle 10g
Hi All,
I m using Oracle Version 10.1.0.2.0 - Production
I have requirement to convert rows into column wise as per the following:
My Query is:
WITH t
AS ( SELECT 'A' AS x, 100 AS y FROM DUAL
UNION ALL
SELECT 'B',200 FROM DUAL
SELECT X, Y
FROM t;
X Y
A 100
B 200
My Requirement is
A B
100 200
So any one could help me that how I resolve this.
Regards,
PrasantaDear frank,
Thanks for your support,.
It's working fine for static cases.If the first column is dynamic then how come i will resolve it.
Example:
Create table mytab (ID_C Varchar2(15),Value_N Number);
Records Population into MyTab table is dynamic.
Insert into mytab values('HO',5000);
Insert Into mytab values('PG1',2400);
Insert Into mytab values('PG2',3000);
Insert Into mytab values('PG3',800);
Commit;
SQL> Select * From MyTab;
IDC_ ValueN_
HO 5000
PG1 2400
PG2 3000
PG3 800
Then My expected result will be as follows
HO PG1 PG2 PG3
5000 2400 3000 800
Thanks and Regards,
Prasanta -
How to convert row into column
Hi All,
My oracle apps version is r12 and db is 10 and i am using Bi publisher version 10g.
Is it possible to convert row into column in Rtf template,
My Query is
SELECT distinct pvs.vendor_site_code,sum(aia.invoice_amount)
FROM ap_invoices_all aia, po_vendors po, po_vendor_sites_all pvs
WHERE aia.org_id = pvs.org_id
AND aia.vendor_id = po.vendor_id
AND aia.vendor_site_id = pvs.vendor_site_id
AND aia.org_id=204
group by pvs.vendor_site_code
And output is like this
Vendor sitecode Invoiceamt
EAM-ERS 79240
STAR GATE - PAY 3245902.31
UPS - HQ 10792040.9
Like this
So in template i need the output like this
Vendor sitecode EAM-ERS STAR GATE - PAY UPS - HQ
Invoiceamt 79240 3245902.31 10792040.9
I tried to achieve the output using sql query but by hardcoding only i have achieved it, so i have tried to convert directly in RTF template.
can any one tell me is it possible.
And if new project is added from the front end ie(now the query will produce 4 rows but now in template i have created only three columns)
Is it possible to add a new column dynamically.
Can any one please guide me and tell me is there any example.
Thanks & regards
SrikkanthTake a look at this post: http://blogs.oracle.com/roller-ui/bsc/spider.jsp?entry=MT%3aENTRY%3a5001
Thanks,
Bipuser -
How to convert rows into columns with decode function
Hi,
How to convert rows into columns with the help of decode function in oracle.
thanks and regards
P Prakashsay
col1 col2
1 10
2 20
3 30
then use
select col1,
sum(decode(col2,10,10)) "new1"
sum(decode(col2,20,20))"new2"
sum(decode(col2,30,30))"new3"
from table_name
group by col1;
we used sum u can use ny function if wont u have to give the column name i.e col2 name also
so i think u got it nw
regards
Maybe you are looking for
-
How could I edit correctly my bullets in my html editor
I try to manage bullets in a simple HTML Editor. To do that, I used two differents methods but they both failed. When I look at the generated source code, my tags correcty exist but in the HTMLDocument, I can't see the text well formatted. Is anybody
-
Transparent background video object
All- I have a video with a transparent background I'd like to use in my edge file. I can load the video easily enough but, is it possible for the video loader to render a transparent background thru jquery or css? Thx
-
i want some info how to set multiple jobs simultaneously. i have one pgm which is taking much time in prod. infact that pgm updates one table and picks from that table and sends to FTP file. i have splitted those table updates into 4 parts , i mean i
-
Authn and authz issues with OUD
I have an application that supports LDAP as a means of authentication and authorization. I would like to have it use our OUD-based identity store. This is not an open system; I have no control over the client's behaviour, so any tweaking I do to make
-
Problem retreiving unicode char.
I have a database MSSQL with some fields as nvarchar. I pasted some chinese chars on it in Enterprise administrator and it works fine. but using rs.getString , results to "?????" characther. I wonder whats wrong with the app. While the chinese charac