Sqlquery

Hi,
I want to delete duplicate records and display remaining records in a table using single sql statement. Is it possible.
can any one let me know?
Thanks,
Rajesh

drop table test;
create table test(id number);
insert into test values(1);
insert into test values(1);
insert into test values(2);
commit;
create or replace function dont_use return number
is
pragma autonomous_transaction;
n number;
begin
delete from test t
where rowid not in ( select max(rowid) from test group by id);
n := sql%rowcount;
commit;
return n;
end;
select *
from test;
ID
1
1
2
--"The below SINGLE SQL will delete dups and will show the unique values
with dont_use_t as
select /*+ materialize */ dont_use cnt
from dual
select *
from test t,dont_use_t
where t.rowid in ( select max(rowid) from test group by id);
ID      CNT
2     1
1     1
select *
from test;
ID
2
1
{code}
Hypothetical answer for a hypothetical question.. :)
Edited by: jeneesh on Mar 1, 2013 3:47 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • How to feed data into crystal reporte with "SQLQuery" method in c#?

    Hi there,
    I've an old app that was written in VB with some crystal reports from Crystal Report 7.
    Now I need to upgrade this old app into c# with newer version of Crystal Report, so we decide to go for VS2010.
    I can open the report template in the VS2010 without any problems.
    But I'm running into some issue here:
    the old report has multiple tables from a SQL db as the connection. Each table has a PK to each other.
    and the VB code feed the data like below:
    MainForm.CrystalReport(1).SQLQuery = SQLString
    I couldn't find any reference for "SQLQuery" method in the C#, is there such command exist?
    Thank you in advanced,

    Thank you Ludek. Looking into the info you provided.

  • Crystal Reports 2008 sqlquery Using

    We have an inquiry.
    Now, we are using Windows XP, Visual studio 2008, Crystal Reports 2008.
    Before, we had been used Windows XP, Visual studio 6, Crystal Reports 7.
    Since we changed development Environment to Visual Basic.NET, we have some problem to process with previous method.
    It was possible to send Query directly to Crystal Reports in previous development Environment. But, we do not know how to we do at VB.NET.
    <Previous Coding>
    Crystalreport.SQLQuery = u2018select * from TABLE order by dateu201D
    We used as above.
    Please let us know it is possible to use as above in Crystal Reports 2008 of VB.NET
    We are using [VIEW] but, It is not possible to make [VIEW] with u201Corder byu201D. So we had been used above method for special cases.

    Hi,
    It is been my problem to, it is very a big adjustment in terms of coding and others, please refer to this link for a step by step guide using crystal report on vb.net., [CLICK HERE|http://www.vbforums.com/showthread.php?p=2686697]
    Regards,
    Clint

  • Need ABAP Query Builder Like Ms-SQLQuery Builder for Critical ABAP-Query

    Dear ABAP Friends,
    I Need ABAP Query Builder which is as flexible as Ms-SQLQuery Builder for building Critical ABAP-Queries e.g. "I have 4 master tables , Each master table having self-join with some condition and these 4 Result-Sets have Innser-Join+Left Outer Join " Please Help.

    I have seen TCODE SQ01, But I found that this TCODE may be used to build simple ABAP Query with Selection-screen which can be used for generating simple report. But i think for critical query ??????????
    I have build my Query in MS-SQL and got the right output, Now how do I write this in ABAP Using Join statement. Please Help.....................
    My SQL Query as below(Remember this is a single Query and verified correct in SQL):
    SELECT     P1.PERNR, P1.ENAME, P1.BEGDA AS P1BEGDA, P1.ENDDA AS P1ENDDA, P1.AEDTM AS P1AEDTM, P1.UNAME AS P1UNAME, P1.PERSG, P1.PERSK,
                          P1.PLANS,
           P2.ENDDA AS P2ENDDA, P2.BEGDA AS P2BEGDA, P2.AEDTM AS P2AEDTM, P2.UNAME AS P2UNAME, P2.GESCH, P2.FAMST,
                       P21.ENDDA AS P21ENDDA, P21.BEGDA AS P21BEDDA, P21.AEDTM AS P21AEDTM, P21.UNAME AS P21UNAME, P21.FAMSA, P21.FAVOR, P21.FANAM,
                          P21.FGBDT, P21.FASEX,
                       P0.ENDDA AS P0ENDDA, P0.BEGDA AS P0BEDDA, P0.AEDTM AS P0AEDTM, P0.UNAME AS P0UNAME, P0.MASSN,
                          P0.MASSG
    FROM         (SELECT     TOP (100) PERCENT PA0001_2.PERNR, PA0001_2.ENDDA, PA0001_2.BEGDA, PA0001_2.AEDTM, PA0001_2.UNAME, PA0001_2.PERSG,
                                                  PA0001_2.PERSK, PA0001_2.PLANS, PA0001_2.ENAME
                           FROM          PA0001 AS PA0001_2 INNER JOIN
                                                      (SELECT     PERNR, MAX(ENDDA) AS ENDDA
                                                        FROM          PA0001 AS PA0001_1
                                                        GROUP BY PERNR) AS Pi1
    ON PA0001_2.PERNR = Pi1.PERNR
    AND PA0001_2.ENDDA = Pi1.ENDDA
                                               ORDER BY PA0001_2.PERNR) AS P1 LEFT OUTER JOIN
                              (SELECT     TOP (100) PERCENT PA0000.PERNR, PA0000.ENDDA, PA0000.BEGDA, PA0000.AEDTM, PA0000.UNAME, PA0000.MASSN,
                                                       PA0000.MASSG
                                FROM          PA0000 INNER JOIN
                                                           (SELECT     PERNR, MAX(AEDTM) AS Pi0AEDTM
                                                             FROM          PA0000 AS PA0000_1
                                                             GROUP BY PERNR) AS Pi0 ON PA0000.PERNR = Pi0.PERNR AND PA0000.AEDTM = Pi0.Pi0AEDTM
                                ORDER BY PA0000.PERNR) AS P0 ON P1.PERNR = P0.PERNR LEFT OUTER JOIN
                              (SELECT     TOP (100) PERCENT PA0021.PERNR, PA0021.ENDDA, PA0021.BEGDA, PA0021.AEDTM, PA0021.UNAME, PA0021.FAMSA, PA0021.FAVOR,
                                                       PA0021.FANAM, PA0021.FGBDT, PA0021.FASEX
                                FROM          PA0021 INNER JOIN
                                                           (SELECT     PERNR, MAX(AEDTM) AS Pi21AEDTM
                                                             FROM          PA0021 AS PA0021_1
                                                             GROUP BY PERNR) AS Pi21 ON PA0021.PERNR = Pi21.PERNR AND PA0021.AEDTM = Pi21.Pi21AEDTM
                                ORDER BY PA0021.PERNR) AS P21 ON P1.PERNR = P21.PERNR LEFT OUTER JOIN
                              (SELECT     TOP (100) PERCENT PA0002.PERNR, PA0002.ENDDA, PA0002.BEGDA, PA0002.AEDTM, PA0002.UNAME, PA0002.GESCH,
                                                       PA0002.FAMST
                                FROM          PA0002 INNER JOIN
                                                           (SELECT     PERNR, MAX(ENDDA) AS Pi2ENDDA
                                                             FROM          PA0002 AS PA0002_1
                                                             GROUP BY PERNR) AS Pi2 ON PA0002.PERNR = Pi2.PERNR AND PA0002.ENDDA = Pi2.Pi2ENDDA
                                ORDER BY PA0002.PERNR) AS P2 ON P1.PERNR = P2.PERNR
    xxxxx----
    Edited by: Goutam Roy on May 5, 2009 1:11 PM

  • How to use a select list value in a PL/SQL function body returning SQLquery

    Hi Friends,
    I have a select list P6_TEST with values 'nav' anf 'jyo'. I am trying to create a report using "SQL Query (PL/SQL
    function body returning SQL query)". In my report query can i check if P6_TEST='nav' and do something like the
    code shown below.How can i do that.
    DECLARE
    v_sql VARCHAR2(3000);
    BEGIN
    IF :P6_TEST = 'nav' THEN
    v_sql :=
    'SELECT
    * from department';
    ........................Thanks,
    Nav

    Nav:
    What you have should work. Give it a go. Post back if you run into issues.
    Varad

  • Problem with sqlquery

    hi,
    i have a requirement where i have to find a (status='C' >2) can anyone correct
    select CR.REPAIR_NUMBER,CR.INCIDENT_ID,CS.INCIDENT_ID,CS.INCIDENT_NUMBER,CR.STATUS
    FROM CSD_REPAIRS CR, CS_INCIDENTS_ALL_B CS
    WHERE CR.INCIDENT_ID = CS.INCIDENT_ID AND TO_NUMBER(CR.STATUS='C')>2)
    can any one correct me or help mee

    select *
      from (
    select serialnumber
         , count(case when status = 'C' then 1 end)  cnt
      from test
    group by serialnumber
    where cnt >= 2as in
    SQL> with test as
      2  (select 001 incidentid, 'C' status, 'adb1234' serialnumber from dual union all
      3  select 002 incidentid, 'C' status, 'adb1234' serialnumber from dual union all
      4  select 003 incidentid, 'C' status, 'adb1234' serialnumber from dual
      5  )
      6  select *
      7    from (
      8  select serialnumber
      9       , count(case when status = 'C' then 1 end)  cnt
    10    from test
    11   group by serialnumber
    12   )
    13   where cnt >= 2
    14  /
    SERIALN        CNT
    adb1234          3

  • How to avoid Cartesian join in sqlquery

    Please ignore this Thread.
    Thanks
    Lax
    Edited by: LAX_ORA on 05-Nov-2012 08:23

    It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Multiple instances of a table & join supported in OBIEE SQLQuery report

    Hello All,
    I am creating a report in BIP based on the RPD created in OBIEE.
    I have to use multiple instances of same table in this case. But when I do that, I am getting "'The query contains a self join/This is a non-supported operation" error.
    Have anybody got his error before? Could anybody help me solving this?
    Thanks
    Narasimha Rao

    Hello All,
    I am creating a report in BIP based on the RPD created in OBIEE.
    I have to use multiple instances of same table in this case. But when I do that, I am getting "'The query contains a self join/This is a non-supported operation" error.
    Have anybody got his error before? Could anybody help me solving this?
    Thanks
    Narasimha Rao

  • Usage of SQL and SQLQuery Component Oracle BPM 10g

    Hey Friends,
    I have created SQl and SQL query catalog compoenents in Oracle BPM 10g, but unable to figure about how to use them in the BPM process. Do i need to create an automatic activity and make implemenatation as method and write java/pbl code there. Please suggest some solution with code snippet.
    Thanks!!

    Having them cataloged constitutes most of the work you'll need to do. As you mention, the rest of the work is figuring out how you want to use them in a process.
    As an example, if you wanted to have method that would return a list of customer ids you could create a method in a BPM Object:
    listOfIds as String[]
    for each element in
      SELECT customerId
        FROM customer
      do
        listOfIds[] = String(element.customerid)
    end
    // return the array with the valid values
    return listOfIdsAfter adding this, you'll notice that there is an error flagged for your logic. Look at the Properties tab and change the "Server Side Method" property to "Yes".
    Now that you have the method that returns an array, you could use it to automatically populate a dropdown field for an attribute in the BPM Object. You'd do this by opening the properties of the attribute and changing the "Valid Values" property to "Dynamic Method" and select the method you just added.
    There's more to it than this, but hope this is enough to get you going,
    Dan

  • SQLQuery and Where-Statement

    Hi,
    I need a possibility to enter the where-statement at runtime.
    In the "SQL Query Statement" I can enter a query and parameters.
    My Problem ist that at runtime my forms-application builds the where-Part of the sql-statement and then sends it to the report.
    I know that reports has the &where_clause option.
    In &where_clause I can enter the whole where-clause of every statement.
    But how can I "tell" reports that it's query should based on this &where_clause???
    In other words: can I set the "sql Query Statement" at runtime?
    Thank you for your help
    bye
    Florian

    Hi Florian,
    In the data model, you can create a user parameter "P_WHERE" varchar2(1000), set your query like this:
    select col1,...coln
    from table
    where &P_WHERE;
    At the run time, you should pass the Where value from
    your form_application and send it to the parameter P_WHERE
    of the report.
    Hope this helps,
    CB

  • SqlQuery Help [date range]

    Database: Oracle 10g
    Table: SOURCE_TABLE
    #of records: 500k
    Primary Key: ID, EFF_DATE
    Data/Table:
    with SOURCE_TABLE AS
         (select 'P1' AS ID, TO_DATE('03/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V1' AS VALUE1, 'V2' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P1' AS ID, TO_DATE('02/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V3' AS VALUE1, 'V24' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID, TO_DATE('01/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID, TO_DATE('03/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V11' AS VALUE1, 'V21' AS VALUE2 FROM DUAL)                                 
    SELECT * FROM SOURCE_TABLE  Conditions:
    For a given date range i.e. 01/01/2012 to 04/30/2012
    what we need is: For each ID, we need part "P" value1 and value2 column values for each specific month between the default date ranges.
    In this case it would be Jan-2012, FEB-2012, MAR-2012, APR-2012
    If you see below output for P1, there will not be JAN-2012 record as the part P1 is effective from FEB-2012
    What i have done so far:
    i have the select query basically it is looping through 01/2012 to 04/2012 and for every month,
    find out the max eff_date record less then the month that we are computing the value columns for
    Output:
    with output as
         (select 'P1' AS ID , '02/01/2012' AS AS_OF_DATE, 'V3' AS VALUE1, 'V24' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P1' AS ID , '03/01/2012' AS AS_OF_DATE, 'V1' AS VALUE1, 'V2' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P1' AS ID , '04/01/2012' AS AS_OF_DATE, 'V1' AS VALUE1, 'V2' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '01/01/2012' AS AS_OF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '02/01/2012' AS AS_OF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '03/01/2012' AS AS_OF_DATE, 'V11' AS VALUE1, 'V21' AS VALUE2 FROM DUAL
          UNION ALL
          select 'P2' AS ID , '04/01/2012' AS AS_OF_DATE, 'V11' AS VALUE1, 'V21' AS VALUE2 FROM DUAL
    SELECT * FROM OUTPUT;
            ID     AS_OF_DATE     VALUE1     VALUE2
         P1     02/01/2012     V3     V24
         P1     03/01/2012     V1     V2
         P1     04/01/2012     V1     V2
         P2     01/01/2012     V10     V20
         P2     02/01/2012     V10     V20
         P2     03/01/2012     V11     V21
         P2     04/01/2012     V11     V21Thanks in advance

    Hi,
    ora1001 wrote:
    Hi frank,
    I changed the query to inner join instead of outer join because if a part is not effective for a given month, then i dont need a record.
    ex: if P1 EFF_DATE IS 03/01/2012, then i dont need records for JAN, FEB... You're right; inner join is all you need here. My mistake.
    What is "P1 EFF_DATE"? Is that the start of the date range you're interested in (January 1, 2012 in your original example)?
    Don't you still need to cosider rows before that date? For example, say we want to show the same 4 months (January to April, 2012), but instead of
    select 'P2' AS ID, TO_DATE('01/01/2012','MM/DD/YYYY') AS EFF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUALthe data is changed to
    select 'P2' AS ID, TO_DATE('11/01/2011','MM/DD/YYYY') AS EFF_DATE, 'V10' AS VALUE1, 'V20' AS VALUE2 FROM DUALWould you still want the same results? In this example, the values from November 2011 serve as the values for January and Febrruay 2012. It doesn't matter that Noverber 2011 is outside of the target range.
    It works fine... its faster now.
    however, i would like to know the difference in my query vs your query in terms of performance..
    the subquery runs faster when compared to analytic function...
    select * from part p,
    source_table st
    where p.id = st.id
    and st.eff_date = (select max(eff_date) from source_table st1
    where st1.eff_date < '01-mar-2012');
    If st1.eff_date is a DATE, then don't try to compare it to a VARCHAR2, such as '01-mar-2012'. Use TO_DATE:
    where st1.eff_date < TO_DATE ( '01-mar-2012'
                                   , 'DD-mon-YYYY'
                        )or a DATE literal:
    where st1.eff_date < DATE '2012-03-01'instead.
    vs
    select * from (
    select p.id,
    st.eff_date,
    row_number() over (partition by st.id,st.eff_date order by st.id,st.eff_date desc) as consider_order from part p,
    source_table st
    where p.id = st.id) where consider_order = 1;
    The first approach is doing much less work. It just has to remember what the latest eff_date is. Say it has already found a row with March 1, 2012, and it comes across a row with an earlier date, such as January 1, 2012. As soon as it sees that January 1, 2012 is not the new record holder, it can move on to the next row. (Using the LAST function, as I suggested, would cause it to do even less work.)
    The second approach is doing much more work. It has to remember all the dates, in order. Say it has already found a row with March 1, 2012, and it comes across a row with an earlier date, such as January 1, 2012. After it sees that January 1, 2012 is not the new record holder, it still has to determine if January 1 comes 2nd, or 3rd on the list.

  • HTML Character entity references on SQLQuery

    I am trying retrieve the data thru XMLElement and I like to do a HTML Character entity references. I guess XMLElement does it with the proper character set translations and I was not successul in getting it correct. Could you please help me out. My DB character set it UTF-8.
    For example, the "acute" e needs to be translated to its hexa equivalent. I tried it by setting the mid-tier's client's NLS but with no success. I dont want to scan the each character and convert it.
    create table master.temp_xml_encode
    (party_name_id NUMBER(15),
    party_id NUMBER(15),
    party_name VARCHAR2(200) );
    PARTY_NAME_ID PARTY_ID PARTY_NAME
    3831587 5496840 The West Company México, S.A. de C.V.
    3844362 5496730 Schiønning & Arvé A/S
    3847940 5496836 West Rubber de España, S.A.
    4047634 5983166 Timberland España, S.L.
    4266163 5983166 Timberland España, S.A.
    4285954 6482794 The Young Women¿s Christian Association of Central New Jersey
    SELECT XMLELEMENT("party_id", party_id,
    xmlforest(party_name_id AS "partynameid",
    party_name AS "partyname"
    FROM master.temp_xml_encode
    Thanks for your help

    And Yes forgot to add one thing, the index.jsp is a part of the application supplied by vendor and I do not have src of the struts actions (no control on server side code).
    I need to find a solution from client's side.

  • Sqlquery help ---next 50 Mondays in date format

    Hello Forum Members,
    Can you please advice me How to get next 50 Mondays in dateformat from current date
    eg:04/15/2013,04/22/2012 ...
    Best Regards,
    SP

    Hi,
    Welcome to the forum!
    TO_CHAR (dt, 'D') depends on your NLS_TERRITORY setting. The same query might return Mondays on one system, and Tuesdays on another.
    Here's a say that always returns Mondays,no matter what your NLS settings are:
    SELECT     LEVEL                         AS week_num
    ,     TRUNC (SYSDATE, 'IW') + (7 * LEVEL)     AS monday
    FROM     dual
    CONNECT BY     LEVEL <= 50
    ;Output:
    ` WEEK_NUM MONDAY
             1 15-Apr-2013
             2 22-Apr-2013
             3 29-Apr-2013
             4 06-May-2013
             5 13-May-2013
            49 17-Mar-2014
            50 24-Mar-2014

  • Howto split date interval in SQLquery

    Hi,
    i'm looking for way ho to split date interval in 3 rows to 1 row as simple as possible.
    Records:
    ID:333 FROM_DATE: 01/01/2003 TO_DATE: 12/31/2003
    ID:333 FROM_DATE: 01/01/2004 TO_DATE: 12/31/2004
    ID:333 FROM_DATE: 01/01/2005 TO_DATE: 12/31/2005
    into 1 record:
    ID:333 FROM_DATE: 01/01/2003 TO_DATE: 12/31/2005
    or
    ID:333 FROM_DATE: 01/01/2003 TO_DATE: 12/31/2003
    ID:333 FROM_DATE: 01/01/2004 TO_DATE: 12/31/2004
    ID:333 FROM_DATE: 01/01/2005 TO_DATE:
    to
    ID:333 FROM_DATE: 01/01/2003 TO_DATE:
    any suggestions?
    Thanks.
    Regards,
    Stanislav
    Message was edited by:
    stanislav_studeny
    Message was edited by:
    stanislav_studeny
    Message was edited by:
    stanislav_studeny
    Message was edited by:
    stanislav_studeny

    Hi,
    First, let's clearly state the problem:
    We need the first start_date and the last end_date from each id and group. In this problem, terms like "first", "next" and "last" always refer to ordering by start_date, which is never NULL. Therefore, "last end_date" means the end_date from the row with the greatest start_date, even if that end_date IS NULL.
    A group is defined as one or more rows having the same id, where start_date to end_date ranges overlap, or are separated by less than a day. For example, if one row has end_date=30.9.2007, and another row with the same id has start_date=1.10.2007, then those two rows are in the same group. Another example: if one row has has end_date=30.9.2006 and the next row with the same id has start_date=1.10.2007, those two rows are in different groups.
    The following query does that:
    WITH
    ng     AS
    (     -- Begin sub-query ng to compute new_grp
         SELECT     id
         ,     start_date
         ,     end_date
         ,     CASE
                   WHEN     TRUNC (start_date)
                        <=
                        LAG (end_date) OVER     ( PARTITION BY     id
                                         ORDER BY     start_date
                                       ) + 1
                   THEN     0     -- same group as previous row
                   ELSE     1     -- new group begins with this row
              END     AS new_grp
         FROM     data
    )     -- End sub-query ng to compute new_grp
    , g     AS
    (     -- Begin sub-query g to compute grp_num
         SELECT     ng.*
         ,     SUM (new_grp) OVER     ( PARTITION BY     id
                               ORDER BY     start_date
                             ) AS grp_num
         FROM     ng
    )     -- End sub-query g to compute grp_num
    SELECT     id
    ,     MIN (start_date)     AS start_dt
    ,     MAX (end_date) KEEP (DENSE_RANK LAST ORDER BY start_date)
                        AS end_dt
    FROM     g
    GROUP BY     id,     grp_num
    ORDER BY     id,     grp_num
    ;With this data table:
    CREATE TABLE data as
    select 333 as id, to_date('01/01/2006','mm/dd/yyyy') as start_date, to_date('09/30/2007','mm/dd/yyyy') as end_date from dual
    union all
    select 333 as id, to_date('10/01/2007','mm/dd/yyyy') as start_date, to_date('12/13/2007','mm/dd/yyyy') as end_date from dual
    union all
    select 333 as id, to_date('01/01/2008','mm/dd/yyyy') as start_date, null as end_date from dual
    UNION ALL
    SELECT     44165, TO_DATE ('1.1.2006', 'DD.MM.YYYY'),     TO_DATE ('30.9.2006', 'DD.MM.YYYY')     FROM     dual
    UNION ALL
    SELECT     44165, TO_DATE ('1.10.2007', 'DD.MM.YYYY'),     TO_DATE ('31.12.2007', 'DD.MM.YYYY')     FROM     dual
    UNION ALL
    SELECT     44165, TO_DATE ('1.1.2008', 'DD.MM.YYYY'),     NULL                         FROM     dual
    ;the query above produces these results:
            ID START_DT   END_DT
           333 01.01.2006 13.12.2007
           333 01.01.2008
         44165 01.01.2006 30.09.2006
         44165 01.10.2007Here's how the query works.
    Using LAG, it's easy to tell if one row belongs in the same group as the previous row or not. However, it's not so easy to tell to which group a row belongs.
    What we can do is compute a flag (new_grp) that is 1 when then row begins a new group and 0 when it does not. SUM (new_grp) from the first row through the current row will assign a common identifier (grp_num) to all the members of a group.
    Since grp_num is computed by an analytic function (SUM in this example), and it is based on the results of another analytic function (new_grp, computed using LAG), then they can't be computed in the same query: we have to compute new_grp first in a separate sub-query.

  • Merge function and make one sqlquery

    Hello ,
    can anyone make this below query tune... i mean make the function remove and i want single sql query without any function.HELP is highly appreciated
    SELECT usr.employee_id as employeeId, usr.last_name||','||usr.first_name as EmployeeName, obj.Title as Gaoltitle,
    dic_elms_wgt.name as weightage, dic_elms_eec.name as EEComplete, dem_grph.value as citystatecode,
    mgr.last_name||', '||mgr.first_name as managerName, kcfun_rating_k(241,obj.id) as managerselectedcomplete,
    kccabelas.row_concat_user(obj.user_id) as businessUnit
    FROM ************** WHERE usr.id = obj.user_id
    AND usr.status_id = 251
    and mgr.id = usr.manager_id
    AND obj.status_id = 300
    AND obj.type_id != 363
    AND obj.time_frame_id = 2010
    AND obj.is_deleted = 'N'
    AND obj.parent_id = 0
    AND obj.is_individual = 'Y'
    AND dic_elms_wgt.id = obj.weight_id
    AND dic_elms_eec.id = obj.percent_complete_id
    AND dem_grph.id = usr.custom_field_5;
    create or replace FUNCTION row_concat_user(userid in number) RETURN VARCHAR2 IS
    ret VARCHAR2(4000);
    cursor cmulti1 is select value from ****where id in (select ****from ****_2 where user_id =userid) ;
    BEGIN
    for i in cmulti1 LOOP
    IF ret IS NULL THEN
    ret := i.value;
    ELSE
    ret := ret || ',' || i.value;
    END IF;
    END LOOP;
    return ret;
    end;
    sorry this post was closed thanku for response....
    Edited by: OraHungry on Mar 21, 2011 5:15 PM

    >
    stragg is not a built in oracle function, it's a 3rd party function, so unless you point people to the source code, don't recommend it.
    >
    Well it is now a built in oracle function if you are using Oracle 11.2 but, it's undocumented like wm_concat.
    sqlplus / as sysdba
    SQL*Plus: Release 11.2.0.1.0 Production on Mon Mar 21 11:56:09 2011
    Copyright (c) 1982, 2010, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> desc stragg;
    FUNCTION stragg RETURNS VARCHAR2
    Argument Name                  Type                    In/Out Default?
    INPUT                          VARCHAR2                IN
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> show user
    USER is "SYS"
    SQL> desc stragg;
    FUNCTION stragg RETURNS VARCHAR2
    Argument Name                  Type                    In/Out Default?
    INPUT                          VARCHAR2                IN
    SQL> select text from user_source
      2  where name = 'STRAGG';
    TEXT
    FUNCTION stragg(input varchar2 )
    RETURN varchar2
    AGGREGATE USING string_agg_type;
    SQL> select text from user_source where name = 'STRING_AGG_TYPE' and type = 'TYPE';
    TEXT
    type string_agg_type
    -- OID '00000000000000000000000000020101'
    as object
       key      raw(8),
       static function
            ODCIAggregateInitialize(sctx IN OUT string_agg_type, outopn IN RAW,
                                    inpopn IN RAW)
            return pls_integer
            as language c
            library xmltype_lib
            name "STRAGG_INITIALIZE"
            with context
            parameters (
              context,
              sctx, sctx INDICATOR STRUCT, sctx DURATION OCIDuration,
              outopn OCIRaw, inpopn OCIRaw,
              return int
    ...I would still recommend using listagg compared to stragg as it outperformed in one of our recent benchmarking exercise.
    Thanks
    Raj

Maybe you are looking for

  • Error 1031/ error 1026

    Hello, I made a change on a sub.vi (MFCCarrierScheath.vi) to (MFCCarrierSheathR1.vi). This change can be seen by the additional case structure surrounding the second to the right case structure in MFCCarrierSheathR1. This change has resulted in two e

  • Preview in browser stopped working

    Running CS4 version 10 build 4117 and today when I went to do some work I cannot use "preview in browser" Edit List has both firefox and IE listed but when I click the globe it tells me no browsers selected. tried removing browsers and re-selecting t

  • BOR event vs ABAP OO event

    Hi, I would like create new PO workflow (BUS2012) using ABAP OO workflow. Is it possible to use the existing BOR event, such as RELEASESTEPCREATED  instead of creating new one for the ABAP OO workflow class? And if we can re-use the event, how do we

  • Multiple Portals on Same Server

    What is the best way for 2 separate groups in an organization to have (or appear to have) their own instance of the Oracle Portal? We have 2 separate groups ready to begin development in the Portal and are trying to figure out a good way to accomplis

  • WAAS - Some connections optimized, some not (mostly PT In Progress)

    Hello, I have an issue with WAAS acceleration. I have two sites, each one has a WAE apliance. I do the traffic redirection with WCCP v2. Topology picture is attached. Between remote and central site there are two GRE tunnels, Tunnel 31 is primary, Tu