How to convert into columns rows

Hi all,
How to convert columns into rows.
thank you
regards
P Prakash

Whats your DB Version. If its 11g and above you can check out PIVOT and UNPIVOT clause of SELECT statement. Its a new feature of 11g.
For previous version just search this forum you will get lots of examples.

Similar Messages

  • How to convert data from rows into columns

    Hi,
    I have a sql table and the data looks like this
    GLYEAR GLMN01 GLMN02 GLMN03 GLMN04
    2007 -109712.40 6909.15 4758.72 56.88
    2007 -13411.32 19132.9 -5585.07 4362.64
    Where GLyear reprsents Year and GLMN01 is February, GLMN02 is March and so on,
    Now i want my output to be something like this which i want to insert into another table
    GLYear GLMonth GLAmount
    2007 February -109712.40
    2007 March 6909.15
    2007 April 56.88
    My new table has 3 columns, GLYear,GLMonth,GLAmount.
    Can someone please help me with the select statement on how to do this, i can work with the inserts.
    Thanks.

    I want you to check these form tread they have the same discussion as you.  They will definitely solve your problem
    http://blog.jontav.com/post/8344518585/convert-rows-to-columns-columns-to-rows-in-sql-server
    http://dba.stackexchange.com/questions/19057/convert-rows-to-columns-using-pivot-in-sql-server-when-columns-are-string-data
    http://stackoverflow.com/questions/18612326/how-to-convert-multiple-row-data-into-column-data-in-sql-server
    I hope this helps you in solving your problem. 
    Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer

  • How to convert single column into single row

    I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
    emp_id
    100
    101
    102
    102
    103
    200
    I need output like 100,101,102,103,104.........200.

    I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
    with emp as (
                 select  level emp_id
                   from  dual
                   connect by level <= 5
    select  *
      from  emp
      pivot(
            max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
       EMP_ID1    EMP_ID2    EMP_ID3    EMP_ID4    EMP_ID5
             1          2          3          4          5
    SQL>
    SY.

  • Converting multiple column rows into single column

    Hi all Below is my requirement, can you anybody help me solve it. CREATE TABLE TYPE (   c1_type  VARCHAR2 (10),   c2_type  VARCHAR2 (10),   c3_type  VARCHAR2 (10),   c4_type  VARCHAR2 (10),   c5_type  VARCHAR2 (10),   c6_type  VARCHAR2 (10),   c7_type  VARCHAR2 (10),   c8_type  VARCHAR2 (10),   c9_type  VARCHAR2 (10)); INSERT INTO TYPE     VALUES ('Region_D',             'Region_E',             'Region_F',             'Region_D',             'Region_E',             'Region_D',             'Region_M',             'Region_D',             'Region_E'); commit; Acutal output on the below query select * from type; C1_TYPE C2_TYPE C3_TYPE C4_TYPE C5_TYPE C6_TYPE C7_TYPE C8_TYPE C9_TYPE Region_D Region_E Region_F Region_D Region_E Region_D Region_M Region_D Region_E Acutal i am expecting the below output,how to make it using query or using oracle built in function. Region_D Region_D Region_D Region_D Region_E Region_E Region_E Region_F Region_M

    Hi,
    So, you want to put the column values in alphabetic order, with the earliest value in c1_type and the last in c9_type, is that it?
    The fact that you even want to do this says that this is a bad table design.  If sorting the values makes sense, then putting them all in the same column on 9 different rows (rather than 9 different columns on 1 row) makes sense.
    If you're stuck with the current design, then use SELECT ... UNPIVOT to put them on separate rows, then use the analytic ROW_NUMBER function to assign numbers 1-9 to each value, and finally use SELECT ... PIVOT to put them back into 1 row in that order.  If you're not familiar with the built-in UNPIVOT and PIVOT features, look them up in the SQL Language manual, and see the forum FAQ:
    https://forums.oracle.com/message/9362005
    If you get stuck, post your best attempt (formatted), the exact results you want (formatted), and your Oracle version (e.g. 11.2.0.2.0).
    Also, TYPE is an Oracle keyword, so it's not a good table name.  Use something like location_type instead.

  • How to convert  a column   from varchar2 into timestamp(3)

    Hi all,
    I have a date field column with varchar2 as datatype :
    date
    3/13/2011 10:22 AM
    3/13/2011 10:22 AM
    I tried this:
    select to_timestamp(date,'HH24MI') from dual;Iam getting this error:
    ORA-01858: a non-numeric character was found where a numeric was expected
    I want to convert date column to timestamp(3) column

    846773 wrote:
    I want to convert date column to timestamp(3) columnTIMESTAMP is not time column. Look at it as a date with better precision - it supports franctional part of a second. Anyway, use:
    select to_timestamp(date,'MM/DD/YYYY HH:MI AM') from dual;SY.

  • How do I locate column/row (number) selected in applescript

    I require a simple script to adjust the column widths of the current selected column only. I want to base it on a script below which I found on the internet. This script adjusts multiple column widths to the value input and adjusts the stub column to the remaining space. I would like to know how easy it is to create a script with a similar input window that adjusts the column/row selected leaving the others in tact.
    tell application "Adobe InDesign CS4"
        activate
        if class of parent of selection is not cell then
            display dialog " Do not highlight any cells " buttons " OK " default button 1 with icon caution
        else
            set monTableau to parent of parent of selection
            set NbColonnes to count columns of monTableau
            set monBlocTexte to parent text frames of selection
            set maBoiteTexte to item 1 of monBlocTexte
            set {y, x, h, l} to geometric bounds of maBoiteTexte
            set largeurBloc to (l - x)
            tell text frame preferences of maBoiteTexte
                set NumColTexte to text column count
                set largGout to text column gutter
            end tell
            display dialog "Width of columns (mm) " default answer 20
            set largeurTexte to text returned of the result
            set largcol2 to (largeurTexte as integer)
            set largcol1 to ((largeurBloc - (NumColTexte - 1) * largGout) / NumColTexte - (NbColonnes - 1) * largcol2)
            if largcol1 < 2 then
                set largcol1 to ((largeurBloc - (NumColTexte - 1) * largGout) / NumColTexte) / NbColonnes
                set largcol2 to ((largeurBloc - (NumColTexte - 1) * largGout) / NumColTexte) / NbColonnes
            end if
            set width of column (1) of monTableau to largcol1
            repeat with counter from 2 to NbColonnes
                set width of column (counter) of monTableau to largcol2
            end repeat
        end if
    end tell
    Your help will be greatly appreciated
    Thanks
    Dave Williams

    Perhaps like this:
    tell application "Microsoft Excel"
        set i to first row index of active cell
    end
    log i
    Regards,
    H

  • Sysdate - how to convert into a certain format

    Hi,
    I am trying to use sysdate as a default parameter in one of my reports and getting an error message (ORA-01843: not a valid month)...
    my sysdate is coming up in the following format (DD-MMM-YY) and is giving an error message... but when I tried the date manually in following format (MM/DD/YYYY) it worked...
    may I know how to convert sysdate into the following format MM/DD/YYYY
    thanks in advance

    my sysdate is coming up in the following format (DD-MMM-YY)
    There is no "MMM" format model. And how often does it have to be explained that 2-digit year formats are just wrong?
    Suggest you post the query or expression that is causing the error. Generally there is no reason to convert <tt>sysdate</tt> away from a <tt>DATE</tt> type for anything other than display purposes. It is more likely that the error is due to an implicit conversion of another value to <tt>DATE</tt> using a non-default or incorrect format mask.
    Also post the result of running
    select * from v$nls_parametersin the SQL Workshop.
    Edited by: fac586 on 13-Jun-2011 18:00

  • How to convert clob column to long

    Hi,
    Is there any way to convert clob column to long.
    Here below is my scenario..
    Instead of using substr function
    CREATE OR REPLACE PROCEDURE proc AS
    sql2 clob := '';
    sqlstring1 LONG;
    sqlstring2 LONG;
    sqlstring3 LONG;
    sqlstring4 LONG;
    sqlstring5 LONG;
    sqlstring6 LONG;
    sqlstring7 LONG;
    sqlstring8 LONG;
    sqlstring9 LONG;
    sqlstring10 LONG;
    BEGIN
    FOR sql1 IN (SELECT info FROM emp)
    LOOP
    sql2 := sql1.sql_string;
    sqlString1 := dbms_lob.SUBSTR(sql2, 8000, 1);
    sqlString2 := dbms_lob.SUBSTR(sql2, 8000, 8001);
    sqlString3 := dbms_lob.SUBSTR(sql2, 8000, 16001);
    sqlString4 := dbms_lob.SUBSTR(sql2, 8000, 24001);
    sqlString5 := dbms_lob.SUBSTR(sql2, 8000, 32001);
    sqlString6 := dbms_lob.SUBSTR(sql2, 8000, 40001);
    sqlString7 := dbms_lob.SUBSTR(sql2, 8000, 48001);
    sqlString8 := dbms_lob.SUBSTR(sql2, 8000, 56001);
    sqlString9 := dbms_lob.SUBSTR(sql2, 8000, 64001);
    sqlString10 := dbms_lob.SUBSTR(sql2, 8000, 72001);
    EXECUTE IMMEDIATE sqlString1 || sqlString2 || sqlString3 ||
    sqlString4 || sqlString5 || sqlString6 ||
    sqlString7 || sqlString8 || sqlstring9 ||
    sqlstring10;
    END LOOP;
    COMMIT;
    END proc;
    Any help really appreciated
    Thanks

    We cannot execute clob dynamically.That's what I said: execute immediate doesn't support CLOB!
    But you can concatenate two long's:
    SQL> DECLARE
       l_stmt1   LONG;
       l_stmt2   LONG;
    BEGIN
       l_stmt1 := RPAD ('BEGIN ', 32500, ' ');
       l_stmt2 :=
           RPAD ('  dbms_output.put_line(''Hello World'');', 32500, ' ')
           || 'END;';
       DBMS_OUTPUT.put_line ('Length of statement: '
                             || LENGTH (l_stmt1 || l_stmt2)
       EXECUTE IMMEDIATE (l_stmt1 || l_stmt2);
    END;
    Length of statement: 65004
    Hello World
    PL/SQL procedure successfully completed.So if you strip some extra spaces or try to compact your statement somehow, you might be able use above method.

  • How to Convert a Column value to Rows which has ';' as delimitter.

    COLA COLB
    1 London University; Harvard University(1947; Masters; Distinction); Stanford University(1948, Masters; Distinction); Cambridge University(1949; Graduation, First class)
    Which needs to be transformed as
    COLA COLB
    1 London University
    1 Harvard University(1947 Masters Distinction)
    1 Stanford University(1948, Masters Distinction)
    1 Cambridge University(1949 Graduation, First class)
    Thanks in Advance.
    Regards,
    Balakrishna

    maybe this example might help.
    SQL> select trim(replace(decode(c.semicolon_pos,0,substr(c.str,decode(c.lg,0,1,c.lg)),substr(c.str,decode(c.lg,0,1,c.lg),(c.semicolon_pos - c.lg))),';',null)) single_string
      2    from (select b.rn, b.str, b.semicolon_cnt, b.semicolon_pos,
      3                 nvl(lag(b.semicolon_pos) over (order by b.rn, b.str),0) lg
      4            from (select rownum rn, a.str, a.semicolon_cnt,
      5                         instr(a.str,';',1,rownum) semicolon_pos
      6                    from (select vt.str,
      7                                 (length(vt.str) - length(replace(vt.str, ';'))) semicolon_cnt
      8                            from (select '1 London University; Harvard University(1947, Masters, Distinction); Stanford University(1948, Masters, Distinction); Cambridge University(1949, Graduation, First class)' str from dual) vt) a
      9                  connect by level <= a.semicolon_cnt+1) b) c;
    SINGLE_STRING
    1 London University
    Harvard University(1947, Masters, Distinction)
    Stanford University(1948, Masters, Distinction)
    Cambridge University(1949, Graduation, First class)
    SQL>

  • S_ALR_87012078 - How to Convert into ALV

    Sir,
    My client want to down load the data or report :- { S_ALR_87012078 - Due Date Analysis for Open Items (Vendors)} in DAILY INTERVAL FORMAT .
    Hence, How can I convert this report into ALV report .
    i.e..
                          Daily intervels
    Vendors I   0-30      I   31-60   I    60-90 I 9   0-120
    100001  I
    100002  I
    100100
    Thanks & Regards

    Hello,
    There is no ALV grid control here.
    However, you have three selection options:
    Graphical
    Classical
    Object Lis
    When you say for example in graphical format: Report ==> Export, again you have three options:
    Copy report to XXL, Copy page to XXL, Object list.
    Additionally you can also do HTML export.
    However, this report will not give you number of day you want like 0-30, 31-60 etc.
    For that you need to develop your own:
    Hello,
    Note that if you are on classical GL, you cannot have profit center on vendor or customer line items.
    If you are on new GL and document splitting is active then you can have profit center on customer or vendor line items.
    The following example I have given is for customers.
    The only difference is in transaction codes. For customer you go to FDI1, for vendor you go to FKI1 (reports).
    For Customer you go to FDI4, for vendor you go to FKI4 for forms.
    Remaining all are the same.
    Go to transaction code FDI4
    Select Form Type RFFRRD20 Line item analysis
    Give your form name and description
    Structure (Two axis) - as defaulted
    Click on Create
    You will have lead column
    Delete the rows 2, 3 and 4
    Double click on column 1
    Enter the customer numbers from 1 to 999999
    First column double click (A)
    Slelect following values
    Due date analysis 1
    Days for net due date 0 to 30
    Give the short name, medium name and long text for the column.
    Repeat this step in next columns like 31 to 60, 61 to 90, 91 to 120 and 121 to 99999 days etc in other columns and select due date analysis 1. (B,C,D,E)
    Create one more column by way of formula. To create a new column you need to double click on blue line. Put formula add all five columns you have created above. (F = ABCDE)
    You prepare one more column with
    Due date analysis 2 (G)
    Now you prepare one more column add (F+G) = This will be total open items = over due and not due.
    Now go to FDI1 and prepare a report - assign the form created in FDI4 to the report.
    Characteristics you need to select are
    Account Type (Select Account Type as D for customers)
    Currency
    Customer
    Document Type
    Special G/L Ind
    Company Code
    Change the output types and options according to your requirement.
    Refer FDI2 and FDI3 for other standard reports created.
    Refer FDI5 and FDI6 for other standard forms created.
    Save your report and execute.
    Regards,
    Ravi

  • How to add dynamic columns & rows

    I want to display the data in the columns (seperated by partition) of the fieldNames I select.
    Suppose my Query is like
    Select Fax,Phone from Customers
    Now I want to display the data of Fax& Phone in two different columns & its heading as also Fax & Phone
    My code for the same is like this
    This is my Northwind.jsp
    <%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f"%>
    <%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h"%>
    <f:view>
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
        <HTML>
            <HEAD>
                <TITLE>Northwind</TITLE>
                <LINK REL = "STYLESHEET" HREF = "./css/styles.css" TYPE = "text/css">
            </HEAD>
            <BODY>
                <CENTER>
                    <TABLE BORDER = 5>
                        <TR>
                            <TH CLASS = "TITLE">
                               Northwind Database
                            </TH>
                        </TR>
                    </TABLE>
                    <P>
                    <h:panelGrid id="MainGrid" />
                    <h:dataTable binding="#{fieldList.dataTable}"
                        value= "#{fieldList.data11}"
                        var= "#{row}" border="1"
                        id="RootTable" />
                </CENTER>
            </BODY>
        </HTML>
    </f:view>My java code for the same is as follows
    public UIData getDataTable()
        javax.faces.component.UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();
        UIComponent panelGrid1= root.findComponent("MainGrid");
        UIComponent  datatable = panelGrid1.findComponent("RootTable");
        UIData dataTable= new UIData();
        UIColumn col;
        UIOutput out = null;
        Application app = FacesContext.getCurrentInstance().getApplication();
        int ctr=getCounter();
        int colCount = 1;
        for(int j = 0; j < colCount; ++j)
            out = new UIOutput();
            col = new UIColumn();
            HtmlOutputText headerComponent = new HtmlOutputText();
            headerComponent.setId("Header1"+ctr);
            col.setHeader(headerComponent);
            headerComponent.setValue(fieldName);
            ValueBinding vb = app.createValueBinding("#{data11}");
            out.setValueBinding("value", vb);
            out.setRendererType("javax.faces.Text");
            col.getChildren().add(out);
            dataTable.getChildren().add(col);
            ctr++;
        panelGrid1.getChildren().add(dataTable);
        return dataTable;
    public Result getData11()
        System.out.println("In getData11");
        try
                Context context = new InitialContext();
                Map sessionMap=FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
                FieldList flist=(FieldList)sessionMap.get("fieldList");
                DataSource dataSource =
                (DataSource)context.lookup("java:comp/env/jdbc/Northwind");
                Connection connection = dataSource.getConnection();
                Statement statement = connection.createStatement();
                String query = getQuery();
                System.out.println("In getData11 ::query::::::::"+query);
                ResultSet resultSet = statement.executeQuery(query);
                ResultSetMetaData rsmd = resultSet.getMetaData();
                int numberOfColumns = rsmd.getColumnCount();
              //  System.out.println("resultSet.getMetaData() numberOfColumns="+numberOfColumns );
               for(int ii=1;ii<=numberOfColumns;ii++)
                   System.out.println("rsmd.getColumnName(ii)::::::::"+rsmd.getColumnName(ii));
                System.out.println("numberOfColumns::::::::"+numberOfColumns);
                boolean b = rsmd.isSearchable(1);
                Result result=ResultSupport.toResult(resultSet);
                return(result);
                } catch(Exception e)
                System.out.println("Connection error "+e);
                return(null);
    }Here I am not getting the data but I am getting the header name with no data in it.
    Can Anybody tell what is wrong in the code or how it should be done.

    Hi,
    You can add columns dynamically ,
    In your bean code
    private UIColumn mycolumn = new UIColumn();
    public UIColumn getMyColumn() {
    return mycolumn ;
    public void setMyColumn(UIColumn uic) {
    this.mycolumn = uic;
    and in your jsf page
    <h:column binding="#{YourBean.mycolumn }" id="column1">
    <h:outputText value="My Value"/>
    <f:facet name="header">
    <h:outputText value="My Header"/>
    </f:facet>
    </h:column>

  • In Pages, using an Invoice Template, how do I add columns, rows, or add individual functions to cells like I would using Numbers? Is it possible? I'd rather not use numbers because the invoice has a lot of writing as well.

    Here's a sample of the invoice. I would like to automatically calculate the 'amounts', 'totals' and 'subtotals' sections.
    Is this possible? How do I do it?

    Got it!
    Select the cells you wish to either SUM, PRODUCT, COUNT, etc...
    Then, at the top of the screen, press on the INSERT heading,
    then press on the FUNCTION setting,
    then press on the actual function you are looking for,
    and it should automatically insert the function into the appropriate cell it is needed....

  • How to convert into INR

    Hi all,
    I created a program to run a report,in one column we need to fetch data from export invoice and amount is in foreign currency.
    we need to convert foreign currencies to indian currency and display in report. <removed by moderator>.
    Edited by: madhu ms on Sep 6, 2010 8:41 AM
    Moderator message: currency conversion questions = FAQ, please search before posting.
    locked by: Thomas Zloch on Sep 6, 2010 9:29 AM

    Hi friend,
    It will save time when you search before posting.
    thanks,

  • How to deactivate move columns/rows on tables obiee11

    Hi!
    I have two questions:
    1. Is possible to hide the option of next image?
    http://imageshack.us/photo/my-images/690/tabledp.jpg/
    I want to user only see table like obiee 10 and I don't want to move columns or rows...
    2. Also I want to hide information when user has the mouse in gauge chart...like next image:
    http://imageshack.us/photo/my-images/809/gaugej.jpg/
    Only for this gauge...maybe some other gauges I want to see this info...
    Thanks!

    Alex1 wrote:
    1. Is possible to hide the option of next image?
    http://imageshack.us/photo/my-images/690/tabledp.jpg/
    I want to user only see table like obiee 10 and I don't want to move columns or rows...
    No, this is not possible in OBIEE 11g. There is a bug logged for this ( Bug 10222173 - ABILITY TO DISABLE DRAG AND SORT FUNCTIONALITY OF COLUMNS )
    Regards,
    -Amith.

  • Project file how to convert into a avi

    in a project file there are many files like finale, scene1, scene2 etc.. then how to render that one

    It sounds like you are a beginner. You have to go through some training materials or you will never figure it out.
    https://helpx.adobe.com/after-effects/how-to/add-effects-motion-graphics.html

Maybe you are looking for