Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Row to Column Conversion for Tabletype data

Posted on 2014-03-11
8
Medium Priority
?
224 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many‚Ķ
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

604 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