Transform columns in row for a table in Oracle 10g
Hi,
I am using Oracle 10g.
There is a table (example) EMPLOYEE, with following structure
IDUSER YEAR1 YEAR2 YEAR3
12345 value1 value2 value3
99999 value7 value6 value5
and I need display :
IDUSER YEAR
12345 value1
12345 value2
12345 value3
99999 value7
99999 value6
99999 value5
How can I do this with without unpivot?
Thanks
Hi,
Welcome to the forum!
One way to unpivot in any version of Orace is to cross-join your table with another table (or resut set, in ths case) that has as many rows as you need toroduce from each row of your original table.
Here's an example:
WITH cntr AS
SELECT LEVEL AS n
FROM dual
CONNECT BY LEVEL <= 3
SELECT e.iduser
, CASE c.n
WHEN 1 THEN year1
WHEN 2 THEN year2
WHEN 3 THEN year3
END AS uear
FROM cntr c
CROSS JOIN employee e
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Edited by: Frank Kulash on Apr 11, 2013 6:47 AM
Similar Messages
-
Clob Columns gettting swapped in a table in Oracle 10G
Hi Experts,
When we try to insert a data into a table having two clob columns, if the data size increases more than 1000 characters, the contents of these two clob columns getting swapped. If it is less than 1000 characters, it works fine.
We are using bea Jrockit 27.6 JDK, Oracle 10G, Hibernate2, ibatis. Oracle jdbc driver is 10.2.0.4.
Any pointers on the above would be appreciated.
Thanks in advance.
-OKcheck if it is something related to inline and outline storage.
for LOB, if the data is less than 32k they are stored inline with table data. If they are more than 32k they are stored seperately. Perhaps...
one thing you can do is to use 2 tablespaces and assign one tablespace each for CLOB column then definitely you are apart. -
Unix permission problem for external table in oracle 10g, sun solaris
Hello All,
I'm facing a problem in accessing external table which has stumped me a bit.
What I'm looking for is to use a external table with restricted permission to Others(770) on unix.
Would appreciate if someone helps me out here.
Here are the steps:
1.create directory ext_tab_dir1 as '/home/ravi/test'
2.grant read,write on directory ext_tab_dir1 to scott
3.CREATE TABLE scott.emp_load1(employee_number CHAR(5))
ORGANIZATION EXTERNAL (
type oracle_loader
default directory ext_tab_dir1
access parameters (
records delimited by newline
fields terminated by ' '
optionally enclosed by '"'
missing field values are null
location ('info.dat')
Now I have added unix user oracle to unix group myDbGroup and provided myDbGroup read/write/exec permission on directory /home/ravi/test.
info.dat has been placed in /home/ravi/test.
#pwd
/home/ravi
#ls -l
drwxrwx--- 2 ravi myDbGroup 512 Mar 7 17:35 test
I have manually logged in as user oracle and successfully created a sample file in /home/ravi/test.
-rwxrwx--- 1 ravi myDbGroup 13 Mar 7 17:33 info.dat
-rw-r--r-- 1 oracle oinstall 0 Mar 7 18:05 sampleFile
I then connect to the db using sqlplus as ravi and do a
#select * from scott.emp_load1
I get the following error
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04063: unable to open log file emp_load1_18567.log
OS error Permission denied
ORA-06512: at "SYS.ORACLE_LOADER", line 19
After this, I gave full permission to /home/ravi/test
drwxrwxrwx 2 ravi myDbGroup 512 Mar 7 17:35 test
#select * from scott.emp_load1
And this was successful.
It created a log file in /home/ravi/test
-rwxrwx--- 1 ravi myDbGroup 13 Mar 7 17:33 info.dat
-rw-r--r-- 1 oracle oinstall 0 Mar 7 18:05 sampleFile
-rw-r--r-- 1 oracle oinstall 0 Mar 7 18:05 emp_load1_18567.log
Now what stumped me is the owner and group owner of the file emp_load1_18567.log.
It is same as the sampleFile which I created manually!!
From this it can be deducted oracle is not using user id oracle while reading/writing to the unix directory but somehow assigning user id oracle as owner to the log file at the end.
If someone has encountered this problem earlier or has some info about this...pls share.
Regards,
RavinandanThanks for the reply.
I have earlier checked this with NOLOGFILE option.
But no luck.
I would like to add one more detail(which I missed earlier) about the problem.
If I give 750 access to /home/ravi(That is read/exec to Group and none perm to Others),
I will get the same error(KUP-04063: unable to open log file emp_load1_18567.log).
This obviously means oracle is not even able to access the directory(Although unix user oracle has access via the group perms). -
I have a requirement in which I need to write a query for transforming the columns to rows.
Input table (DB - 11g)
========
ORDER_ID HOME_NUM WORK_NUM MOBILE_NUM FAX_NUM
100 999456901 <null> 334054483 <null>
101 <null> <null> <null> 787372163
102 587372163 943528985 642344352 677676666
103 53522890 <null> <null> <null>
104 <null> 83366656 956656655 <null>
decode the contact numbers like this, HOME_NUM = 1, WORK_NUM = 2, MOBILE_NUM = 3 and FAX_NUM = 4 and insert as phone_type_cd with the corresponding number. Output should be
ORDER_ID phone_type_cd contact_num
100 1 999456901
100 3 334054483
101 4 787372163
102 1 587372163
102 2 943528985
102 3 642344352
102 4 677676666
103 1 53522890
104 2 83366656
104 3 956656655
Edited by: sarvan on Jul 12, 2011 6:09 AMHi,
Another way is to cross-join your table to a table (or a result set, as I ded below) that contains one row fro every possible phone_type:
WITH cntr AS
SELECT LEVEL AS phone_type
FROM dual
CONNECT BY LEVEL <= 4
SELECT i.order_id
, c.phone_type
, CASE c.phone_type
WHEN 1 THEN i.home_num
WHEN 2 THEN i.work_num
WHEN 3 THEN i.mobile_num
WHEN 4 THEN i.fax_num
END AS contact_num
FROM cntr c
CROSS JOIN input_table i
WHERE CASE c.phone_type
WHEN 1 THEN i.home_num
WHEN 2 THEN i.work_num
WHEN 3 THEN i.mobile_num
WHEN 4 THEN i.fax_num
END IS NOT NULL
ORDER BY i.order_id
, c.phone_type
;The query above will work in Oracle 9 (and up), but starting in Oracle 11 there's a better way: SELECT ... UNPIVOT .
If input_table consists of only the columns you posted:
SELECT *
FROM input_table
UNPIVOT ( contact_num
FOR phone_type IN ( home_num AS 1
, work_num AS 2
, mobile_num AS 3
, fax_num AS 4
ORDER BY order_id
, phone_type
;Edited by: Frank Kulash on Jul 12, 2011 9:31 AM -
Hi, I would like transform columns to rows.
i.e. source table:
colA colB colC colD colE colX
aa bb cc dd ee 1
ff gg hh ii jj 2
..and output table-solution:
colText colValue colX
colA aa 1
colB bb 1
colC cc 1
colD dd 1
colE ee 1
colA ff 2
colB gg 2
colC hh 2
colD ii 2
colE jj 2
It's possible do it only with select - it would be the best solution.
Thanks zdenek T.Here is another way.
SQL> DESC MYTABLE
Name Null? Type
COLA VARCHAR2(20)
COLB VARCHAR2(20)
COLC VARCHAR2(20)
COLD VARCHAR2(20)
COLE VARCHAR2(20)
COLX VARCHAR2(20)
SQL> SELECT * FROM MYTABLE;
COLA COLB COLC
COLD COLE COLX
aa bb cc
dd ee 1
ff gg hh
ii jj 2
1 SELECT COLUMN_NAME,DECODE(COLUMN_ID,1,COLA,2,COLB,3,COLC,4,COLD,5,COLE),COLX
2 FROM MYTABLE M,USER_TAB_COLUMNS U
3 WHERE TABLE_NAME = 'MYTABLE'
4 AND COLUMN_NAME <> 'COLX'
5* ORDER BY 2,3
SQL> /
COLUMN_NAME DECODE(COLUMN_ID,1,C COLX
COLA aa 1
COLB bb 1
COLC cc 1
COLD dd 1
COLE ee 1
COLA ff 2
COLB gg 2
COLC hh 2
COLD ii 2
COLE jj 2
10 rows selected. -
Multiple header rows for one table?
Using html it's possible to set up multiple table header rows for one table but with APEX Reports I don't see how to implement this. Any ideas?
I want to use the second header row to provide links to data for the column only (not a row). But I still want sortable columns so I want to maintain the default column header behavior too.
Thanks,
LindaMike,
I tried that and found that indeed the substitution string is working and shows in both debug regions I set up on each page I tested.
I have tried this on two kinds of pages. It works correctly on standard pages with PPR report regions.
It is not working correctly on a page based on Carl's tabbed regions with PPR reports. One click and the header disappears. This is the version I really want to get working.
I'd like to post something but have asked twice for a space on apex.oracle.com and have yet to receive even an email acknowledging my request.
Perhaps you can help me get a space?
My new problem on the tabbed page where my multiple headers are working is that when I click on a link in the header, it loads that page below the tab. But if I now click on the tab again, rather than return to the original tab page, I get error "ERR-1777: Page 4042 provided no page to branch to. Please report this error to your application administrator. " This happens on both the tabbed regions pages and on the standard tabbed pages. I guess I need to provide a differently formatted url? It is currently like this -
-----------------------"<th id="opt-details1" [a href="f?p=&APP_ID.:3001:&APP_SESSION.:::::"] View Details</a></th>" --------------[not really square brackets but I didn't know how to make this show in the forum with proper <> brackets ----------------------
Thanks again,
Linda
---sorry for the lack of white space. It seems to happen when I post on forums on Sunday nights - all white space is removed. -
How to get count of rows for a table?
Hi,
How to get count of rows for a table and secondly, how can i have access to a particular cell in a table?
Regards,
DevashishHi Devashish,
WdContext.node<Your_node_name>().size() will give you the no: of rows.
This should be the node that is bound to the table's datasource property.
WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value); will select the row at that particular index.
You can access an attribute of a particular row as
WdContext.node<Your_node_name>().get<node_name>ElementAt(index_value).get<attribute_name>();
Hope this helps,
Best Regards,
Nibu.
Message was edited by: Nibu Wilson -
How to limit rows for a table?
Hi,
does anyone knows a good way to limit the number of rows for a table?
thanks
aldoYou can limit the number of rows using a trigger. Below is quick and dirty example that has not been fully tested.
test@ORCL> create table rowlimit (col1 number);
Table created.
Elapsed: 00:00:00.34
test@ORCL> create or replace trigger limit_rows
2 before insert
3 on rowlimit
4 declare
5 v_count number;
6 begin
7 select count(*)
8 into v_count
9 from rowlimit;
10
11 if v_count >= 4 then
12 raise_application_error(-20000, 'Table can have no more then 4 rows');
13 end if;
14 end;
15 /
Trigger created.
Elapsed: 00:00:00.09
test@ORCL> insert into rowlimit values(1);
1 row created.
Elapsed: 00:00:00.03
test@ORCL> insert into rowlimit values(2);
1 row created.
Elapsed: 00:00:00.00
test@ORCL> insert into rowlimit values(3);
1 row created.
Elapsed: 00:00:00.00
test@ORCL> insert into rowlimit values(4);
1 row created.
Elapsed: 00:00:00.00
test@ORCL> insert into rowlimit values(5);
insert into rowlimit values(5)
ERROR at line 1:
ORA-20000: Table can have no more then 4 rows
ORA-06512: at "TEST.LIMIT_ROWS", line 9
ORA-04088: error during execution of trigger 'TEST.LIMIT_ROWS'
Elapsed: 00:00:00.04
test@ORCL> commit;
Commit complete.
Elapsed: 00:00:00.00
test@ORCL> select count(*) from rowlimit;
COUNT(*)
4
Elapsed: 00:00:00.00
test@ORCL> -
What is the maximum number of row for a table control in LabWindows/CVI ?
I use LabWindows CVI 8.5.1 (MMI first developped in version 6.0).
In one of our many MMI, a table control contains a list of aircraft parameters.
We can add as many parameters (row) as we want but over 40 000 we observe a crash of the LabWindows CVI runtime.
Our client want to inscrease the number of parameters (row) up to 200 000 !!!
So my questions are:
What is the real maximum number of row for the table control ?
Is this maximum number of row different on LabWindows 2010 version ?
Or is there an other solution ?
ThanksGreetings,
Can you clarify what you mean by "crash"? Is there an error message thrown? Is it possible that you've consumed all of the available memory?
Please let me know.
Thanks, James Duvall
Product Support Engineer
National Instruments -
How to create view for xmltype table in oracle
hi:
Can some one help me how to create view for xmltype table in oracle?
XMLType do not have column
SemThank you !!
I read it and become very hard to implement what I want to do.
Can you give me example please?
My main goal to create view for xmltype table is to XQuery the XML data?
Do you have any other suggestion?
Please help
Ali_2 -
SSMA for migrating table from oracle to Sql server
Hi All,
I wanted to replicate oracle huge table to sql server and i am using SSMA.its helpful and fast but can we replicate the table to different name using SSMA.for example i have a table TEST and i wanted to replicate it to SQL_TEST.Can it be possible
using SSMA.
Kindly help me outHi All,
I wanted to replicate oracle huge table to sql server and i am using SSMA.its helpful and fast but can we replicate the table to different name using SSMA.for example i have a table TEST and i wanted to replicate it to SQL_TEST.Can it be possible
using SSMA.
Kindly help me out
Hello,
Same question has already been asked by you in below thead. Why you created duplicate thread ? please avoid this practice or your thread will be marked ass Spam
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/abcdfb1b-c617-453f-828d-c8e4ec266c78/ssma-for-migrating-table-from-oracle-to-sql-server?forum=sqlintegrationservices
Moderators plz merge this thread.
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers -
Retrieve data from a large table from ORACLE 10g
I am working with a Microsoft Visual Studio Project that requires to retrieve data from a large table from Oracle 10g database and export the data into the hard drive.
The problem here is that I am not able to connect to the database directly because of license issue but I can use a third party API to retrieve data from the database. This API has sufficient previllege/license permission on to the database to perform retrieval of data. So, I am not able to use DTS/SSIS or other tool to import data from the database directly connecting to it.
Here my approach is...first retrieve the data using the API into a .net DataTable and then dump the records from it into the hard drive in a specific format (might be in Excel file/ another SQL server database).
When I try to retrieve the data from a large table having over 13 lacs records (3-4 GB) in a data table using the visual studio project, I get an Out of memory exception.
But is there any better way to retrieve the records chunk by chunk and do the export without loosing the state of the data in the table?
Any help on this problem will be highly appriciated.
Thanks in advance...
-Jahedur Rahman
Edited by: Jahedur on May 16, 2010 11:42 PMGirish...Thanks for your reply...But I am sorry for the confusions. Let me explain that...
1."export the data into another media into the hard drive."
What does it mean by this line i.e. another media into hard drive???
ANS: Sorry...I just want to write the data in a file or in a table in SQL server database.
2."I am not able to connect to the database directly because of license issue"
huh?? I never heard this question that a user is not able to connect the db because of license. What error / message you are getting?
ANS: My company uses a 3rd party application that uses ORACLE 10g. And my compnay is licensed to use the 3rd party application (APP+Database is a package) and did not purchased ORACLE license to use directly. So I will not connect to the database directly.
3.I am not sure which API is you are talking about, but i am running an application of the visual studio data grid or similar kind of controls; in which i can select (select query) as many rows as i needed; no issue.
ANS: This API is provided by the 3rd party application vendor. I can pass a query to it and it returns a datatable.
4."better way to retrieve the records chunk by chunk and do the export without loosing the state of the data in the table?"
ANS: As I get a system error (out of memory) when I select all rows in a datatable at a time, I wanted to retrieve the data in multiple phases.
E.g: 1 to 20,000 records in 1st phase
20,001 to 40,000 records in 2nd phase
40,001 to ...... records in 3nd phase
and so on...
Please let me know if this does not clarify your confusions... :)
Thanks...
-Jahedur Rahman
Edited by: user13114507 on May 12, 2010 11:28 PM -
How to hide the data in particular table in oracle 10g
How to hide the data in particular table in oracle 10g
i want stepsIf its on Report u can always hide the column - Keyfigure or Selection - Display - Hide......y do u want to have it on the report if it is to be hided in the first place?
-
How to provide access to v$tables in oracle 10g to user
Hi,
can any one suggest me how to provide access to v$tables in oracle 10g to user .
its requried for auditor.
PLease help me.
regardsuser12009184 wrote:
HI have to provide access to all V$ tables
it required for configuration of new tool.
ThanksYou can grant it the select catalog role to the user. It should provide all the required access to the general v$* & dba_* views.
GRANT SELECT_CATALOG_ROLE TO USER;
Let me know if this helps.
Regards,
Rizwan -
Can we make apply join a column on which VPD policy applied in Oracle 10g
Hi,
i am planning to apply a column level security using VPD concept into Oracle 10g
but i have a one doubt.
Suppose i am going to apply a VPD policy based on user priviliges on a column DEPTNO in EMP table so whenever a particular user logs in,he will not see the deptno.But he can fetch the data from other table DEPT based on join condition EMP.DEPTNO=DEPT.DEPTNO . Is it possible can we make a join a column on which VPD polciy is applied ?
pls any idea or thought would be appreciable..
Thanks in advance
AnwarHi Anwar!
I have not tried yet, but I believe that you can do this.
However imagine the following:
A user U1 has the right to see some values in the deptno column, but not all. This is fine, and I believe that this is what you want to achieve.
A user U2 will see no records from the deptno column. This will impact your query, as your emp.deptno = dept.deptno part of the where clause will deliever no records.
So you have to be careful if this condition could apply and what the impact will be on your software.
cu
Andreas
Maybe you are looking for
-
Unable to execute an update statement using CallableStatement
Hi there, I'm trying to run an update statement from JUnit using java.sql.CallableStatement and oracle.jbo.server.DBTransaction. String updateSql = "update footable set barcol=TO_DATE('12-SEP-09','dd-MM-yy') where bazcol = 505";
-
Upgrading my old OS 8.6
Hello everyone, I'm trying to upgrade my G3 Blue and White which had this configuration: - G3 400 MHz - 256 Mb RAM - HD 6 Gb Maxtor - OS 8.6 - CD-ROM drive Now I upgrade its hardware this way: - 1 Gb RAM - HD 40 Gb Maxtor - OSX 10.3 These are the pro
-
Query: Can we write Triggers in a Packages??
Hi Al
-
TS4455 Why IMovie no longer shows all movie clips from movies from Kodak camera
I am on an IMac 10.6.8 2.16 ghz intel core 2 duo with 3 gb memory I am using IMovie 11 (9.0.4) My camera is a Kodak Playsport shooting hd video On all of over 300 videos I have shot previously IMovie worked perfectly. On the last 3 movies imported
-
Major Monitor Issues in Finder
I was getting horrible refresh problems and artifacts in Finder. Here is what it looked like... http://i36.tinypic.com/e9dyqh.jpg So I zapped the PRAM and repaired permissions, now I am getting an oversaturation in the reds and cyans. Look at the pic