?
Solved

Row to Column Conversion for Tabletype data

Posted on 2014-03-11
8
Medium Priority
?
222 Views
Last Modified: 2014-12-06
Hi All,

I have two tabletype arrays like below.

tabtype_config_option_ft.extend;
tabtype_config_option_ft(1) := 'COLOR';
tabtype_config_option_ft.extend;
tabtype_config_option_ft(2) := 'WIDTH';
tabtype_config_option_ft.extend;
tabtype_config_option_ft(3) := 'LENGTH';
tabtype_config_option_ft.extend;
tabtype_config_option_ft(4) := 'SIZE';            


tabtype_config_options.extend;
tabtype_config_options(1) := 'RED';
tabtype_config_options.extend;
tabtype_config_options(2) := '1.23';
tabtype_config_options.extend;
tabtype_config_options(3) := '4.56';
tabtype_config_options.extend;
tabtype_config_options(4) := '13';

Open in new window


My requirement is to convert this data from row to column. The expected result should be:

COLOR	WIDTH	LENGTH	SIZE
RED	1.23	4.56	13

Open in new window


Is it possible to perform the row to column conversion?

Thanks
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
8 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39920793
This is not even SQL!
It's simple array manipulation, what have you tried?
0
 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 39921341
Hi Mike,

My requirement is, I have one stored procedure with two input parameters like tabtype_config_option_ft and tabtype_config_options. I have to compare this user passed values with some of the SQL queries which is used in the procedure. Since the input data is coming as row type data I am planning to convert that into column and use it in the SQL queries and other calculations.

Usually we can do this row to column conversion if the data is stored in the tables. But here the data is stored in array's.

Thanks
0
 

Author Comment

by:Suriyaraj_Sudalaiappan
ID: 39923009
Assume that I have table data like below

OPTION_FT        OPTION_VAL
COLOR	          RED
WIDTH	          1.23
LENGTH	          4.56
SIZE	                  13

Open in new window


Now i want to convert from to column like below.

COLOR	WIDTH	LENGTH	SIZE
RED	1.23	4.56	13

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 39924010
. . . But here the data is stored in array's.
And what is so difficult about transposing an array?
Arrays are arrays, even in PL/SQL.
0
 
LVL 10

Accepted Solution

by:
dbmullen earned 1000 total points
ID: 39932686
you want to PIVOT:

select *
from my_table
pivot (max(option_val) for (option_ft) in (  
'COLOR' as col_color,
'WIDTH' as col_width,  
'LENGTH' as col_length,
'SIZE'   as col_size))
0
 
LVL 29

Assisted Solution

by:MikeOM_DBA
MikeOM_DBA earned 1000 total points
ID: 39934440
One way:
SQL> CREATE OR REPLACE TYPE Tabtype IS VARRAY (100) OF VARCHAR2 (40);
  2  /

Type created.

SQL> SET SERVEROUT ON SIZE 1000000;
SQL> DECLARE
  2     Tabtype_Config_Option_Ft Tabtype := Tabtype ();
  3     Tabtype_Config_Options Tabtype := Tabtype ();
  4     I              PLS_INTEGER;
  5     J              PLS_INTEGER;
  6  BEGIN
  7     Tabtype_Config_Option_Ft.EXTEND;
  8     Tabtype_Config_Option_Ft ( 1) := 'COLOR';
  9     Tabtype_Config_Option_Ft.EXTEND;
 10     Tabtype_Config_Option_Ft ( 2) := 'WIDTH';
 11     Tabtype_Config_Option_Ft.EXTEND;
 12     Tabtype_Config_Option_Ft ( 3) := 'LENGTH';
 13     Tabtype_Config_Option_Ft.EXTEND;
 14     Tabtype_Config_Option_Ft ( 4) := 'SIZE';
 15     Tabtype_Config_Options.EXTEND;
 16     Tabtype_Config_Options ( 1) := 'RED';
 17     Tabtype_Config_Options.EXTEND;
 18     Tabtype_Config_Options ( 2) := '1.23';
 19     Tabtype_Config_Options.EXTEND;
 20     Tabtype_Config_Options ( 3) := '4.56';
 21     Tabtype_Config_Options.EXTEND;
 22     Tabtype_Config_Options ( 4) := '13';
 23
 24     FOR I IN 1 .. Tabtype_Config_Option_Ft.COUNT
 25     LOOP
 26        DBMS_OUTPUT.Put ( Tabtype_Config_Option_Ft ( I) || CHR ( 9));
 27     END LOOP;
 28
 29     DBMS_OUTPUT.New_Line;
 30
 31     FOR I IN 1 .. Tabtype_Config_Option_Ft.COUNT
 32     LOOP
 33        DBMS_OUTPUT.Put ( Tabtype_Config_Options ( I) || CHR ( 9));
 34     END LOOP;
 35
 36     DBMS_OUTPUT.New_Line;
 37  END;
 38  /
COLOR   WIDTH   LENGTH  SIZE
RED     1.23    4.56    13

PL/SQL procedure successfully completed.

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question