• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Techgoeasy

Techgoeasy

Learn Oracle, PHP, HTML,CSS,Perl,UNIX shell scripts

  • Home
  • Oracle
    • Oracle database
    • Oracle Ebusiness Suite
    • Oracle weblogic
    • Oracle Performance Tuning
    • Oracle Hyperion
    • Oracle Cloud Tutorials
  • SQL
  • interview questions
  • Linux
  • PHP and HTML
  • Downloads
  • General
Home » Oracle » How to converts rows into column in Oracle table

How to converts rows into column in Oracle table

March 9, 2019 by techgoeasy Leave a Comment

Recently I encountered a oracle table which has 50 column and I need to analyze the each column for the particular row. It was tough viewing those 50 columns in the rows, So I created below PLSQL block to convert the rows into column. This takes table name as the input and print one rows in column format

set serveroutput on
declare
colname varchar2(100);
sql_str VARCHAR2(200);
col_value varchar(100);
--------- !!!! Carefully change this select state ment !!! --------------
cursor cur2 is select COLUMN_NAME from dba_tab_columns where TABLE_NAME='&1';
begin
for rec1 in cur2
loop
colname :=rec1.COLUMN_NAME;
sql_str:='select '|| colname ||' from apps.&&1 where rownum< 2';
EXECUTE IMMEDIATE sql_str into col_value;
dbms_output.put_line ( colname ||':'||col_value );
end loop;
end;
/

Filed Under: Oracle, Oracle Sql

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar



Subscribe to our mailing list

Enter your email address to subscribe to this blog and receive notifications of new posts by email

Recent Posts

  • Oracle tkprof utility
  • What is Skew in Database?
  • how to find file based on size in linux
  • SQL trace, 10046 event in Oracle
  • How to use sed replace string in file

Copyright © 2023 : TechGoEasy

  • Hire me
  • Privacy Policy
  • Contact Us
  • New? Start Here
  • About Us