Transpose of  a Table data

Hi,
i have got two tables called salary and salconfig,salary table is refering to salconfig table.
I want a result of transpose values,i.e query should display in the following format.
Empid Basic HRA DA TA
298 4500 1500 800 950
300 2300 450 800 560
my tables r
Salary
ID EMPID SALID VALUE
1 298 2 1500
2 298 1 4500
3 298 3 800
4 298 4 950
5 300 1 2300
6 300 2 450
7 300 3 800
8 300 4 560
Salconfig
ID ITEMS
1 Basic
2 HRA
3 Da
4 ta
If anybody got a query for this plz replay.Query should be a generalized one,because data in salconfig table will change dynamicaly.
Regds
Rupesh
DBA,iNetFrame

Right, so this is the key you want to run (this version allows for employees who don't qualify for everything):
SQL> SELECT s1.emp_id
  2         , s1.val AS basic
  3         , nvl(s2.val, 0) AS hra
  4         , nvl(s3.val, 0) AS da
  5         , nvl(s4.val, 0) AS ta
  6  FROM   ( SELECT x1.emp_id, x1.val FROM salary x1
  7             WHERE  1 = x1.sal_id ) s1
  8         , ( SELECT x2.emp_id, x2.val FROM salary x2
  9             WHERE  2 = x2.sal_id ) s2
10         , ( SELECT x3.emp_id, x3.val FROM salary x3
11             WHERE  3 = x3.sal_id ) s3
12         , ( SELECT x4.emp_id, x4.val FROM salary x4
13             WHERE  4 = x4.sal_id ) s4
14  WHERE  s1.emp_id = s2.emp_id(+)
15  AND    s1.emp_id = s3.emp_id(+)
16  AND    s1.emp_id = s4.emp_id(+)
17  /
    EMP_ID      BASIC        HRA         DA         TA
       298       4500       1500        800        950
       300       2300        450        800        560
       301       2100          0        800          0
SQL> Now what you want is to generate this query dynamically. I'm going to use a ref cursor. There are other approaches.
CREATE OR REPLACE FUNCTION get_remuneration RETURN sys_refcursor
AS
   sel_stmt VARCHAR2(32767);
   from_stmt VARCHAR2(32767);
   where_stmt VARCHAR2(32767);
   return_value  sys_refcursor;
BEGIN
   FOR i IN ( SELECT id, items FROM salconfig ORDER BY id ASC )
   LOOP
      -- assume every employee gets BASIC salary and it's always gonna be 1
      IF i.items = 'Basic'
      THEN
         sel_stmt := 'SELECT s1.emp_id'||chr(10)||'       , s1.val AS basic';
         from_stmt := 'FROM    ( SELECT x1.emp_id, x1.val FROM salary x1'||chr(10)||'             WHERE  1 = x1.sal_id ) s1';
         where_stmt := null;
      ELSE
         sel_stmt := sel_stmt||chr(10)||'       , nvl(s'||trim(i.id)||'.val, 0) AS "'||i.items||'"';
         from_stmt := from_stmt||chr(10)||',     ( SELECT x'||trim(i.id)||'.emp_id, x'||trim(i.id)||'.val FROM salary x'||trim(i.id)||chr(10)||'             WHERE  '||trim(i.id)||' = x'||trim(i.id)||'.sal_id ) s'||trim(i.id);
         IF where_stmt IS null
         THEN
            where_stmt := 'WHERE  ';
         ELSE
            where_stmt := where_stmt||chr(10)||'AND    ';
         END IF;
         where_stmt := where_stmt||'s1.emp_id = s'||trim(i.id)||'.emp_id(+)';
      END IF;
   END LOOP;
   OPEN return_value FOR sel_stmt||chr(10)||from_stmt||chr(10)||where_stmt; 
   RETURN return_value;
END;
/Smoke me a kipper, I'll be back before breakfast.
Cheers, APC

Similar Messages

  • How to convert a table data from rows to columns?

    Hi,
    I have a Employee table of the following format:
    Emp_id | Emp_name | Salary
    101 | James | 1000
    102 | Julia     | 2000
    I have to convert or transpose the table data as follows using a SQL statement/function -
    Emp_id | 101     |     102
    Emp_name | James |     Julia
    Salary     | 1000 |     2000
    How do I achieve this?
    Please help me.
    Thanks,
    993012
    Edited by: 993012 on Mar 11, 2013 3:26 AM

    993012 wrote:
    Hi Pavan,
    Thanks for the prompt reply.
    The link seems to be of not relevant to my question.
    My question is to clearly transpose the rows to columns and vice versa without any changes to data.
    Regards,
    993012I do not see any modification to the data in the Link posted by Pavan. Anyways, One catch with Transposing the Rows is, you need to know the Number of Columns you need to project.
    With Static SQL, there is no way to do so. Hence, you will need PL/SQL with Execute Immediate/Dynamic SQL.
    See demostration by Tom Kyte on Dynamic Pivots to have a look at the example and adapt to your situation.
    Although, I will debate on the need to do it in SQL. Because what you are upto is a part of Reporting and there are many reporting Tools which will have this functionality in-built. SQL, ideally should not be used for reporting purposes. It sole purpose it to store and pass the data to be rendered by Client Software i.e. Java or Third Party tools.

  • Create XML file from table data

    Dear All,
    with dataservice 4.0, I want to create an XML file from a table data.
    Table have a single column but more record, for example:
    0001000488;100;EUR;
    0001000489;200;EUR;
    0001000450;300;EUR;
    My desired XML output:
    <Data>
      0001000488;100;GBP;
      0001000489;200;EUR;
      0001000450;300;EUR;
    </Data>
    I try with a sample query but the sistem write only the last record in XML file:
    <Data>
      0001000450;300;EUR;
    </Data>
    Can everyone help me?
    Thank in advance.
    Simone

    Hello
    That is a very simple (also odd) XML document structure, and as such doesn't require use of the XML target.  It can be easily acheived by writing a normal file with a header and footer, which is acheived using a row_generation and a query to generate the hard coded open and close tags.
    Michael

  • Table data does not refresh

    Using LV2010.
    A table displays the test configuration that has been selected by the user.  This appeared to work fine until recently. 
    Nothing in that area of the code has changed .
    The issue is that although valid data exists on the wire and it even gets written to file, nothing is displayed in the table.
    The operator can click multiple times and nothing is displayed.  Even when running with highlight execution turned ON, the table does not get refreshed.
    Unfortunately, each time the operator click the button to insert the configuration, it does.  But it is not displayed.  The same list goes to the table.  You would expect the subsequent attempts would cause all the items to be displayed when it finally does, but no... only the last selection gets displayed.
    I've recently taken over the project and did notice that a previously working feature was not working.  That feature was to allow multiple selections to be inserted at once.  I suspect the feature still workes, but the table only displays a single line of data.
    I did find a thread that started to discuss a similar behavior with a link to a description of the bug, but that page appears to have dissappeared from the website.  It was discussed in 2005.
    Is there a way to force a refresh display on a table?  Another thought... Could it be that the table is displaying data from a portion further down the list which makes it appear as if there is no data?  As I said earlier, this section of code was not touched and it is the only area where the table data is updated and the display refreshed..
    Has anyone else seen this behavior?
    As can be seen above, the probe does "see" the data on the wire.  The screen capture was taken after the data flow had completed the entire state. The wire itself claims to have a 2D array of 1 X 11 elements.  Normally, this data would be displayed.  I can't think of why it wouldn't be displayed.  If I could, I wouldn't be posting this.. 
    I am curious if this is a LV bug...
    Attachments:
    TableDataInvisible.PNG ‏21 KB

    You know me & locals... 
    Plus the property node was used for something else.
    I fear using the VI Analyzer would... well... euh..  hummm...  how to say this,...
    blow up.. 
    LOL!! 

  • Unable to display table data in Review View

    Hi Experts,
    I have one main view and one review View .In my main view i have one table (Normal Table) and several other input feilds and text views....
    If i click on review button in my main view, am able to see all the data in review view except table data.
    How can i get the table data which i have entered in main view.. the same should display in review view.
    I binded the same node in both main and review. and node is defined under component controller.
    Any ideas?
    Regards
    Farooq.

    Hi,
    I think you already binded in review view also with same node. right? So data will move automatically and display in
    review view also. In WDDOINIT of review veiw read data from that node and use bind_Table.
    Cheers,
    Kris.

  • How to loop and read repeating table data of infoPath form in Visual studio workflow.

    Hi,
    I am trying to read info Path form repeating table data in Visual studio workflow.
    could anyone elaborate me in brief how to loop through repeating table and read all rows value one by one in workflow.
    any help would be more then welcome. 
    Thanks...

    Hi Rohan,
    According to your description, my understanding is that you want to create a Visual Studio workflow to get data from info path repeating table.
    I suggest you can submit Repeating Table to a SharePoint List and then you can create a .NET workflow to read data from the SharePoint List.
    Here are some detailed articles for your reference:
    Codeless submitting InfoPath repeating table to a SharePoint list
    Create a Workflow using Visual Studio 2010
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Excel issues with importing CSV or HTML table data from URL - Sharepoint? Office365?

    Greetings,
    We have a client who is having issues importing CSV or HTML table data as one would do using Excel's Web Query import from a reporting application.  As the error message provided by Excel is unhelpful I'm reaching out to anyone who can help us begin to
    troubleshoot problems affecting what is normal standard Excel functionality.  I'd attach the error screenshot, but I can't because my account is not verified....needless to say it says "Microsoft Excel cannot access  the file https://www.avantalytics.com/reporting_handler?func=wquery&format=csv&logid=XXXX&key=MD5
    Where XXXX is a number and MD5 is an md5 code.  The symptoms stated in the error message are:
    - the file name or path does not exist
    -The file is being used by another program
    -The workbook you are trying to save has the same name as a currently open workbook.
    None of these symptoms are the case, naturally. The user encountered this with Excel2010, she was then upgraded to Excel2013 and is still experiencing the same issue. The output of this URL in a browser (IE, Chrome, Firefox) is CSV data for the affected
    user, so it is not a network connectivity issue.  In our testing environment using both Excel2010 or 2013 this file is imported successfully, so we cannot replicate.  The main difference I can determine between our test environment and the end-user
    is they have a Sharepoint installation and appear to have Office365 as well.
    So,  my question might more appropriately be for Sharepoint or Office365 folks, but I can't be sure they're  a culprit.  Given this - does anyone have any knowledge of issues which might cause this with Sharepoint or Office365 integrated with
    Excel and/or have suggestions for getting more information from Excel or Windows other than this error message?  I've added the domain name as a trusted publisher in IE as I thought that might be the issue, but that hasn't solved anything.  As you
    can see its already https and there is no authentication or login - the md5 key is the authentication.  The certificate for the application endpoint is valid and registered via GoDaddy CA.
    I'm at a loss and would love some suggestions on things to check/try.
    Thanks  -Ross

    Hi Ross,
    >> In our testing environment using both Excel 2010 and 2013 this file is imported successfully, so we cannot replicate.
    I suspect it is caused by the difference of web server security settings.
    KB: Error message when you use Web query to a secure Web page (HTTPS://) in Excel: "Unable to open"
    Hope it will help.
    By the way, this forum is mainly for discussing questions about Office Development (VSTO, VBA and Apps for Office .etc.). For Office products feature specific questions, you could consider posting them on
    Office IT Pro forum or Microsoft Office Community.
    Regards,
    Jeffrey
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Help for Adding table data to list

    Dear Folk,
    How can i add table data to a list. I tried following but not successfull
    Populate_List('OTHER.GROUPLIST', 'GROUP_LIST');
    Help me..

    V_RECORDGROUP :=FIND_GROUP(I_RECORDGROUPNAME);
    V_QUERY:='SELECT data FROM tablea';
    V_RECORDGROUP :=CREATE_GROUP_FROM_QUERY(I_RECORDGROUPNAME,V_QUERY);
    V_TEMP:=POPULATE_GROUP(V_RECORDGROUP);
    POPULATE_LIST(I_ITEM_NAME,V_RECORDGROUP);

  • Can we delete the archived RS tables data in unix path?

    Hi Experts
    As you all know that when we perform RS table archiving we setup a Logical file path 'ARCHIVE_GLOBAL_PATH' pointing to the physical path '/usr/sap/<SYSID>/SYS/global/<FILENAME>' in unix system.
    Here we have our RS table data in the unix path and this logical path will make sure that there are no problems with requests status.
    Now our unix path has grown in size hence we would like to delete some archived data from this path. Could you pls confirm if we delete the data from this unix path will there be any problems with the requests status?
    Simply can we delete the RS table archived data from the unix file path??
    Thanks!!

    Hi All
    Any idea about this would be appreciated.
    Thanks!!

  • Problem with pl/sql table data type

    hai friends,
    i have one procedure it has some in parameters and one out parameter which fetches values to front end.
    But the out parameter will be pl/sql table data type.
    if it is ref cursor
    then i declared as
    var x refcursor;
    exec procedure_name(1,:x);
    it is ok.
    but for pl/sql table data type is out parameter then what i will do in the prompt .
    give me syntax and clarify my doubt.
    advanced thanks...
    madhava

    The SQL*Plus VARIABLE statement does not support user-defined types, hence it cannot support nested tables. It can support cursors because they can be weakly typed (so we can use the one SQL*Plus VAR to hold any shape of resultset). Nested tables are strongly typed; SQL*Plus is a relatively stupid interface and cannot be expected to understand UDT.
    So, it you want to use nested tables as output you'll need to code a wrapping procedure that can understand your nested table type and handle it accordingly.
    Sorry.
    Cheers, APC

  • Passing table data to pl sql procedure oaf

    Hi All,
    I have a requirement where i have to pass table data to plsql procedure.
    In the first page i select the REQUISITION and click on RETURN button and it will take me to the next page.
    and in the Next page i will click on APPLY button.
    When i click on APPLY, it will call the procedure and will give input to the procedure whatever has been selected when i have selected requisition.
    Please help. Please tell me the approach how to get this task done. A sample code will work.
    Hope the requirement is clear.
    Thanks in Advance.

    Hi Chinmay,
    Refer below code for Your Requirement.
    //Code For Quering Data
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    Connection conn = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
    String Query = "SELECT organization_id FROM hr_operating_units WHERE organization_id = fnd_global.org_id";
    PreparedStatement stmt = conn.prepareStatement(Query);
    resultset=stmt.executeQuery();
    while (resultset.next())
    orgId = (String)resultset.getString("ORGANIZATION_ID").toString();
    conn.commit();
    catch(Exception e)
    e.printStackTrace();
    //Code for Pass Resulted column to Procedure Input for delete Particular Record
    Execute parameterized PL SQL procedure from OAF page
    Let us try to call PL/SQL package from OAF page. We will try to remove selected line from Database.
    Package Spec
    CREATE OR REPLACE PACKAGE APPS.genpack_pkg
    AS
    PROCEDURE roll_delete_proc (orgId IN VARCHAR2);
    END genpack_pkg;
    Package Body
    CREATE OR REPLACE PACKAGE BODY APPS.genpack_pkg
    AS
    PROCEDURE roll_delete_proc (orgId IN VARCHAR2)
    AS
    BEGIN
    DELETE FROM pklist_roll_details_temp
    WHERE roll_line_id = orgId;
    COMMIT;
    END roll_delete_proc;
    END genpack_pkg;
    //in Controller PFR
    import java.sql.CallableStatement;
    if (pageContext.getParameter("ActionsButton") != null)
    String val = pageContext.getParameter("ActionsChoice");
    if ("DELLN".equals(val))
    CallableStatement cstmt = null;
    for (OAViewRowImpl row = (OAViewRowImpl)tempvo.first(); row != null; row = (OAViewRowImpl)tempvo.next()) {
    if ((row.getAttribute("Selectflag") == null) ||
    (!row.getAttribute("Selectflag").toString().equals("Y"))) continue;
    try {
    int rollid = Integer.parseInt((String)row.getAttribute("orgId"));
    Connection conn = am.getOADBTransaction().getJdbcConnection();
    if (rollid == 1)
    temphm.put(row.getAttribute("orgId").toString(), row.getAttribute("PoNumber").orgId());
    tempvo.removeCurrentRow();
    else
    try
    StringBuilder sb = new StringBuilder();
    sb.append(rollid);
    String strI = sb.toString();
    System.out.println("Inside else in delete");
    cstmt = conn.prepareCall("{call GENPACK_PKG.tpc_roll_delete_proc(?)}");
    cstmt.setString(1, strI);
    System.out.println("Oracle Callable Statment Execution Init for Delete");
    cstmt.execute();
    catch (SQLException e) {
    throw new OAException(e.toString(), (byte)0);
    }tempvo.removeCurrentRow();
    catch (OAException e) {
    throw new OAException("No row selected", (byte)3);
    Thanks,
    Dilip

  • To export and import oracle 11g table data only

    Hi Gurus,
    Just not sure of the procedure to follow in the export just the table data and then truncate the table do some changes(not table structure changes ) and then import the same table data in to the relevent table .
    Could some please help me in the setps involved in it .
    Thanks a Lot in advance

    If you can use Data Pump, here are your commands:
    expdp table_owner/password directory=<your_directory> dumpfile=table_name.dmp tables=table_name content=data_only
    impdp table_owner/password directory=<your_directory> dumpfile=table_name.dmp tables=table_name table_exists_action=append
    Data Pump requires version 10.1 or later.
    Dean

  • PO ref i need Table Data from GR,IR & Account Document Numbers

    Hi Fi/Co Family Please give me valuable suggestion ,
    Through PO Number we will get GR Number in TC: ME23, how can I get from table data with reference PO to GR, IR and Accounting Document Numbers.
    Regards,
    Venkat

    hi
    if ur problem is to find the document number only, then go to tcode me23n and give ur PO number and click on PO history tab on item details.
    hope it works.award if useful.

  • Unable to edit table data, but not for all tables

    I have multiple tables in a schema. For some tables, I am able make edits to table data directly, i.e., context menu Table | Open, and the Data tab. When I am able to edit, I do get a pencil icon inside the cell I am editing/typing (and am able to commit the changes). When I am not able to edit, it does nothing (no error messages, sound, or visual cue). I thought it had to do with who owns the table object, but I log in as the same owner of the affected table objects.
    Any pointers would be greatly appreciated so I am equipped when asking the DBA.
    Thanks,
    OS: Windows XP Professional SP2
    Java(TM) Platform: 1.6.0_11
    Oracle IDE: 2.1.1.64.45
    Versioning Support: 2.1.1.64.45
    Edited by: New2OWB10gR2 on Jun 23, 2010 12:20 PM

    Hello again,
    Here you are the DDL of the offending table:
    CREATE TABLE "DBADMEX"."T50SEC82"
    "COD_EMPRESA" CHAR(4 BYTE) DEFAULT ' ' NOT NULL ENABLE,
    "COD_EMPR_CONT" CHAR(4 BYTE) DEFAULT ' ' NOT NULL ENABLE,
    "COD_SECT_CONT" CHAR(2 BYTE) DEFAULT ' ' NOT NULL ENABLE,
    "NUM_CUEN_CONT" CHAR(18 BYTE) DEFAULT ' ' NOT NULL ENABLE,
    "COD_PAIS" CHAR(4 BYTE) DEFAULT ' ' NOT NULL ENABLE,
    "COD_SECTOR" CHAR(6 BYTE) DEFAULT ' ' NOT NULL ENABLE
    PCTFREE 10 PCTUSED 40 INITRANS 50 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "TS_50" ;
    CREATE UNIQUE INDEX "DBADMEX"."I5000082" ON "DBADMEX"."T50SEC82"
    "COD_EMPRESA", "COD_EMPR_CONT", "COD_SECT_CONT", "NUM_CUEN_CONT"
    PCTFREE 10 INITRANS 50 MAXTRANS 255 COMPUTE STATISTICS STORAGE
    INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
    TABLESPACE "TS_50" ;
    We are using the following versions:
    Oracle database: 11.1.0.7.0
    Oracle Client: 11.2.0.1.0
    Windows (where the client runs): XP SP3 (version 5.1 Build 2600_spsp_sp3_gdr.080814-1236) in spanish.
    SQL Developer: 2.1.1.64 (MAIN-64.45)
    I think I haven't forgotten anything.
    Thanks in advance for your help!

  • Problem in converting table data into CSV file

    Hi All,
    In my Process i need to convert my error table data into csv file,my data is converted as csv file by using OdisqlUnload function,but the column headers are not converted,i use another procedure for converting column headers but iam getting below error ...
    com.sunopsis.sql.SnpsMissingParametersException: Missing parameter string.find, string.find
    SQL: import string import java.sql as sql import java.lang as lang import re sourceConnection = odiRef.getJDBCConnection("SRC") output_write=open('C:/Oracle/Middleware/Oracle_ODI2/oracledi/pro/PRO.txt','r+') myStmt = sourceConnection.createStatement() my_query = "select * FROM E$_LOCAL_F0911Z1" my_query=my_query.upper() if string.find(my_query, '*') > 0: myRs = myStmt.executeQuery(my_query) md=myRs.getMetaData() collect=[] i=1 while (i <= md.getColumnCount()): collect.append(md.getColumnName(i)) i += 1 header=','.join(map(string.strip, collect)) elif string.find(my_query,'||') > 0: header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',') else: header = my_query[7:string.find(my_query, 'FROM')] print header old=output_write.read() output_write.seek(0) output_write.write (header+'\n'+old) sourceConnection.close() output_write.close()
    And i used below code for converting.......
    import string
    import java.sql as sql
    import java.lang as lang
    import re
    sourceConnection = odiRef.getJDBCConnection("SRC")
    output_write=open('C:/Oracle/Middleware/Oracle_ODI2/oracledi/pro/PRO.txt','r+')
    myStmt = sourceConnection.createStatement()
    my_query = "select FROM E$_COMPANY"*
    *my_query=my_query.upper()*
    *if string.find(my_query, '*') > 0:*
    *myRs = myStmt.executeQuery(my_query)*
    *md=myRs.getMetaData()*
    *collect=[]*
    *i=1*
    *while (i <= md.getColumnCount()):*
    *collect.append(md.getColumnName(i))*
    *i += 1*
    *header=','.join(map(string.strip, collect))*
    *elif string.find(my_query,'||') > 0:*
    *header = my_query[7:string.find(my_query, 'FROM')].replace("||','||",',')*
    *else:*
    *header = my_query[7:string.find(my_query, 'FROM')]*
    *print header*
    *old=output_write.read()*
    *output_write.seek(0)*
    *output_write.write (header+'\n'+old)*
    *sourceConnection.close()*
    *output_write.close()*
    Any one can you help regarding this
    Edited by: 30021986 on Oct 1, 2012 6:04 PM

    This may not be an option for you but in pinch you may want to consider outputing your data to an MS Spreadsheet, then saving it as a CSV. It's somewhat of a cumbersome process, but it will get you by for now.
    You will need to change your content type to application/vnd.ms-excel.
    <% response.setContentType("application/vnd.ms-excel"); %>

Maybe you are looking for