Query to generate report in order

Hi ,
I want to generate report in below order using sql query. In this col2, col3 and col4 will have only 1 value at time remaining will be NULL. What i want is i want to group by Axx or Bxx or Cyy in a specific order based on col2, col3 and col4. please help me
Result:
Example
col1 col2 col3 col4
100 Axx <null> <null>
200 <null> Axx <null>
300 Axx <null> <null>
400 <null> Bxx <null>
500 Bxx <null> <null>
600 <null> Cyy <null>
.........

Naga wrote:
Hi ,
I want to generate report in below order using sql query. In this col2, col3 and col4 will have only 1 value at time remaining will be NULL. What i want is i want to group by Axx or Bxx or Cyy in a specific order based on col2, col3 and col4. please help me
Result:
Example
col1 col2 col3 col4
100 Axx <null> <null>
200 <null> Axx <null>
300 Axx <null> <null>
400 <null> Bxx <null>
500 Bxx <null> <null>
600 <null> Cyy <null>
.........Thanks for not posting the original data or explaining clearly ({message:id=9360002})
It sounds like you want something like...
group by coalesce(col2,col3,col4)
order by coalesce(col2,col3,col4), col1

Similar Messages

  • Query on generating report using XMLP based on a search spec

    Hi,
    We are using XMLP reporting tool to generate reports for our application. Our requirement is to generate reports based on a search spec. Should I send this search spec as a input parameter to the FO processor? In other words, what is the exact procedure to generate reports based on a search spec? This search spec is provided at runtime.
    Thanks,
    Sudha.

    Hi Henry,
    Thank  you for your response.
    BEx query has not been created yet. we need to create accordingly and require your help in creating the same.
    Regarding reporting requirements,  User wants to have adhoc reporting  with rolling months ( 12 months or 6 months) functionality. Users want to link any KF to this rolling months dimension.
    If we can't have this, what is the alternative that we can propose to user.
    Thanks
    Akshara.

  • FIFO Query to generate report Which relates the out-quantity to in-quantity

    Dear Experts,
    I am trying to generate a report to find out the Inward documents of Items which are issued or transfered. Items are managed with FIFO. Certain Items are serially managed and certain not.
    I am using the tables OIVL, OIVE and OIVQ for getting the details.
    Now my problem is in certain situations the relation between OIVE and OIVQ returns more line items than required and not able to specifically found out the rows. (Same TreeID is used for several transactions)
    Please help
    Thanks and regards
    Ajith Gopalakrishnan

    Hi,
    This Query help you a lot as I made this query for displaying the recieve and out quantity of an item as per the date i.e. On which date you recieve how much quantity of an item and how much quantity you release of an item. and please amend the remaining transtype from the transaction table (OINM).
    In case of FIFO you know that First IN First OUT is followed so you can easily see that which item on a particular date you recieve and which item on a particular date you release...and if any more further enhancement you required then please let me know ....if will definitely make out some time to help you out.
    select distinct SUM(InQty)as InQty,SUM(OutQty)as OutQty,ItemCode,Dscription,DocDate, TransType,
    case TransType
    when '-2' then 'opening Balance'
    when '20' then 'Goods Reciept PO '
    when '59' then 'Reciept From Production/Good Reciept '
    when '15' then 'Deliveries '
    end as 'TransName'
    from (
    select ItemCode,Dscription,DocDate, InQty,OutQty,TransType from oinm ) as OINM
    group by DocDate,ItemCode,TransType,Dscription order by  docdate asc
    Thanks
    Randy

  • Urgent ; SAP Query for generating report  from BLNR ,DOCNR and oth in NEWGL

    We are posting document to 5 ledgers.There is a leading ledger and 4 non leadING ledgers. One Ledger contains the detailed information , and I need to add all the fields information when I create that report.
    We want BLNR field to be the reference for creating report.
    we have to create a report clubbing BLNR field from BKPF  , and DOCNR from FLEXA Table.
    Thanks,
    YGB

    Sorry it is BELNR not BLNR

  • How to fetch latest data from database instead of clicking on Generate report in RSRT?

    Hi all,
    We are not able to get latest data of BEx query.Everytime we have to click on Generate Report  button in RSRT for getting latest value.
    Is there any way to get latest value automatically? We are not doing any changes in query.
    When we click on Generate Report it is fetching data from Database instead of cache,so if it is possible to disable cache or any other workaround?
    We have used time(0TIME) characteristic in query as a formula variable. We have applied a condition on that variable to fetch the first record (latest value). When we click on generate report, it fetches correct value with latest time but when we run the query without generate report, it is not fetching latest value. The cube on which this query is developed, is a realtime cube.
    Regards,
    Zalak

    Once its in the request attributes it would be far better to use JSP Expression Language as well as the JSTL that Malcolm suggested So if the servlet code said:
         request.setAttribute("myList", al);Then using EL and the JSTL tags from <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> the JSP would look something like:
    <c:forEach items="${myList}" var="user">
    <TR>
       <TD><c:out value="${user.name}" /></TD>
       <TD><c:out value="${user.fname}" /></TD>
       <TD><c:out value="${user.city}" /></TD>
       <TD><c:out value="${user.cont}" /></TD>
       <TD><c:out value="${user.age}" /></TD>
    </TR>
    </c:forEach>

  • How to define the PLD of a Query generator report

    Hi All,
    I want to define the PLD of a Query Report. Currently I am Convertning it to Excel format. But my client wants it in PLD format.  so please tell me the process of defining the PLD for a Query generator Report.
    Thanks & Regards
    Pankaj Sharma.

    Hi,
    When u wrote yr query at that time save yr query
    Now yr query is save in "Query Manager"
    Open Query Manager > select yr query
    There is a button "Create Report"
    Create USer Report Window is display "define yr name" and select "Base Temple"
    once u save it double click and edit yr PLD....
    Hope it a best way to create uer PLD
    Thanks
    Kevin

  • Generating report from Backend Query in OIM

    Hi,
    I am trying to generate a report in OIM. The requirement is to generate a query that can be executed in the database to retrieve the following:
    All the users in OIM with out the access (Not in provisioned or Enabled state) to Active Directory
    I tried generating report using the out-of-box report for Resource Access List, which provides the list of users who are having access to particular resource, but there is no out-of-box report for providing report for users who do not have access to a particular resource.
    Could any one help me write such a query. I know we need to look in to many tables before we fetch the details. A sample query would be really helpful.
    Thanks

    Users who have access to specific resource - it is based on organization level, simple query that lists organizations with resources that they have access to :
    select a.act_name, o.obj_name, ap.acp_create, ap.acp_update
    from act a, acp ap, obj o
    where a.act_key = ap.act_key
    and ap.obj_key = o.obj_key
    Relation between users and organization is simple so it would be easy to you continue on your own...
    Hope this helps!

  • GRAPH in Query Generator Reports

    Hi Experts,
    I would like know what is the logic to generate graph in Query Generator report.
    you can see there is graph button in Query Generator window, if you click on this button, shows popup window with graph. i am not sure what is the logic they used to generate this graph.
    Please let me know if any one have an idea.
    Thanks in advnace.
    Regs
    kv

    Hi Gordon,
    Thanks for the quick reply,  let me check.
    Do SAP B1 have any DIAPI or UIAPI object for create graph.
    Please advise.
    Thanks
    kv

  • Cannot build the query or generate the report. WIS 30351

    I am trying to create a docuemtn using SDK. I have created a document and when I try to add dataprovider and update the document, I am facing the below error
    Cannot build the query or generate the report. WIS 30351
    http://help.sap.com/saphelpiis_sbo41sp5wi-sdk/frameset.htm?ec5645bc6fdb101497906a7cb0e91070.html
    Any help would be appreciated...

    Hi Pirabu,
    here's the required steps for what you described:
    1. Create a new report in folder with ID 12345:
         POST ../raylight/v1/documents
         request body:
            <document>
            <name>My New Doc</name>
            <folderId>12345</folderId>
            </document>
          response:
            <success>
            <message>The resource of type "Document" with identifier "54321" has been successfully created.</message>
            <id>54321</id>
            </success>
    2. use the new document ID when adding a data provider (ie universe ID is 5543)
          POST ../raylight/v1/documents/54321/dataproviders
          request body:
            <dataprovider>
            <name>Query 1</name>
            <dataSourceId>5543</dataSourceId>
            </dataprovider>
          response:
            <success>
            <message>The resource of type "Data provider" with identifier "DP0" has been successfully created.</message>
            <id>DP0</id>
            </success>
    If you are doing something different, please provide the steps you are using and the type of datasource you are adding (unv, unx, Bex query etc).
    Is the error when adding the data provider, or do you have an additional step updating the document?
    Also, what version of BI4 are you working with?
    Dan

  • Cannot build the query or generate the report - BI4.0 Dashboard on WebService Error

    Hello All,
         I am trying to create a Dashboard with WebService connections in SAP BI4.0 SP04. While running the dashboard I am receiving the error, Cannot build the query or generate the report. I have already set the refresh parameter to TRUE (bound to an excel cell and I have tried with 1 also). Back end WebI Reports of the BIWS connections are created from BEx queries through BICS connection. I have two prompts to run the Web Service and the report. Please share your thoughts regarding this.
    Thanks and Regards,
      Debajyoti Dan

    Hi All,
        I have found the issue. The problem is coming only when I am receiving prompts from BEx query and trying to use them through dashboard. I replaced these BEx prompts with the same in WebI report. Then the entire functionality started working correctly from dashboard.
    But, this is only a work around and can not be applied at all times. So I have raised a message for the same to SAP. I will update the thread based on what I receive from SAP Support.

  • Query to generate a report for incoming pending payments as per Item Group!

    Dear All,
    I need a Query to generate a report for incoming pending payments through Item Group.
    Please provide me the same.
    Thanks in advance..........................
    Edited by: Param Deshwal on Nov 22, 2011 7:11 AM

    Hi
         try this
    SELECT T0.[DocNum] as 'Invoice Number', T0.[DocDate] as 'Invoice Date', T0.[CardName], T0.[DocTotal] as 'Invoice Amount', T0.[PaidToDate] as 'Paid Amount',(T0.[DocTotal]-T0.[PaidToDate]) as 'Pending Amount',T3.[ItmsGrpnam] FROM OINV T0 Inner join inv1 t1 on t0.docentry=t1.docentry inner join oitm t2 on t2.itemcode=t1.itemcode inner join oitb t3 on t3.[ItmsGrpcod]=t2.[ItmsGrpcod] where T3.[ItmsGrpnam]=[%0] 
    Regards,
    sudhir B.
    Edited by: B.sudhir on Nov 22, 2011 7:28 AM

  • Generating report based on dynamically generated sql query

    I have to rewrite asp reports to oracle reports.
    The original application has forms in asp where reports are generated dynamically based on the options selected.
    There are many options to select.
    Some add filter criteria to where clause.
    I have no problem with this. As i can generate report using parameter form.
    whereas i don't know how to generate reports whose columns change based on the user selection.
    The front end screens are going to be in java and jsp pages. The only way i can think of is generating reports on all possible options the user may select. But, as there are more than 15 options, i think this is not the right approach.
    How can i achieve this.
    Thank you very much.
    navya.

    One method that comes to mind would be to use an after parameter form, and use lexical parameters to create dynamic statements.
    For example in your after pform:
    If :P_NAME = 'JOHN' then
    :P_SELECT = 'SELECT COL1, COL2 ';
    :P_FROM = 'FROM JOHN ';
    :P_WHERE = 'WHERE COL3 = 'JOHN';
    END IF;
    Then in your query, you could say:
    &P_SELECT
    &P_FROM
    &P_WHERE
    Something like that - If only parts of you where statement will change, you can just write that one part -
    like
    IF :P_STATE is not null then
    :P_STATE = ' and table.state = :P_STATE_IN ';
    else :P_STATE = ' and 1=1 ';
    end if;
    and in your query...
    where....
    &:P_STATE
    So IF a person enters a state, then limit the search to that state, or else do a 1=1.
    Hope this gives you a start

  • How to generate report with dynamic variable number of columns?

    How to generate report with dynamic variable number of columns?
    I need to generate a report with varying column names (state names) as follows:
    SELECT AK, AL, AR,... FROM States ;
    I get these column names from the result of another query.
    In order to clarify my question, Please consider following table:
    CREATE TABLE TIME_PERIODS (
    PERIOD     VARCHAR2 (50) PRIMARY KEY
    CREATE TABLE STATE_INCOME (
         NAME     VARCHAR2 (2),
         PERIOD     VARCHAR2 (50)     REFERENCES TIME_PERIODS (PERIOD) ,
         INCOME     NUMBER (12, 2)
    I like to generate a report as follows:
    AK CA DE FL ...
    PERIOD1 1222.23 2423.20 232.33 345.21
    PERIOD2
    PERIOD3
    Total 433242.23 56744.34 8872.21 2324.23 ...
    The TIME_PERIODS.Period and State.Name could change dynamically.
    So I can't specify the state name in Select query like
    SELECT AK, AL, AR,... FROM
    What is the best way to generate this report?

    SQL> -- test tables and test data:
    SQL> CREATE TABLE states
      2    (state VARCHAR2 (2))
      3  /
    Table created.
    SQL> INSERT INTO states
      2  VALUES ('AK')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('AL')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('AR')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('CA')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('DE')
      3  /
    1 row created.
    SQL> INSERT INTO states
      2  VALUES ('FL')
      3  /
    1 row created.
    SQL> CREATE TABLE TIME_PERIODS
      2    (PERIOD VARCHAR2 (50) PRIMARY KEY)
      3  /
    Table created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD1')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD2')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD3')
      3  /
    1 row created.
    SQL> INSERT INTO time_periods
      2  VALUES ('PERIOD4')
      3  /
    1 row created.
    SQL> CREATE TABLE STATE_INCOME
      2    (NAME   VARCHAR2 (2),
      3       PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD),
      4       INCOME NUMBER (12, 2))
      5  /
    Table created.
    SQL> INSERT INTO state_income
      2  VALUES ('AK', 'PERIOD1', 1222.23)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('CA', 'PERIOD1', 2423.20)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('DE', 'PERIOD1', 232.33)
      3  /
    1 row created.
    SQL> INSERT INTO state_income
      2  VALUES ('FL', 'PERIOD1', 345.21)
      3  /
    1 row created.
    SQL> -- the basic query:
    SQL> SELECT   SUBSTR (time_periods.period, 1, 10) period,
      2             SUM (DECODE (name, 'AK', income)) "AK",
      3             SUM (DECODE (name, 'CA', income)) "CA",
      4             SUM (DECODE (name, 'DE', income)) "DE",
      5             SUM (DECODE (name, 'FL', income)) "FL"
      6  FROM     state_income, time_periods
      7  WHERE    time_periods.period = state_income.period (+)
      8  AND      time_periods.period IN ('PERIOD1','PERIOD2','PERIOD3')
      9  GROUP BY ROLLUP (time_periods.period)
    10  /
    PERIOD             AK         CA         DE         FL                                             
    PERIOD1       1222.23     2423.2     232.33     345.21                                             
    PERIOD2                                                                                            
    PERIOD3                                                                                            
                  1222.23     2423.2     232.33     345.21                                             
    SQL> -- package that dynamically executes the query
    SQL> -- given variable numbers and values
    SQL> -- of states and periods:
    SQL> CREATE OR REPLACE PACKAGE package_name
      2  AS
      3    TYPE cursor_type IS REF CURSOR;
      4    PROCEDURE procedure_name
      5        (p_periods   IN     VARCHAR2,
      6         p_states    IN     VARCHAR2,
      7         cursor_name IN OUT cursor_type);
      8  END package_name;
      9  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY package_name
      2  AS
      3    PROCEDURE procedure_name
      4        (p_periods   IN     VARCHAR2,
      5         p_states    IN     VARCHAR2,
      6         cursor_name IN OUT cursor_type)
      7    IS
      8        v_periods          VARCHAR2 (1000);
      9        v_sql               VARCHAR2 (4000);
    10        v_states          VARCHAR2 (1000) := p_states;
    11    BEGIN
    12        v_periods := REPLACE (p_periods, ',', ''',''');
    13        v_sql := 'SELECT SUBSTR(time_periods.period,1,10) period';
    14        WHILE LENGTH (v_states) > 1
    15        LOOP
    16          v_sql := v_sql
    17          || ',SUM(DECODE(name,'''
    18          || SUBSTR (v_states,1,2) || ''',income)) "' || SUBSTR (v_states,1,2)
    19          || '"';
    20          v_states := LTRIM (SUBSTR (v_states, 3), ',');
    21        END LOOP;
    22        v_sql := v_sql
    23        || 'FROM     state_income, time_periods
    24            WHERE    time_periods.period = state_income.period (+)
    25            AND      time_periods.period IN (''' || v_periods || ''')
    26            GROUP BY ROLLUP (time_periods.period)';
    27        OPEN cursor_name FOR v_sql;
    28    END procedure_name;
    29  END package_name;
    30  /
    Package body created.
    SQL> -- sample executions from SQL:
    SQL> VARIABLE g_ref REFCURSOR
    SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2,PERIOD3','AK,CA,DE,FL', :g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         CA         DE         FL                                             
    PERIOD1       1222.23     2423.2     232.33     345.21                                             
    PERIOD2                                                                                            
    PERIOD3                                                                                            
                  1222.23     2423.2     232.33     345.21                                             
    SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2','AK,AL,AR', :g_ref)
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         AL         AR                                                        
    PERIOD1       1222.23                                                                              
    PERIOD2                                                                                            
                  1222.23                                                                              
    SQL> -- sample execution from PL/SQL block
    SQL> -- using parameters derived from processing
    SQL> -- cursors containing results of other queries:
    SQL> DECLARE
      2    CURSOR c_period
      3    IS
      4    SELECT period
      5    FROM   time_periods;
      6    v_periods   VARCHAR2 (1000);
      7    v_delimiter VARCHAR2 (1) := NULL;
      8    CURSOR c_states
      9    IS
    10    SELECT state
    11    FROM   states;
    12    v_states    VARCHAR2 (1000);
    13  BEGIN
    14    FOR r_period IN c_period
    15    LOOP
    16        v_periods := v_periods || v_delimiter || r_period.period;
    17        v_delimiter := ',';
    18    END LOOP;
    19    v_delimiter := NULL;
    20    FOR r_states IN c_states
    21    LOOP
    22        v_states := v_states || v_delimiter || r_states.state;
    23        v_delimiter := ',';
    24    END LOOP;
    25    package_name.procedure_name (v_periods, v_states, :g_ref);
    26  END;
    27  /
    PL/SQL procedure successfully completed.
    SQL> PRINT g_ref
    PERIOD             AK         AL         AR         CA         DE         FL                       
    PERIOD1       1222.23                           2423.2     232.33     345.21                       
    PERIOD2                                                                                            
    PERIOD3                                                                                            
    PERIOD4                                                                                            
                  1222.23                           2423.2     232.33     345.21                       

  • Query to generate Nested XML feed

    Hello,
    I use Oracle 11g R2 SOE....
    I have two main tables
    COMMERCIALS_PROPERTIES (com_id number PK , com_size number, project_id number, com_type number)
    COM_PHOTOS (ID number PK , com_id number FK, content blob, mimetype varchar2)
    Please, note the following has nothing to do with my problem:
    CONTENT and MIMETYPE columns. Also, the lookup tables: PROJECTS , COM_TYPE
    I Exposed a report as RESTful web service in XML format:
    I am using this query to generate the XML 1 feed, but I need to tweak the query to generate XML 2 feed.
    Is it possible, how to do it ???
    Select
    "COM"."COM_ID" as "COM_ID",
    "COM"."COM_SIZE" as "SIZE",
    "PROJECTS"."PROJECT_NAME_EN" as "PROJECT",
    "COM_TYPES"."COM_TYPE" as "COM_TYPE",
    'http://fam-erp.com/apex/erp/fateh/'||IMG.ID as "ImgURL"
    FROM
    COM_PHOTOS IMG inner join COMMERCIALS_PROPERTIES "COM"
    on   IMG.COM_ID = COM.COM_ID
    inner join "PROJECTS" "PROJECTS"
    on "PROJECTS"."PROJECT_ID"="COM"."PROJECT_ID"
    inner join "COM_TYPE_LOOKUP" "COM_TYPES"
    on "COM_TYPES"."TYPE_ID"="COM"."COM_TYPE"
    WHERE
      COM.COM_ID < 80 order by 1h1. XML 1
    h2. Please look only at <COM_ID> and <ImgURL>
    <ROWSET>
    <ROW>
    <COM_ID>77</COM_ID>
    <SIZE>842</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1410</ImgURL>
    </ROW>
    <ROW>
    <COM_ID>77</COM_ID>
    <SIZE>842</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1412</ImgURL>
    </ROW>
    <ROW>
    <COM_ID>78</COM_ID>
    <SIZE>756</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1425</ImgURL>
    </ROW>
    <ROW>
    <COM_ID>78</COM_ID>
    <SIZE>756</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1429</ImgURL>
    </ROW>
    </ROWSET>---------------------------
    h1. XML 2
    h2. Please look only at <COM_ID> and <Images> and <ImgURL>
    <ROWSET>
    <ROW>
    <COM_ID>77</COM_ID>
    <SIZE>842</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <Images>
          <ImgURL>http://fam-erp.com/apex/erp/fateh/1410</ImgURL>
          <ImgURL>http://fam-erp.com/apex/erp/fateh/1412</ImgURL>
    </Images>
    </ROW>
    <ROW>
    <COM_ID>78</COM_ID>
    <SIZE>756</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <Images>
            <ImgURL>http://fam-erp.com/apex/erp/fateh/1425</ImgURL>
            <ImgURL>http://fam-erp.com/apex/erp/fateh/1429</ImgURL>
    </Images>
    </ROW>
    </ROWSET>

    Hello,
    I see, I found another solution, but come across another problem that is the web service should get Data from more than one table. I have this procedure, and I would like to *"UNION" its* Select Statement with another Select Statement:
    declare
      v_xml clob;
      v_retval clob := '<?xml version="1.0" encoding="iso-8859-1"?>';
      v_blob blob;
    begin
    select
           xmlelement(
             "LISTINGS",
             xmlagg(
               xmlelement(
                 "LISTING",
                 xmlforest(
    'RS-'||R."RES_ID" as "Property_Ref_No",
    "UNIT_TYPE_LOOKUP"."UNIT_TYPE" as "Unit_Type",
    'Sale' as "Ad_Type",
    'Dubai' as "State",
    L.LOCATION_NAME_EN AS "Community",
    "PROJECTS"."PROJECT_NAME_EN" as "Property_Name",
    "RES_SALE"."ASKING_PRICE" as "Price",
    ' ' as "Frequency",
    ST."SUB_TYPE" as "Unit_Model",
    R."RES_SIZE" as "Unit_Builtup_Area",
    R.BEDS as "Bedrooms",
    R.bath as "No_of_Bathrooms",
    "RES_SALE"."AD_TITLE" as "Property_Title",
    RES_SALE.DESCRIPTION as "Web_Remarks",
    to_char("RES_SALE"."UPDATED_ON",'YYYY-MM-DD HH:MI:SSPM') as "Last_Updated",
    R.VIDEO as "Web_Tour",
    select xmlagg(
                                 xmlforest(
                                'http://thevillaproject.com/apex/erp/IMAGES/'||IMG.ID AS "ImageUrl"
    FROM      
          IMAGES IMG     
    WHERE IMG.RES_ID = R.RES_ID ) Images )))).getclobval()
      into      v_xml
      FROM
          "RES_SALE" "RES_SALE"
    inner join
          RES R on (R."RES_ID"="RES_SALE"."RES_ID")
    inner join
              "UNIT_STATUS_LOOKUP" on (UNIT_STATUS_LOOKUP.status_id = "RES_SALE"."RES_STATUS")
    inner join
          "PROJECTS" "PROJECTS" on ("PROJECTS"."PROJECT_ID"=R."PROJECT_ID")
    inner join
          "UNIT_TYPE_LOOKUP" "UNIT_TYPE_LOOKUP" on ("UNIT_TYPE_LOOKUP"."TYPE_ID"=R."RES_TYPE")
    inner join
          "RES_SUB_TYPE_LOOKUP" ST on (ST."SUB_TYPE_ID"=R."SUB_TYPE")
    INNER JOIN
          COMPLEX_LOOKUP CL ON (CL.COMPLEX_ID = "PROJECTS".COMPLEX_ID)
    INNER JOIN
          LOCATIONS L ON (L.LOCATION_ID = CL.LOCATION_ID)
    WHERE  "RES_SALE".RES_status IN (5,8) AND "RES_SALE".LIVE = 'Y' AND "RES_SALE".DESCRIPTION IS NOT NULL
      dbms_lob.append(v_retval,v_xml);
      OWA_UTIL.Mime_Header('text/xml'); 
      htp.p('Content-length: ' || to_char(dbms_lob.getlength(v_retval)));
      htp.p('Content-Disposition:  inline; filename="Just.xml"');
      owa_util.http_header_close;
      v_blob := wwv_flow_utilities.clob_to_blob(v_retval);
      wpg_docload.download_file(v_blob);
    end; h1. Select Statement that is needed to be "UNION-ED" with the Select Statement of the previous procedure:
    select
           xmlelement(
             "LISTINGS",
             xmlagg(
               xmlelement(
                 "LISTING",
                 xmlforest(
    'RR-'||R."RES_ID" as "Property_Ref_No",
    "UNIT_TYPE_LOOKUP"."UNIT_TYPE" as "Unit_Type",
    'Rent' as "Ad_Type",
    'Dubai' as "State",
    L.LOCATION_NAME_EN AS "Community",
    "PROJECTS"."PROJECT_NAME_EN" as "Property_Name",
    "RES_RENT"."ASKING_PRICE" as "Price",
    ' ' as "Frequency",
    ST."SUB_TYPE" as "Unit_Model",
    R."RES_SIZE" as "Unit_Builtup_Area",
    R.BEDS as "Bedrooms",
    R.bath as "No_of_Bathrooms",
    "RES_RENT"."AD_TITLE" as "Property_Title",
    "RES_RENT".DESCRIPTION as "Web_Remarks",
    to_char("RES_RENT"."UPDATED_ON",'YYYY-MM-DD HH:MI:SSPM') as "Last_Updated",
    R.VIDEO as "Web_Tour",
    select xmlagg(
                                 xmlforest(
                                'http://thevillaproject.com/apex/erp/IMAGES/'||IMG.ID AS "ImageUrl"
    FROM      
          IMAGES IMG     
    WHERE IMG.RES_ID = R.RES_ID ) Images ))))
    FROM
          "RES_RENT" "RES_RENT"
    inner join
          RES R on (R."RES_ID"="RES_RENT"."RES_ID")
    inner join
              "UNIT_STATUS_LOOKUP" on (UNIT_STATUS_LOOKUP.status_id = "RES_RENT"."RES_STATUS")
    inner join
          "PROJECTS" "PROJECTS" on ("PROJECTS"."PROJECT_ID"=R."PROJECT_ID")
    inner join
          "UNIT_TYPE_LOOKUP" "UNIT_TYPE_LOOKUP" on ("UNIT_TYPE_LOOKUP"."TYPE_ID"=R."RES_TYPE")
    inner join
          "RES_SUB_TYPE_LOOKUP" ST on (ST."SUB_TYPE_ID"=R."SUB_TYPE")
    INNER JOIN
          COMPLEX_LOOKUP CL ON (CL.COMPLEX_ID = "PROJECTS".COMPLEX_ID)
    INNER JOIN
          LOCATIONS L ON (L.LOCATION_ID = CL.LOCATION_ID)
    WHERE  "RES_RENT".RES_status IN (5,8) AND "RES_RENT".LIVE = 'Y' AND "RES_RENT".DESCRIPTION IS NOT NULL

  • SQL query to generate Nested XML

    Hello,
    I use Oracle 11g R2 SOE....
    I have two main tables
    COMMERCIALS_PROPERTIES (com_id number PK , com_size number, project_id number, com_type number)
    COM_PHOTOS (ID number PK , com_id number FK, content blob, mimetype varchar2)
    Please, note the following has nothing to do with my problem:
    CONTENT and MIMETYPE columns. Also, the lookup tables: PROJECTS , COM_TYPE
    In APEX ( Application Express ) we can expose a report as RESTful web service in XML format:
    I am using this query to generate the XML 1 feed, but I need to tweak the query to generate XML 2 feed.
    Is it possible, how to do it ???
    Select
    "COM"."COM_ID" as "COM_ID",
    "COM"."COM_SIZE" as "SIZE",
    "PROJECTS"."PROJECT_NAME_EN" as "PROJECT",
    "COM_TYPES"."COM_TYPE" as "COM_TYPE",
    'http://fam-erp.com/apex/erp/fateh/'||IMG.ID as "ImgURL"
    FROM
    COM_PHOTOS IMG inner join COMMERCIALS_PROPERTIES "COM"
    on   IMG.COM_ID = COM.COM_ID
    inner join "PROJECTS" "PROJECTS"
    on "PROJECTS"."PROJECT_ID"="COM"."PROJECT_ID"
    inner join "COM_TYPE_LOOKUP" "COM_TYPES"
    on "COM_TYPES"."TYPE_ID"="COM"."COM_TYPE"
    WHERE
      COM.COM_ID < 80 order by 1h1. XML 1
    h2. Please look only at <COM_ID> and <ImgURL>
    <ROWSET>
    <ROW>
    <COM_ID>77</COM_ID>
    <SIZE>842</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1410</ImgURL>
    </ROW>
    <ROW>
    <COM_ID>77</COM_ID>
    <SIZE>842</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1412</ImgURL>
    </ROW>
    <ROW>
    <COM_ID>78</COM_ID>
    <SIZE>756</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1425</ImgURL>
    </ROW>
    <ROW>
    <COM_ID>78</COM_ID>
    <SIZE>756</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <ImgURL>http://fam-erp.com/apex/erp/fateh/1429</ImgURL>
    </ROW>
    </ROWSET>---------------------------
    h1. XML 2
    h2. Please look only at <COM_ID> and <Images> and <ImgURL>
    <ROWSET>
    <ROW>
    <COM_ID>77</COM_ID>
    <SIZE>842</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <Images>
          <ImgURL>http://fam-erp.com/apex/erp/fateh/1410</ImgURL>
          <ImgURL>http://fam-erp.com/apex/erp/fateh/1412</ImgURL>
    </Images>
    </ROW>
    <ROW>
    <COM_ID>78</COM_ID>
    <SIZE>756</SIZE>
    <PROJECT>Bayswater Tower</PROJECT>
    <COM_TYPE>Office</COM_TYPE>
    <Images>
            <ImgURL>http://fam-erp.com/apex/erp/fateh/1425</ImgURL>
            <ImgURL>http://fam-erp.com/apex/erp/fateh/1429</ImgURL>
    </Images>
    </ROW>
    </ROWSET>

    Hi, Fateh
    One possible way is to use XML functions to create your XML.
    Using XML functions you can do the IMAGES as an XMLAGG subquery rather than join to the image table.
    Here's an example using SCOTT schema:
    SQL> select xmlelement(
      2            "ROWSET"
      3          , xmlagg(
      4               xmlelement(
      5                  "ROW"
      6                , xmlforest(
      7                     d.deptno as "ID"
      8                   , d.dname as "NAME"
      9                   , (
    10                        select xmlagg(
    11                                  xmlelement(
    12                                     "ImgUrl"
    13                                   , 'http://the.server.com/'||e.empno
    14                                  )
    15                                  order by e.empno
    16                               )
    17                          from scott.emp e
    18                         where e.deptno = d.deptno
    19                     ) as "Images"
    20                  )
    21               )
    22               order by d.deptno
    23            )
    24         ) the_xml
    25    from scott.dept d
    26    /* joins to the other tables EXCEPT image table */
    27  /
    THE_XML
    <ROWSET><ROW><ID>10</ID><NAME>ACCOUNTING</NAME><Images><ImgUrl>http://the.serverThat output is an XMLTYPE column (think of it as a CLOB with added functionality ;-) )
    My SQL*PLUS cuts the output, but believe me, it is all there.
    Just to show it, here's the same example wrapped in an XMLSERIALIZE function to pretty-print the XML:
    SQL> select xmlserialize(
      2            content
      3            xmlelement(
      4               "ROWSET"
      5             , xmlagg(
      6                  xmlelement(
      7                     "ROW"
      8                   , xmlforest(
      9                        d.deptno as "ID"
    10                      , d.dname as "NAME"
    11                      , (
    12                           select xmlagg(
    13                                     xmlelement(
    14                                        "ImgUrl"
    15                                      , 'http://the.server.com/'||e.empno
    16                                     )
    17                                     order by e.empno
    18                                  )
    19                             from scott.emp e
    20                            where e.deptno = d.deptno
    21                        ) as "Images"
    22                     )
    23                  )
    24                  order by d.deptno
    25               )
    26            )
    27            as varchar2(4000)
    28            indent size=2
    29         ) the_xml
    30    from scott.dept d
    31    /* joins to the other tables EXCEPT image table */
    32  /
    THE_XML
    <ROWSET>
      <ROW>
        <ID>10</ID>
        <NAME>ACCOUNTING</NAME>
        <Images>
          <ImgUrl>http://the.server.com/7782</ImgUrl>
          <ImgUrl>http://the.server.com/7839</ImgUrl>
          <ImgUrl>http://the.server.com/7934</ImgUrl>
        </Images>
      </ROW>
      <ROW>
        <ID>20</ID>
        <NAME>RESEARCH</NAME>
        <Images>
          <ImgUrl>http://the.server.com/7369</ImgUrl>
          <ImgUrl>http://the.server.com/7566</ImgUrl>
          <ImgUrl>http://the.server.com/7788</ImgUrl>
          <ImgUrl>http://the.server.com/7876</ImgUrl>
          <ImgUrl>http://the.server.com/7902</ImgUrl>
        </Images>
      </ROW>
      <ROW>
        <ID>30</ID>
        <NAME>SALES</NAME>
        <Images>
          <ImgUrl>http://the.server.com/7499</ImgUrl>
          <ImgUrl>http://the.server.com/7521</ImgUrl>
          <ImgUrl>http://the.server.com/7654</ImgUrl>
          <ImgUrl>http://the.server.com/7698</ImgUrl>
          <ImgUrl>http://the.server.com/7844</ImgUrl>
          <ImgUrl>http://the.server.com/7900</ImgUrl>
        </Images>
      </ROW>
      <ROW>
        <ID>40</ID>
        <NAME>OPERATIONS</NAME>
      </ROW>
    </ROWSET>For a webservice you do not need to pretty-print the XML that is returned by the webservice.
    I do not know APEX, so I do not know if APEX supports exposing an allready built piece of XML rather than exposing a query result.
    But my guess is that it should do it very nicely if you query an XMLTYPE datatype (that is - use the first of my examples rather than the pretty-printed one.)
    If you can't get APEX to do it this way, then I suggest you try asking in the APEX forum rather than the SQL forum ;-)

Maybe you are looking for

  • Need to show No applicable data in the report.

    Hi All, We ave a key figure in the selection screen. And user will enter the value. based on the input, the report has to display less than or equal to the entered value as a result in the output of the report. Input NIV as 67,169.48 then below resul

  • Movie clip capture app?

    I am wanting to build a powerpoint type presentation probably using Keynote around several shortlips from a TV series as well as several motion pictures of the same series. I've already received permission from Paramount Pictures as well as CBS Studi

  • R12 Payment Document Sorting Case Sensitive

    Our customer request to payment document assigned sorting by payee name in case sensitive We have set the PPP to sort by Payee Name already However, we tested the document number assigned to generated in case insensitive. e.g we have 3 payee name in

  • Deleting all linked documents per sales order/item

    We have documents linked to our sales orders/items (which can be seen via CV03N).  I would like to run a batch program to selectively delete all of these linked documents.  There is a function module CV140_LINKS_DELETE that looks will do the trick if

  • What is the use of Fragmentation Content

    Hi All, I need some clarifiration on Fragmentation content on OBIEE RPD side, for what purpose we can use these fragmentation in OBIEE.