Columns to rows in oracle 10g

Hi,
  I need the output from columns to rows in oracle 10g.
this is my original output using some select query,
select a.created_by,b.modified_by from created_tp a,modified_tp b where a.col_id=b.col_id.
created_by       modified_by
Siva                 Raja
but i need this same output by rows like
user--anything fine
Siva
Raja
Thanks
Siva

Hi,
select case l when 1 then a.created_by
else b.modified end
from created_tp a,modified_tp b, (select level l from dual connect by level <= 2)
where a.col_id=b.col_id.

Similar Messages

  • Converting Columns to rows in Oracle 10g

    Hi
    i need hint to convert rows to columns.i had given the data strucure and expected output
    Source Table
    BU_ID     Prod_id     total_clients   Tot_men        Totwomen
    101        AAA           85              50          35
    101        BBB           40              20          20Expected Output
    BU_ID  Prod_id    Clint_info          Values
    101      AAA          total_clients      85
    101      AAA          Tot_men          50
    101      AAA          totwomen        35
    101      BBB           total_clients      40
    101      BBB           tot_men          20
    101      BBB           totwomen        20Thanks
    Edited by: Sami on Aug 1, 2012 8:25 PM

    Hi,
    Cross-join your table with a Counter Table , a table (or result set, as in the example below) that counts from 1 up to the number of columns you want to unpivot, like this:
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL <= 3     -- Number of columns to be unpivoted
    SELECT       s.bu_id
    ,       s.prod_id
    ,       CASE  c.n
              WHEN  1  THEN  'total_clients'
              WHEN  2  THEN  'total_men'
              WHEN  3  THEN  'total_women'
           END          AS client_info
    ,       CASE  c.n
              WHEN  1  THEN  total_clients
              WHEN  2  THEN  total_men
              WHEN  3  THEN  total_women
           END          AS values
    FROM            source_table  s
    CROSS JOIN     cntr           c
    ORDER BY  s.bu_id
    ,            s.prod_id
    ,       c.n
    ;If you'd care to post CREATE TABLE and INSERT statements for your sample data, then I could test this.
    The values column that you create can only have 1 data type. If the original, unpivoted columns have different data types, you may need to convert some of them in the CASE expression that defines values.

  • Columns Display Support in Oracle 10g Express Edition..................

    I am working with the Oracle 10g Express Edition, and I Created a Table with 52 Fields and even successfully inserted data into the table via Java Program. But the problem is when I am displaying the table from the Oracle 10g Express Edition Interface, it is displaying only first 31 Fields and displaying "<div class="fielddata">First 31 columns displayed.</div>". What should i do if I want to display all the 52 columns. Awaiting for the Reply. Thank You..

    duplicate post
    Columns Display Support in Oracle 10g Express Edition..................

  • Converting column data into rows in oracle 10g

    sample data:
    PATID NA2     NA3     NA4     
    1     3     4     5     
    1     34     45     56     
    1     134     245     356     
    2     134     245     356     
    2     334     275     56     
    2     4     275     56     
    2     4     5     56     
    how to display the above data like
    PATID NA2 NA3 NA4
    1 ID1 ID2 ID3 ID4 ID1 ID2 ID3 ID4 ID1 ID2 ID3 ID4
    3 34 134 4 45 245 5 56 356
    2 134 134 4 4 245 275 275 5 356 56 56 56

    Many examples are here:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    (and you can do a search on this forum as well to find more)
    edit
    Your sample data is not very clear, by the way.
    Please post a CREATE TABLE and some INSERT statements, just enough to put up the testcase.
    Use the tag before and after posting examples, so formatting will be maintained.
    See the [FAQ|http://forums.oracle.com/forums/help.jspa] for more information regarding tags (scroll a bit down)...
    Edited by: hoek on Jan 26, 2010 5:23 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Auto-increment  identity column through procedure in oracle 10g on windows

    Hi,
    I need identity primary key which should be auto increment before while inserting data into table.
    for this i had use sequence and then trigger to increment it.
    but now i need to increment it in Procedure, while my procedure is having code to insert data in same table which has primary key

    Hi,
    SNEHA RK wrote:
    Hi,
    I need identity primary key which should be auto increment before while inserting data into table.
    for this i had use sequence and then trigger to increment it.Right. Some database products have auto-increment columns, and they are really handy. Unfortunately, Oracle does not have auto-increment columns. A sequence is an auto-increment object, and it's the right way to automatically generate unique identifiers, but you need to explicity reference the sequence, either in you DML statements, or in a trigger that will automatically fire before a DML statement.
    but now i need to increment it in Procedure, while my procedure is having code to insert data in same table which has primary keyAre you saying that you need to increment the sequence, completely aside from INSERTing into the table?
    If so, just reference sequence_name.NEXTVAL wherever you want to. In PL/SQL, you can say
    SELECT  sequence_name.NEXTVAL
    INTO    number_variable
    FROM    dual;This works in any version of Oracle, but starting in Oracle 11, you also have the option of referencing te sequence without using dual, or any other table.
    I hope this answers your question.
    If not, post a complete script that people can run to re-create the problem and test their ideas.
    For example:
    -- Here are the table and the seqauence that I created:
    CREATE TABLE table_x ...
    CREATE SEQUENCE ...
    -- Here is the BEFORE INSERT trigger I wrote:
    CREATE OR REPLACE TRIGGER ...
    -- The trigger works exactly how I want it to in statements like this:
    INSERT INTO table_x ...
    -- So there are no problems (that I know of) with anything up to this point.
    -- Now I want to use the same sequence to ...
    -- so that when I execute a statement like this
    -- then the next time  I add a new row to the orginal table, like this
    INSERT INTO table_x ...
    -- then the contents of table_x should be ... because ...

  • Getting the ROWIDs of non-duplicate rows in Oracle 10g

    Hi,
    given a table TAB1 in which the primary key is composed of these first 3 columns:
    ================================================
    colA____________colB_________________colC____________________colD
    ================================================
    AA-----------------------01-----------------------20080101-----------------------100
    BX-----------------------32-----------------------20050325-----------------------366
    AA-----------------------01-----------------------20080102-----------------------645
    AA-----------------------01-----------------------20080707-----------------------765
    AB-----------------------02-----------------------20080806-----------------------336
    AB-----------------------02-----------------------20080705-----------------------543
    I wish to be able to find the ROWIDs of those rows where colA||colB occurs only once in the table TAB1.
    So in the above example, I would want to know the ROWID of the row containing colA=BX and colB=32 as "BX32" occurs only once in this table (AA01 occurs 3 times, AB02 occurs twice so I'm not interested in them).
    The following does work, but it is too SLOW:
    select ROWID from TAB1 where colA||colB = (select colA||colB from TAB1 HAVING COUNT(*)=1)
    Can anyone please suggest an efficient way to find this unique ROWID value in these circumstances?
    Edited by: Nemesis on Nov 29, 2008 2:50 AM

    Thank you Walter.
    This does not give the desired result however. It compares the table, row by row with a 'mirror' of itself and says 'give me the rowid of the row where its mirror does not match itself' (correct me if I am wrong)
    (Here I added the '=' to ' AND d.ROWID = d1.ROWID);'
    SELECT D.rowid
    FROM TAB1 D
    WHERE NOT EXISTS (SELECT *
    FROM TAB1 d1
    WHERE d1.COLA = d.COLA
    AND d1.COLB = d.COLB
    AND d.ROWID = d1.ROWID);
    So it returns nothing as all rows match their mirror rows.
    However, it gave me the idea of doing the following:
    SELECT D.ROWID FROM TAB1 D WHERE (SELECT COUNT(*) FROM TAB1 D1 WHERE X.colA = D.colA AND X.colB = D.colB )=1;
    Which works, and seems a little faster than my original query, so thank you for this.

  • Column to row

    How to convert column to row in Oracle 10g.
    Input
    WB
    CB
    IT
    CARDS
    Output should be as follows.
    WB|CB|IT|CARDS

    declare
              var_result emp.ename%type := null;
    begin
         for i in (select ename from emp)
         loop
              if i.ename is not null then
                   var_result := var_result ||'|'|| i.ename ;
              else      
                   var_result := var_result ;
              end if;
         end loop;
         var_result := substr(var_result,2) ;
         dbms_output.put_line('result is: '||var_result);
    end;

  • Oracle 10g - undo management

    Guys,
    I am updating 1 million rows in Oracle 10g platform, normally when I do it in oracle 9i I run it as batch process and commit after each batch. Obviously to avoid/control undo generation. But in Oracle 10g I am told undo management is automatic and I do not need run the update as batch process.
    Is this right please throw some light on this new feature - automatic undo management
    Thanks

    Automatic undo management was available in 9i as well, and my guess is you were probably using it there. However, I'll assume for the sake of this writing that you were using manual undo management in 9i and are now on automatic.
    Automatic undo management depends upon UNDO_RETENTION, a parameter that defines how long Oracle should try to keep committed transactions in UNDO. However, this parameter is only a suggestion. You must also have an UNDO tablespace that's large enough to handle the amount of UNDO you will be generating/holding, or you will get ORA-01555: Snapshot too old, rollback segment too small errors.
    You can use the UNDO advisor to find out how large this tablespace should be given a desired UNDO retention, or look online for some scripts...just google for: oracle undo size
    Oracle 10g also gives you the ability to guarantee undo. This means that instead of throwing an error on SELECT statements, it guarantees your UNDO retention for consistent reads and instead errors your DML that would cause UNDO to be overwritten.
    Now, for your original question...yes, it's easier for the DBA to minimize the issues of UNDO when using automatic undo management. If you set the UNDO_RETENTION high enough with a properly sized undo tablespace you shouldn't have as many issues with UNDO. How often you commit should have nothing to do with it, as long as your DBA has properly set UNDO_RETENTION and has an optimally sized UNDO tablespace. Committing more often will only result in your script taking longer, more LGWR/DBWR issues, and the "where was I" problem if there is an error (if it errors, where did it stop?).
    Lastly (and true even for manual undo management), if you commit more frequently, you make it more possible for ORA-01555 errors to occur. Because your work will be scattered among more undo segments, you increase the chance that a single one may be overwritten if necessary, thus causing an ORA-01555 error for those that require it for read consistency.
    It all boils down to the size of the undo tablespace and the undo retention, in the end...just as manual management boiled down to the size, amount, and usage of rollback segments. Committing frequently is a peroxide band-aid: it covers up the problem, tries to clean it, but in the end it just hurts and causes problems for otherwise healthy processes.

  • Interchanging of Rows to Columns and Columns to Rows

    Can anyone help me in this query ....
    Interchanging of Rows to Columns and Columns to Rows in Oracle
    Ex :- Actual Data
    EmpId Ename Sal
    1 A 2000
    2 B 3000
    3 C 1000
    4 D 3000
    Query Result should be like below ::::::::::
    after Transposing [ Interchanging of Rows to Columns and Columns to Rows ]the data should come like below
    Empid 1 2 3 4
    EName A B C D
    Sal 2000 3000 1000 3000
    Thanks
    Kavitha and Sudhir

    Please see the following links
    transpose my table column
    http://asktom.oracle.com/pls/ask/f?p=4950:8:1532380262922962983::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:52733433785851
    pivot a result set
    http://asktom.oracle.com/pls/ask/f?p=4950:8:1532380262922962983::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:124812348063

  • Oracle 10g query rows to column transpose

    In oracle 10g I have table called LoginUser
    Select * from LoginUser where Day = '01-Dec-2012'
    will give me the below result
    Day, Name, Country
    1-Dec-12 , John, UK
    1-Dec12 , Cate, US
    1-Dec-12 , Prakash, India
    1-Dec-12 ,Juli, Pak
    But I want result as below
    Day, Name1, Country1, Name2, Country2, Name3, Country3, Name4, Country4
    1-Dec-12, John, UK, Cate, US, Prakash, India, Juli, Pak
    Please help
    Edited by: 975340 on Dec 6, 2012 1:48 AM
    Edited by: 975340 on Dec 6, 2012 1:50 AM

    Refer to below thread
    Re: Multiple rows into a single line in 'Single Column Table'

  • 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

  • Dynamic rows to columns oracle 10g

    Hi,
    I'm using oracle 10g. I have a requiriement where I need to show rows to columns. I have read through many posts but I couldn't find what I wanted to solve. Lots of them are using decode, since they know the values in one column.
    My table has name, value and date. I need to get values for each name at certain date (each distinct date needs to become column). I don't know the name beforehand.
    Name, Value, Date
    T1 100 06-27-2011 09:00:00
    T2 100 06-27-2011 09:00:00
    T1 200 06-27-2011 09:15:00
    T2 150 06-27-2011 09:15:00
    I would also need to use a date range. Someone can request date between 09:00:00 and 09:05:00 or 09:00:00 and 09:30:00 etc.
    I need to print
    Name, 06-27-2011 09:00:00, 06-27-2011 09:15:00
    T1 100 200
    T2 100 150
    Appreciate any advice on this.
    Edited by: user8801143 on 28-Jun-2011 08:23

    With 10g
    see http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:766825833740#2989343200346664698
    search for post on February 11, 2011 and reply on February 14, 2011
    with 11g see the pivot clause

  • Oracle 10g - Defining the column name in Non English

    Hi Experts,
    I have an exisitng application which is developed on Windows using ASP Technology and uses Oracle 10g 10.1.0.2.0.
    The application is supported with an instance of Data Base within which multiple tablespaces are created for different clients. The application is developed in such a way that some of the tables arecreated dynamically and the columns are named using the data entered through the UI.
    This application needs to be globalized now. The problem is, the column name entered through the UI can be in any language based on the client's settings and those values in turn will be used for naming the columns in the tables.
    1) Can I have the column names to be named using non english characters in Oracle 10g DB? If so,
    1.1) what should I do to configure the exisiting Oracle instance to support it?
    1.2) To what level is that configuration possible, is it per DB instance level (or) can it be done at Tablespace level. I would like to configure each tablespace to host tables with columns defined with different languages, say for example, tablespace 1 will have tables with Japaenese column names and tablespace 2 will have tables with German column names?
    2) What should I do to make my entire DB to support unicode data i.e., to accept any language strings. Currently all strings are declared as VarChar2, should I change all VarChar2 to NVarChar2 (or) is there a way to retain the VarChar2 as is and make some database wide setting?
    Please note that I do not have an option of retaining the column in English as per the Business Requirement.
    Envionment:
    OS - Windows 2003 32 bit
    Oracle 10g 10.1.0.2.0
    UI forms in ASP
    TIA,
    Prem

    1. Yes, you can.
    SQL> create table ÜÝÞ( ßàá number(10));
    Table created.
    SQL> insert into ÜÝÞ values (10);
    1 row created.1.1 and 1.2 and 2. You can choose UTF as your default character set. It allows the user of non-English characters in VARCHAR columns in your whole database. It is not per tablespace.
    SQL> create table ÜÝÞ( ßàá varchar2(100));
    Table created.
    SQL> insert into ÜÝÞ values ('âãäçìé');
    1 row created.

  • Row chaining and row migration in Oracle 10g R2/11g R2

    Hi,
    Due to the business rule changes, one of the numeric column in a large table (20 millions rows) will be expanded from number(8) to number(10). Also, the values of this column of each row will be updated from 6 digits to 10 digits. All the indexes that use this column will be dropped and recreated after update. I would like to know if there is any row chaining or row migration issue in Oracle 10g R2 /11g R2.
    Thanks for your help

    neemin wrote:
    Hi,
    Due to the business rule changes, one of the numeric column in a large table (20 millions rows) will be expanded from number(8) to number(10). Also, the values of this column of each row will be updated from 6 digits to 10 digits. All the indexes that use this column will be dropped and recreated after update. I would like to know if there is any row chaining or row migration issue in Oracle 10g R2 /11g R2.
    Thanks for your helpIt depends.
    what you do observe after TESTING against the Development DB?

  • Convert columns to row equivalent to stragg function in oracle sql

    Hi,
    Sorry i forgot my Oracle version :
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 64-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - ProductionI searched in google but i didn't found the solution.
    I looking for a function in discoverer equivalent to stragg sql function.
    Note : stragg function convert columns to rows.
    Thanks
    SELECT   deptno, stragg ('-' || ename)
        FROM emp_test
    GROUP BY deptno;
        DEPTNO STRAGG_STR                                                 
            10 -CLARK-KING-MILLER                                         
            20 -SMITH-FORD-ADAMS-SCOTT-JONES                              
            30 -ALLEN-BLAKE-MARTIN-TURNER-JAMES-WARD                      
    3 rows selected.Edited by: Salim Chelabi on 2010-01-29 08:32

    Hi again,
    *1- I created  my function in my schema.*
    CREATE OR REPLACE TYPE t_string_agg AS OBJECT
      g_string  VARCHAR2(32767),
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
         RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER,
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER
    SHOW ERRORS
    CREATE OR REPLACE TYPE BODY t_string_agg IS
      STATIC FUNCTION ODCIAggregateInitialize(sctx  IN OUT  t_string_agg)
        RETURN NUMBER IS
      BEGIN
        sctx := t_string_agg(NULL);
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateIterate(self   IN OUT  t_string_agg,
                                           value  IN      VARCHAR2 )
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := self.g_string || ',' || value;
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateTerminate(self         IN   t_string_agg,
                                             returnValue  OUT  VARCHAR2,
                                             flags        IN   NUMBER)
        RETURN NUMBER IS
      BEGIN
        returnValue := RTRIM(LTRIM(SELF.g_string, ','), ',');
        RETURN ODCIConst.Success;
      END;
      MEMBER FUNCTION ODCIAggregateMerge(self  IN OUT  t_string_agg,
                                         ctx2  IN      t_string_agg)
        RETURN NUMBER IS
      BEGIN
        SELF.g_string := SELF.g_string || ',' || ctx2.g_string;
        RETURN ODCIConst.Success;
      END;
    END;
    SHOW ERRORS
    CREATE OR REPLACE FUNCTION string_agg (p_input VARCHAR2)
    RETURN VARCHAR2
    PARALLEL_ENABLE AGGREGATE USING t_string_agg;
    SHOW ERRORS
    *2- I ran my query in my schema with sqlplus.*
    SELECT deptno,ename,sal, string_agg(ename)over(partition by deptno) AS employees
    FROM   emp_test
    order by deptno;
        DEPTNO ENAME             SAL EMPLOYEES                                        
            10 CLARK            2450 CLARK,KING,MILLER                                
            10 KING             5000 CLARK,KING,MILLER                                
            10 MILLER           1300 CLARK,KING,MILLER                                
            20 JONES            2975 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 FORD             3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 ADAMS            1100 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SMITH             800 JONES,FORD,ADAMS,SMITH,SCOTT                     
            20 SCOTT            3000 JONES,FORD,ADAMS,SMITH,SCOTT                     
            30 WARD             1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 TURNER           1500 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 ALLEN            1600 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 JAMES             950 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 BLAKE            2850 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
            30 MARTIN           1250 WARD,TURNER,ALLEN,JAMES,BLAKE,MARTIN             
    14 rows selected.
    *3- I import this function in discoverer administration*
    4- My problem :When i use the function string_agg(ename)over(partition by deptno) in discover deskto i got the error you can't use over in this place.
    Any ideas.
    Thank in advance.
    Regards Salim.

Maybe you are looking for

  • Job prints but is then stuck in queue - LaserJet P1102 with JetDirect 175x print server

    Hello, I have an unusual error happening when i try to install my P1102 through a print server. Everything installs ok and allows me to print a test page, the next document i try to print prints ok but the job remains in the queue and stays there. Af

  • Submiting report in back ground with values

    Hello all abapers,   I m working on one application where one module pool program will take input from user for user id and password. After verification, one back ground report will be scheduled by this program to change user pw and add some role in

  • E51 streaming question

    Hi all, My first post here. I have an issue when streaming audio on my E51. I am using an internet radio application. When the backlight goes out the audio streaming also stops. I have searched the setings but failed to find a method of preventing th

  • My hard drive have free space over the limit...

    Hi every one, I've a strange issue here. My HD indicate me that I've more space than it should but in «About This Mac» and «System Report» I've 36GB left. The strange thing is that there is about 217Gb of Backup? What is wrong...

  • Error Useing with LSMW recording Maintenace Plan Schesule period update

    Hi Experts, I have one quary i am using Lsmw recording methode to update schedule period of around 4000 ,aintenamce plans, i created Lsmw but it is reading when i want batch input session Overview time i get following message. please help me "LEAVE T