Order by rownumber

Hi. I have this:
select rownum,usergroup,username
from users
order by 2,3;
The problem is that i have at the column rownum:
6
1
4
9
2
5
I want it to be sorted. How can i sort by 2,3 and then add rownum. I can't use sequences only sql.
Thanks.

Hi,
Plz find this ex.
SQL> select * from dummy;
NO NAME
1 abc
2 abc
3 bcd
1 bcd
2 bdc
4 dbdc
6 rows selected.
SQL> select rownum,no,name from(select no,name from dummy order by no,name);
ROWNUM NO NAME
1 1 abc
2 1 bcd
3 2 abc
4 2 bdc
5 3 bcd
6 4 dbdc
6 rows selected.

Similar Messages

  • Finding a Particular string in a Database in the most Optimized way

     Hi All,
              Below is the query to find  a Particular String in the entire database tables,I have a Database of about 500 + tables and each contains many data's .In these tables i want to find a particular
    string but didn't know the column name and table name.so i did as below,but for executing this it almost take 40 - 45 minutes.Is there any other way to Optimize this and make the Query execution Faster.I am copying the code below.Please comment
    DECLARE
        @search_string  VARCHAR(100),
        @table_name     SYSNAME,
        @table_id       INT,
        @column_name    SYSNAME,
        @sql_string     VARCHAR(2000),
     @TableCount    INT,
     @ColumnCount   INT
    SET @search_string = 'Developer'
    DECLARE   @Tables TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
    DECLARE   @Columns TABLE(Rownumber int identity(1,1),name nvarchar(370),id int)
    INSERT INTO @Tables
    SELECT name, object_id FROM sys.objects WHERE type = 'U'
    SELECT @TableCount=COUNT(1) FROM @Tables
    WHILE (@TableCount >0)
    BEGIN
      SELECT TOP(1)
         @table_name=name
        ,@table_id=id
      FROM  @Tables ORDER BY Rownumber
    INSERT INTO @Columns
    SELECT name,object_id FROM sys.columns WHERE object_id = @table_id AND system_type_id IN (167, 175, 231, 239)
    SELECT @ColumnCount=COUNT(1) FROM @Columns
      WHILE (@ColumnCount >0)
      BEGIN
        SELECT TOP(1)
           @column_name=name
        FROM  @Columns
        WHERE id= @table_id
         ORDER BY Rownumber
         --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''%' + @search_string + '%'') PRINT ''' + @table_name + ', ' + @column_name + ''''
          SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] LIKE ''' + @search_string + '%'') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
    + ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
         --select (@sql_string);
          --SET @sql_string = 'IF EXISTS (SELECT 1 FROM ' + @table_name + ' WHERE [' + @column_name + '] = ''' + @search_string + ''') select ''' + @table_name + ''' AS TableName ,  ''' + @column_name
    + ''' AS ColumnName , '''+ @search_string  + ''' As SearchString'
         EXECUTE(@sql_string)
       SET @ColumnCount=@ColumnCount-1
       DELETE FROM @Columns WHERE  Name =   @Column_Name
      END
    SET @TableCount=@TableCount-1
    DELETE FROM @Tables WHERE Name= @Table_Name
    END

    You may also try the below :
    http://gallery.technet.microsoft.com/c0c57332-8624-48c0-b4c3-5b31fe641c58

  • Query of Qeries Syntax problem

    I'm getting an error on the syntax for my SELECT statement in
    a Query of Queries. The code is:
    <cfquery name="OnOrderLogData" dbtype="Query"
    result="result3">
    SELECT *,
    ROW_NUMBER() OVER([ORDER] [BY] RowNumber [ASC]) + 0 AS
    PageOrder
    FROM OOLogView
    WHERE RowNumber > 3 AND RowNumber <= 33
    </cfquery>
    The error is:
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    I know that certain reserved words need to be escaped with
    square brackets, and I have surrounded all the words that were on
    the list in the reference manual with square brackets. I did not
    see anything in the reference manual that says I can not use
    parenthesis in the SELECT statement, nor anything that says I can
    not use the SQL function ROW_NUMBER. I have spent several hours
    trying many different things and still can't get it to work. It
    works fine when I execute it as an Ad Hoc query in SQL Server 2005
    Studio Express (when I take out the square brackets).
    Can anyone please help me figure out what is wrong and how to
    fix it? Thanks.

    > Adam, your's was the least impolite
    Heh. Talk about "damning with faint praise".
    > I have Ben Forta's 3 volumes, the CF Reference Manual
    and the CF User's Guide.
    > None are very specific about what IS OK to do,
    I actually find livedocs to be the best resource for looking
    up CF stuff.
    http://livedocs.adobe.com/coldfusion/8/using_recordsets_1.html
    Or googling these forums (NB: *Google*, not the in-built
    search function,
    which is rubbish).
    > If I would say something to my boss such as, "You
    shouldn't expect..." or
    > "What do you expect..." in the context as these answers,
    I would be in the dog
    > house.
    Sure. But you're not our boss. If we were to draw parallels
    like that,
    it'd be the other way around if anything. (I would not draw
    the parallels
    either way, that said). I actually *would* talk to one of my
    subordinates
    like that, but I'm noted at work for my "terseness" at times
    (some might
    describe it in harsher terms than that ;-). We've all got
    different
    expectations, I guess.
    > That is the kind of criteria used to judge the
    appropriateness of how
    > one should converse with other people.
    OK, well I think - for the reasons you outlined - you're
    going to be a bit
    disappointed there. I recommend ignoring the tone (or at
    least the tone
    you're perceiving), and just take the info as given. On the
    whole, people
    here are pretty polite, actually.
    But anyway. I think you got your answer, so job done.
    Although now you've
    got to work out another way of sorting out your issue...
    Adam

  • Please review procedure for performance tuning

    Hi Friends,
    I have a procedure, which is taking lot of time for execution. Please help me how can i tune this procedure to reduce the execution time.
    Purpose of the procedure : This procedure runs every data to load data from DWH to Data Marts,
    We have some adverse keywords given by business in the table CFG_ADVERSE_KEYWORD ,the procedure will identify the keywords in the tables like df_call_ae_vd, in the notes column and loads only records which has adverse keywords.
    Below is the procedure
    create or replace procedure              LOAD_DM_AE_DATA_PRC
    as
    v_insert_count              NUMBER  := 0;
    /* current_process identifies the block of code where exception is raised, used for debugging */
    v_current_process           VARCHAR2(100) := NULL;
    v_error_code                VARCHAR2(8)   := NULL;
    v_error_text                VARCHAR2(110) := NULL;
    v_error_msg                 VARCHAR2(500) := NULL;
    v_error_count               NUMBER  := 0;
    /* module_name is the procedure name */
    v_module_name               VARCHAR2(50)  := 'LOAD_DM_AE_DATA_PRC';
    /* table_name is the target table truncated and loaded by the procedure */
    v_table_name                 VARCHAR2(50)  := NULL;
    v_table_name1                VARCHAR2(50)  := 'MM_USER_AE_VD';
    v_table_name2                VARCHAR2(50)  := 'MF_CALL_AE_VD';
    v_table_name3                VARCHAR2(50)  := 'MM_CHANGE_REQUEST_AE_VD';
    v_table_name4                VARCHAR2(50)  := 'MM_COMPETITOR_INSIGHT_AE_VD';
    v_table_name5                VARCHAR2(50)  := 'MM_FORMULARY_AE_VD';
    v_table_name6                VARCHAR2(50)  := 'MM_MED_INQUIRY_AE_VD';
    v_table_name7                VARCHAR2(50)  := 'MM_SAMPLETRANS_AE_VD';
    v_table_name8                VARCHAR2(50)  := 'MM_ADVERSE_EVENT_ALL';
    v_table_name9                VARCHAR2(50)  := 'MM_USER_COUNTRY_AE_VD';
    v_table_name10               VARCHAR2(50)  := 'CFG_AE_CONCAT_KEYWORD';
    v_table_name                 VARCHAR2(50)  := NULL;
    /* source_name is the view or source table */
    v_source_name                VARCHAR2(50)  := 'DA_RDW_AP_DWH';
    /* Variables specific to application.  */
    ** Declare Exceptions                                                                          *
    procedure_err              EXCEPTION;
    ** Begin procedure                                                                             *
    BEGIN /* procedure*/
      DBMS_OUTPUT.ENABLE(1000000);
    ** Truncate tables                                                                             *
      BEGIN /* Truncate target*/
        v_current_process := 'Truncate table ' || v_table_name1;
        DBMS_OUTPUT.PUT_LINE(v_current_process);
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name1);              
        DBMS_OUTPUT.PUT_LINE (v_table_name1||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name2);              
        DBMS_OUTPUT.PUT_LINE (v_table_name2||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name3);              
        DBMS_OUTPUT.PUT_LINE (v_table_name3||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name4);              
        DBMS_OUTPUT.PUT_LINE (v_table_name4||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name5);              
        DBMS_OUTPUT.PUT_LINE (v_table_name5||' truncated' );
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name6);              
        DBMS_OUTPUT.PUT_LINE (v_table_name6||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name7);              
        DBMS_OUTPUT.PUT_LINE (v_table_name7||' truncated' ); 
       EXECUTE IMMEDIATE ('Truncate table ' || v_table_name8);              
        DBMS_OUTPUT.PUT_LINE (v_table_name8||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name9);              
        DBMS_OUTPUT.PUT_LINE (v_table_name9||' truncated' ); 
        EXECUTE IMMEDIATE ('Truncate table ' || v_table_name10);              
        DBMS_OUTPUT.PUT_LINE (v_table_name10||' truncated' ); 
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END; /* Truncate target*/
    ** 1.Load table MM_USER_AE_VD                                                                  *
       BEGIN  
        insert into DM_RDW_AP_VD.MM_USER_AE_VD
        ( ID                     ,
          NAME                   ,
          COUNTRY_CODE_BI__C     ,
          LASTMODIFIEDDATE       ,
          SYSTEMMODSTAMP )
        select
          ID                     ,
          NAME                   ,
          COUNTRY_CODE_BI__C     ,
          LASTMODIFIEDDATE       ,
          sysdate
        from DA_RDW_AP.DM_USER_AE_VD
        union
        select '999', 'Do not delete this record', null, sysdate-1, sysdate-1
        from dual;
        DBMS_OUTPUT.PUT_LINE (v_table_name1||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END;
    ** 2. SCAN/Load table MF_CALL_AE_VD                                                            *
      BEGIN  
           insert into DM_RDW_AP_VD.MF_CALL_AE_VD
            ( ID                      ,
              NAME                    ,
              CALL_DATE_VOD__C        ,
              PRE_CALL_NOTES_VOD__C   ,
              NEXT_CALL_NOTES_VOD__C  ,
       NEXT_CALL_NOTES_VOD__C_HTML,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              LASTMODIFIEDDATE        ,
              SYSTEMMODSTAMP)
      select
              distinct a.ID             ,
              a.NAME                    ,
              a.CALL_DATE_VOD__C        ,
              a.PRE_CALL_NOTES_VOD__C   ,
              a.NEXT_CALL_NOTES_VOD__C  ,
       replace(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '),
        substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(   trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
      ) as NEXT_CALL_NOTES_VOD__C_HTML,
              a.COUNTRY_CODE_BI__C      ,
              a.OWNERID                 ,
              a.LASTMODIFIEDDATE        ,
              a.SYSTEMMODSTAMP
          from (da_rdw_ap.df_call_ae_vd a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where  (b.country_code = 'EN' and instr( lower(a.NEXT_CALL_NOTES_VOD__C), lower(b.Keyword) , 1, 1 ) > 0)
        where  (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.NEXT_CALL_NOTES_VOD__C is not null
          union
       select
              distinct a.ID             ,
              a.NAME                    ,
              a.CALL_DATE_VOD__C        ,
              a.PRE_CALL_NOTES_VOD__C   ,
              a.NEXT_CALL_NOTES_VOD__C  ,
       replace(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '),
               substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' '), instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
              ) as NEXT_CALL_NOTES_VOD__C_HTML,
              a.COUNTRY_CODE_BI__C      ,
              a.OWNERID                 ,
              a.LASTMODIFIEDDATE        ,
              a.SYSTEMMODSTAMP         
          from (da_rdw_ap.df_call_ae_vd a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
       --where (instr( lower(a.NEXT_CALL_NOTES_VOD__C), lower(b.Keyword) , 1, 1 ) > 0 );
          where (instr( lower(' ' || translate(trim(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0)  and  b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name2||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
         EXCEPTION
            WHEN OTHERS THEN
              v_error_count := v_error_count + 1;
              v_error_code  := TO_CHAR(sqlcode);
              v_error_text  := SUBSTR(sqlerrm, 1, 110);
              RAISE procedure_err;
      END;
    ** 3. SCAN/Load table MM_CHANGE_REQUEST_AE_VD                                                  *
      BEGIN
        insert into DM_RDW_AP_VD.MM_CHANGE_REQUEST_AE_VD
          (   ID                      ,
              NAME                    ,
              COMMENTS_BI__C          ,
       COMMENTS_BI__C_HTML     ,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              LASTMODIFIEDDATE        ,
              SYSTEMMODSTAMP )
          select
              distinct a.ID           ,
              a.NAME                  ,
              a.COMMENTS_BI__C        ,
       replace(replace(a.COMMENTS_BI__C, chr(10),' '),
               substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
              ) as COMMENTS_BI__C_HTML,
              a.COUNTRY_CODE_BI__C    ,
              a.OWNERID               ,
              a.LASTMODIFIEDDATE      ,
              a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_CHANGE_REQUEST_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.COMMENTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0) and a.COMMENTS_BI__C  is not null
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMMENTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.COMMENTS_BI__C is not null
          union
          select
              distinct a.ID           ,
              a.NAME                  ,
              a.COMMENTS_BI__C        ,
       replace(replace(a.COMMENTS_BI__C, chr(10),' '),
               substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
              ) as COMMENTS_BI__C_HTML,
              a.COUNTRY_CODE_BI__C    ,
              a.OWNERID               ,
              a.LASTMODIFIEDDATE      ,
              a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_CHANGE_REQUEST_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where instr( lower(a.COMMENTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENTS_BI__C  is not null;
       where (instr( lower(' ' || translate(trim(replace(a.COMMENTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name3||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 4. SCAN/Load table MM_COMPETITOR_INSIGHT_AE_VD                                              *
      BEGIN
        insert into DM_RDW_AP_VD.MM_COMPETITOR_INSIGHT_AE_VD
         (  COMPETITOR_INSIGHTS_BI__C    ,
      COMPETITOR_INSIGHTS_BI__C_HTML,
            ID                           ,
            NAME                         ,
            OWNERID                      ,
            LASTMODIFIEDDATE             ,
            SYSTEMMODSTAMP )
          select
            distinct a.COMPETITOR_INSIGHTS_BI__C  ,
      replace(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '),
               substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMPETITOR_INSIGHTS_BI__C_HTML,
            a.ID                         ,
            a.NAME                       ,
            a.OWNERID                    ,
            a.LASTMODIFIEDDATE           ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_COMPETITOR_INSIGHT_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.COMPETITOR_INSIGHTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0) and a.COMPETITOR_INSIGHTS_BI__C is not null
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0 ) and a.COMPETITOR_INSIGHTS_BI__C is not null
          union 
          select
            distinct a.COMPETITOR_INSIGHTS_BI__C  ,
      replace(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '),
             substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMPETITOR_INSIGHTS_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMPETITOR_INSIGHTS_BI__C_HTML,
            a.ID                         ,
            a.NAME                       ,
            a.OWNERID                    ,
            a.LASTMODIFIEDDATE           ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_COMPETITOR_INSIGHT_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where instr( lower(a.COMPETITOR_INSIGHTS_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMPETITOR_INSIGHTS_BI__C is not null;
       where (instr( lower(' ' || translate(trim(replace(a.COMPETITOR_INSIGHTS_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name4||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 5. SCAN/Load table MM_FORMULARY_AE_VD                                                       *
      BEGIN
         insert into DM_RDW_AP_VD.MM_FORMULARY_AE_VD
          (    COMMENT_FORMULARY_BI__C   ,
        COMMENT_FORMULARY_BI__C_HTML,
               ID                        ,   
               NAME                      ,   
               OWNERID                   ,       
               LASTMODIFIEDDATE          ,
               SYSTEMMODSTAMP )
         select
               distinct  a. COMMENT_FORMULARY_BI__C,
        replace(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '),
                substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                 '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
               ) as COMMENT_FORMULARY_BI__C_HTML,
               a.ID                      ,
               a.NAME                    ,      
               a.OWNERID                 ,    
               a.LASTMODIFIEDDATE        ,
               a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_FORMULARY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          -- where (b.country_code = 'EN' and instr( lower(a.COMMENT_FORMULARY_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENT_FORMULARY_BI__C is not null)
         where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMMENT_FORMULARY_BI__C , chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.COMMENT_FORMULARY_BI__C  is not null
          union
          select
               distinct  a. COMMENT_FORMULARY_BI__C,
            replace(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '),
                substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                 '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' '), instr(replace(replace(lower(a.COMMENT_FORMULARY_BI__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
               ) as COMMENT_FORMULARY_BI__C_HTML,
               a.ID                      ,
               a.NAME                    ,      
               a.OWNERID                 ,    
               a.LASTMODIFIEDDATE        ,
               a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_FORMULARY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.OWNERID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where (instr( lower(a.COMMENT_FORMULARY_BI__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENT_FORMULARY_BI__C is not null);
       where (instr( lower(' ' || translate(trim(replace(a.COMMENT_FORMULARY_BI__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name5||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 6. SCAN/Load table MM_MED_INQUIRY_AE_VD                                                     *
      BEGIN
        insert into DM_RDW_AP_VD.MM_MED_INQUIRY_AE_VD
         (   ID                  ,
             NAME                ,
             INQUIRY_TEXT__C     ,
      INQUIRY_TEXT__C_HTML,
             CREATEDBYID         , 
             LASTMODIFIEDDATE    ,
             SYSTEMMODSTAMP )
           select
             distinct a.ID       ,
             a.NAME              ,
             a.INQUIRY_TEXT__C   ,
      replace(replace(a.INQUIRY_TEXT__C, chr(10),' '),
               substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)),1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
             ) as INQUIRY_TEXT__C_HTML,
             a.CREATEDBYID       ,    
             a.LASTMODIFIEDDATE  ,
             a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_MED_INQUIRY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.INQUIRY_TEXT__C), lower(b.Keyword) , 1, 1 ) > 0 and a.INQUIRY_TEXT__C is not null)
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.INQUIRY_TEXT__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.INQUIRY_TEXT__C  is not null
          union
          select
             distinct a.ID       ,
             a.NAME              ,
             a.INQUIRY_TEXT__C   ,
      replace(replace(a.INQUIRY_TEXT__C, chr(10),' '),
               substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)),1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.INQUIRY_TEXT__C, chr(10),' '), instr(replace(replace(lower(a.INQUIRY_TEXT__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
             ) as INQUIRY_TEXT__C_HTML,
             a.CREATEDBYID       ,    
             a.LASTMODIFIEDDATE  ,
             a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_MED_INQUIRY_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where (instr( lower(a.INQUIRY_TEXT__C), lower(b.Keyword) , 1, 1 ) > 0 and a.INQUIRY_TEXT__C is not null);
          where (instr( lower(' ' || translate(trim(replace(a.INQUIRY_TEXT__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name6||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 7. SCAN/Load table MM_SAMPLETRANS_AE_VD                                                     *
      BEGIN
        insert into DM_RDW_AP_VD.MM_SAMPLETRANS_AE_VD
         (  COMMENTS_VOD__C     ,
      COMMENTS_VOD__C_HTML,
            ID                  ,
            NAME                ,
            CREATEDBYID         ,
            LASTMODIFIEDDATE    ,
            SYSTEMMODSTAMP)
         select
            distinct  a.COMMENTS_VOD__C   ,
      replace(replace(a.COMMENTS_VOD__C, chr(10),' '),
             substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMMENTS_VOD__C_HTML,
            a.ID                ,
            a.NAME              ,
            a.CREATEDBYID       ,   
            a.LASTMODIFIEDDATE  ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_SAMPLETRANS_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID), dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b
          --where (b.country_code = 'EN' and instr( lower(a.COMMENTS_VOD__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENTS_VOD__C is not null)
       where (b.country_code = 'EN' and instr( lower(' ' || translate(trim(replace(a.COMMENTS_VOD__C , chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1 ) > 0) and a.COMMENTS_VOD__C  is not null
         union
         select
            a.COMMENTS_VOD__C   ,
      replace(replace(a.COMMENTS_VOD__C, chr(10),' '),
             substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))),
                '<FONT style="BACKGROUND-COLOR: yellow"><b>' || substr(replace(a.COMMENTS_VOD__C, chr(10),' '), instr(replace(replace(lower(a.COMMENTS_VOD__C), chr(10),' '), chr(13), ''), lower(trim(b.Keyword)), 1,1), length(trim(b.Keyword))) || '</b></FONT>'
            ) as COMMENTS_VOD__C_HTML,
            a.ID                ,
            a.NAME              ,
            a.CREATEDBYID       ,   
            a.LASTMODIFIEDDATE  ,
            a.SYSTEMMODSTAMP
          from (DA_RDW_AP.DM_SAMPLETRANS_AE_VD a LEFT OUTER JOIN dm_rdw_ap_vd.mm_user_ae_vd c on a.CREATEDBYID=c.ID LEFT OUTER JOIN
          dm_rdw_ap_vd.CFG_ADVERSE_KEYWORD b on b.country_code = c.COUNTRY_CODE_BI__C)
          --where instr( lower(a.COMMENTS_VOD__C), lower(b.Keyword) , 1, 1 ) > 0 and a.COMMENTS_VOD__C is not null;
       where (instr( lower(' ' || translate(trim(replace(a.COMMENTS_VOD__C, chr(10),' ')), '().,:;?!', ' ') || ' '), lower(' ' || trim(b.Keyword) || ' ') , 1, 1) > 0) and b.Keyword is not null;
          DBMS_OUTPUT.PUT_LINE (v_table_name7||' - '||SQL%ROWCOUNT||' records loaded' );
          commit;   
      EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
      END;
    ** 8.Load table MM_ADVERSE_EVENT_ALL                                                                  *
       BEGIN  
        insert into MM_ADVERSE_EVENT_ALL
        ( COUNTRY_CODE_BI__C ,
          CALLDATE         ,
          COMMENTS     ,
       COMMENTS_HTML     ,
          OWNERID       ,
       LASTMODIFIEDDATE ,
       RECORDTYPE ,
       SORT ,
          SYSTEMMODSTAMP )
      select nvl(a.country_code_bi__c, b.country_code_bi__c) as country_code_bi__c,
      a.calldate,
      a.comments,
      a.comments_html,
      a.ownerid,
      a.lastmodifieddate,
      a.recordtype,
      a.sort,
      a.systemmodstamp
      from (select
      country_code_bi__c,
      call_date_vod__c as calldate,
      next_call_notes_vod__c as comments,
      next_call_notes_vod__c_html as comments_html,
      ownerid,
      lastmodifieddate,
      'Call' as recordtype,
      '1' as sort,
      systemmodstamp
      from mf_call_ae_vd
      union
      select
      country_code_bi__c,
      lastmodifieddate as calldate,
      comments_bi__c as comments, 
      comments_bi__c_html as comments_html, 
      ownerid,
      lastmodifieddate,
      'Change Request' as recordtype,
      '2' as sort,
      systemmodstamp
      from mm_change_request_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      competitor_insights_bi__c as comments,
      competitor_insights_bi__c_html as comments_html,
      ownerid,
      lastmodifieddate,
      'Competitor Insight' as recordtype,
      '3' as sort,
      systemmodstamp
      from mm_competitor_insight_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      comment_formulary_bi__c as comments,
      comment_formulary_bi__c_html as comments_html,
      ownerid,
      lastmodifieddate,
      'Formulary' as recordtype,
      '4' as sort,
      systemmodstamp
      from mm_formulary_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      inquiry_text__c as comments,
      inquiry_text__c_html as comments_html,
      createdbyid as ownerid,
      lastmodifieddate,
      'Customer Request' as recordtype,
      '5' as sort,
      systemmodstamp
      from mm_med_inquiry_ae_vd
      union
      select
      null,
      lastmodifieddate as calldate,
      comments_vod__c as comments,
      comments_vod__c_html as comments_html,
      createdbyid as ownerid,
      lastmodifieddate,
      'Sample Transaction' as recordtype,
      '6' as sort,
      systemmodstamp
      from mm_sampletrans_ae_vd
      ) a LEFT OUTER JOIN mm_user_ae_vd b on a.ownerid=b.ID;
        DBMS_OUTPUT.PUT_LINE (v_table_name8||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END; 
    ** 9.Load table MM_USER_COUNTRY_AE_VD                                                               *
       BEGIN  
        insert into MM_USER_COUNTRY_AE_VD
        ( REGION       ,
          COUNTRY_CODE ,
          COUNTRY_NAME )
      select distinct
      case
      when u.country_code_bi__c in  ('AE','BH','EG','JO','KW','LB','OM','QA','SA') then ('EMEA')
      when u.country_code_bi__c in  ('AU','CN','HK','ID','IN','JP','KR','MY','PH','SG','TH','TW', 'VN') then ('APAC')
      when u.country_code_bi__c in  ('BR','CA','MX','US' ) then ('AMERICA')
          --when u.country_code_bi__c in  ('AU', 'CN','IN','JP','KR','MY', 'TH','TW') then ('APAC')
          --when u.country_code_bi__c in  ('CA','CE','CR','DO','GT','HN','NI','PA','SV','US') then ('AMERICA')
      else (null)
      end as REGION,
      u.country_code_bi__c AS COUNTRY_CODE,
      decode (u.country_code_bi__c,
      'AE', 'United Arab Emirates',
        'BH', 'Bahrain',
      'EG', 'Egypt',
      'JO', 'Jordan',
      'KW', 'Kuwait',
      'LB', 'Lebanon',
      'OM', 'Oman',
      'QA', 'Qatar',
      'SA', 'Saudi Arabia',
        'AU', 'Australia',
      'CN', 'China',
      'HK', 'Hong Kong',
      'ID', 'Indonesia',
      'IN', 'India',
        'JP', 'Japan',
      'KR', 'Korea',
      'MY', 'Malaysia',
      'PH', 'Philippines',
      'SG', 'Singapore',
      'TH', 'Thailand',
      'TW', 'Taiwan',
      'VN', 'Vietnam',
      'BR', 'Brazil',
      'CA', 'Canada',
        'MX', 'Mexico',
        'US', 'United States') AS COUNTRY_NAME
      from DA_RDW_AP.DM_USER_AE_VD u, DA_RDW_AP.DF_CALL_AE_VD c
      where u.id = c.ownerid
      and u.country_code_bi__c is not null
      order by region, country_name;
        DBMS_OUTPUT.PUT_LINE (v_table_name9||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END;
    ** 10. Load table CFG_AE_CONCAT_KEYWORD - Load concatenated data in a single record by country code *
       BEGIN  
        insert into DM_RDW_AP_VD.CFG_AE_CONCAT_KEYWORD
         (COUNTRY_CODE ,
        KEYWORD)
        select country_code, replace(output, ',', ', ') as keyword
        from
          (select country_code, wm_concat(trim(keyword)) over (partition by country_code order by rownumber) as output,
             count(keyword) over (partition by country_code order by rownumber) as running_count,
             count(keyword) over (partition by country_code) as tot_count
          from DM_RDW_AP_VD.CFG_ADVERSE_KEYWORD)
          where running_count = tot_count;
        DBMS_OUTPUT.PUT_LINE (v_table_name10||' - '||SQL%ROWCOUNT||' records loaded' ); 
        commit;
       EXCEPTION
          WHEN OTHERS THEN
            v_error_count := v_error_count + 1;
            v_error_code  := TO_CHAR(sqlcode);
            v_error_text  := SUBSTR(sqlerrm, 1, 110);
            RAISE procedure_err;
       END;  
    ** Mandatory record for burst query                                                            *
      BEGIN  
           insert into DM_RDW_AP_VD.MF_CALL_AE_VD
            ( ID                      ,
              NAME                    ,
              CALL_DATE_VOD__C        ,
              PRE_CALL_NOTES_VOD__C   ,
              NEXT_CALL_NOTES_VOD__C  ,
              NEXT_CALL_NOTES_VOD__C_HTML,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              LASTMODIFIEDDATE        ,
              SYSTEMMODSTAMP)
      select
              ID                      ,
              NAME                    ,
              sysdate - 1             ,
              PRE_CALL_NOTES_VOD__C   ,
              NEXT_CALL_NOTES_VOD__C  ,
              NEXT_CALL_NOTES_VOD__C_HTML,
              COUNTRY_CODE_BI__C      ,
              OWNERID                 ,
              sysdate - 1             ,
              sysdate - 1
        from DM_RDW_AP_VD.MF_CALL_AE_VD_DUMMY;
          DBMS_OUTPUT.PUT_LINE (v_table_name2||' - '||SQL%ROWCOUNT||' records loaded' ); 
          commit;
         EXCEPTION
            WHEN OTHERS THEN
              v_error_count := v_error_count + 1;
              v_error_code  := TO_CHAR(sqlcode);
              v_error_text  := SUBSTR(sqlerrm, 1, 110);
              RAISE procedure_err;
      END;
    END LOAD_DM_AE_DATA_PRC;

    In following replace.. replace.. substr what are you trying to achieve? Can you please eg. so that we can try to use regular expression to do what being done by so many replace, substrs... This will help improve code performance and readability!
    ** 2. SCAN/Load table MF_CALL_AE_VD *
              replace(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10), ' '),
                      substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10), ' '),
                             instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C),
                                                   chr(10),
                                           chr(13),
                                   lower(trim(b.Keyword)),
                                   1,
                                   1),
                             length(trim(b.Keyword))),
                      '<FONT style="BACKGROUND-COLOR: yellow"><b>' ||
                      substr(replace(a.NEXT_CALL_NOTES_VOD__C, chr(10), ' '),
                             instr(replace(replace(lower(a.NEXT_CALL_NOTES_VOD__C),
                                                   chr(10),
                                           chr(13),
                                   lower(trim(b.Keyword)),
                                   1,
                                   1),
                             length(trim(b.Keyword))) || '</b></FONT>'
                      ) as NEXT_CALL_NOTES_VOD__C_HTML,

  • Help with analytical function   (ora 9...)

    Hi everyone, is there a way to fill some missing numbers based on what have come before and after that missing number by starttime and based on how many missing data are between? ... by "simple" select? I know how to do that just theoreticly with simple math commands, but is there a way to apply them in sql (analytical functions)?
    Thanks in advance for any ideas !
    The missing number on line 17 could be calculated as 339+(1/2)*(356-339) = 347,5
    The missing number on line 23 could be calculated as 355+(1/3)*(292-355) = 334
    The missing number on line 24 could be calculated as 355+(2/3)*(292-355) = 313
    rownumber + temp_table (starttime,data_column)
    15     23.5.2007 16:15     ,     258
    16     23.5.2007 16:30     ,     339
    17     23.5.2007 16:45     ,     
    18     23.5.2007 17:00     ,     356
    19     23.5.2007 17:15     ,     373
    20     23.5.2007 17:30     ,     355
    21     23.5.2007 17:45     ,     363
    22     23.5.2007 18:00     ,     355
    23     23.5.2007 18:15     ,     
    24     23.5.2007 18:30     ,     
    25     23.5.2007 19:00     ,     292
    26     23.5.2007 19:15     ,     295
    THANKS
    Message was edited by:
    dusoo

    Way too late, but I wouldn't let my effort go unpublished ;-)
    SQL> create table temp_table
      2  as
      3  select 15 rownumber, to_date('23.5.2007 16:15','dd.mm.yyyy hh24:mi') starttime, 258 data_column from dual union all
      4  select 16, to_date(' 23.5.2007 16:30','dd.mm.yyyy hh24:mi'), 339 from dual union all
      5  select 17, to_date(' 23.5.2007 16:45','dd.mm.yyyy hh24:mi'), null from dual union all
      6  select 18, to_date(' 23.5.2007 17:00','dd.mm.yyyy hh24:mi'), 356 from dual union all
      7  select 19, to_date(' 23.5.2007 17:15','dd.mm.yyyy hh24:mi'), 373 from dual union all
      8  select 20, to_date(' 23.5.2007 17:30','dd.mm.yyyy hh24:mi'), 355 from dual union all
      9  select 21, to_date(' 23.5.2007 17:45','dd.mm.yyyy hh24:mi'), 363 from dual union all
    10  select 22, to_date(' 23.5.2007 18:00','dd.mm.yyyy hh24:mi'), 355 from dual union all
    11  select 23, to_date(' 23.5.2007 18:15','dd.mm.yyyy hh24:mi'), null from dual union all
    12  select 24, to_date(' 23.5.2007 18:30','dd.mm.yyyy hh24:mi'), null from dual union all
    13  select 25, to_date(' 23.5.2007 19:00','dd.mm.yyyy hh24:mi'), 292 from dual union all
    14  select 26, to_date(' 23.5.2007 19:15','dd.mm.yyyy hh24:mi'), 295 from dual
    15  /
    Tabel is aangemaakt.
    SQL> with t as
      2  ( select t.*
      3         , max(case when data_column is not null then rownumber end) over (order by rownumber) lowerbound
      4         , last_value(data_column ignore nulls) over (order by rownumber) prevvalue
      5         , min(case when data_column is not null then rownumber end) over (order by rownumber desc) upperbound
      6         , last_value(data_column ignore nulls) over (order by rownumber desc) nextvalue
      7      from temp_table t
      8  )
      9  select rownumber
    10       , starttime
    11       , case
    12         when data_column is not null then data_column
    13         else   prevvalue * ((upperbound - rownumber) / (upperbound - lowerbound))
    14              + nextvalue * ((rownumber - lowerbound) / (upperbound - lowerbound))
    15         end data_column
    16    from t
    17   order by rownumber
    18  /
                                 ROWNUMBER STARTTIME                                      DATA_COLUMN
                                        15 23-05-2007 16:15:00                                    258
                                        16 23-05-2007 16:30:00                                    339
                                        17 23-05-2007 16:45:00                                  347,5
                                        18 23-05-2007 17:00:00                                    356
                                        19 23-05-2007 17:15:00                                    373
                                        20 23-05-2007 17:30:00                                    355
                                        21 23-05-2007 17:45:00                                    363
                                        22 23-05-2007 18:00:00                                    355
                                        23 23-05-2007 18:15:00                                    334
                                        24 23-05-2007 18:30:00                                    313
                                        25 23-05-2007 19:00:00                                    292
                                        26 23-05-2007 19:15:00                                    295
    12 rijen zijn geselecteerd.Regards,
    Rob.

  • Selecting/Ordering/ROWNUMBER in Oracle 9i

    Hello,
    I am trying to sort a large table by 'splitting' it in 2 ranges based on the numeric
    value of a varchar2 column:
    colA=varchar2(7) (represents a numeric range, like a transaction number)
    If hypothetically the table has 1000 rows I am trying to split it into 1-500 and 501-1000
    then I do:
    statement1:
    SELECT colA FROM (select rownum AS z,colA from TABLE1 ORDER BY lpad(colA,7) ASC ) WHERE z>=1 and z<501;
    statement2:
    SELECT colA FROM (select rownum AS z,colA from TABLE1 ORDER BY lpad(colA,7) ASC ) WHERE z>=501 and z<1001;
    This is not working: I am finding values of colA in the second statement output that
    should be in the first select range based on numeric value
    e.g.
    Doing MAX(colA) for statement1(lower range) gives 1030240
    Doing MIN(colA) for statement 2 (upper range) gives: 1000008
    In an ascending sort, the maximum value of colA in statement1 should be LESS than
    the minimum value of statement2 using the same sorting criteria.
    Why is this not working? It seems the ROWNUMs get jumbled up here...
    Does the "inner" select (select rownum AS z,colA from TABLE1 ORDER BY lpad(colA,7) ASC) attribute the ROWNUMs to the ordered set and then lose
    the ordering for the outer select?
    Any help greatly appreciated...

    If you split your table according to lpad(colA,7) - behaves like to_number(ColA)
    and then "check" the result by retrieving each range's min(ColA) and max(ColA) - varchar2 type
    the "strange" behaviour will not disappear
    =========================
    ColA  | lpad(ColA,7)
    =========================
    1     |       1
    12    |      12
    123   |     123
    1234  |    1234
    12345 |   12345
    23456 |   23456
    3456  |    3456
    456   |     456
    78    |      78
    9     |       9
    =========================
    ColA  | ordered | rownum
    =========================
    1     |       1 |  1     <= lower range ColA minimum
    9     |       9 |  2     <= lower range ColA maximum
    12    |      12 |  3        lower range
    78    |      78 |  4        lower range
    123   |     123 |  5        lower range
    456   |     456 |  6        upper range
    1234  |    1234 |  7     <= upper range ColA minimum
    3456  |    3456 |  8        upper range
    12345 |   12345 |  9        upper range
    23456 |   23456 | 10     <= upper range ColA maximumRegards
    Etbin

  • Suppress "Order By" clause in Answers Query

    Hello,
    Is it possible to Suppress "Order By" clause in Answers Query.
    I'm using a database view as data source. In the view definition, "order by" clause is already specified. Is it possible to get the same order in the OBIEE report??
    I do not want to use Sort Order column in the repository.
    Thanks,
    Girish

    You add a rownumber to your DB view and use that to 'sort' your report.
    regards
    John
    http://obiee101.blogspot.com/

  • Error while updating Sales Order : Another user Modified Table (RDR1 )

    Hi All,
    I am getting an error message while running the following steps.
    Steps
    1)     Pull an entry from sales order.
    2)     Add new data to line.
    3)     Update the sales order.
    a)     Sap updated the data.
    b)     Through code using DI API we updated some UDF.
    4)     With out closing / Pressing OK button…
    5)     We added new data to line.
    6)     Then Press update.
    An Error will through by B1 as “Another user modified the table(RDR1 ).” Before going to the code where we are handling the update of UDF.
    But after the 3rd step above when we do
    4) Close the window or pressed ok
    5)  take the sales order window again pull the data
    6) Add new Data to line.
    7) Update sales order then it will go smoothly.(Updating by B1 and from code )
    Can anybody tell me why this happens?And any workarounds to solve this?
    Deepesh

    are u adding a matrix row thru the code? I get this error when I am adding rows and I get the rownumber out of sync.
    if so get the max (lineid) from rdr1 and then check against the matrix.rowcount before adding a row. if lineid is greater that matrix.rowcount take lineid + 1 and assign it to the matrix.row, else take the rowcount + 1
    if not, and as a workaround, then you can try using the SBO_SP_transactionnotification stored procedure.

  • Different ways to get the last 5 records ordered by date

    I have a query no that returns the tickets ordered by moddt, modification date,
    I was thinking of adding a select on top, to get the last 5 records of that list the select already generates. An other way was to use that select to create a view,
    and get the 5 last records that way. I also though of a possibly impossible cursor with a sequence, but hmm well I consider that not a good solution.
    So I'm trying to find a way, using a select, the topmost select which is not completed yet, to get the last 5 records. Maybe I should just try the rownumber thing again or something likewise.
    Select * from(
    select * from(
    Select ticketid, appliecatiecd, categorieid, substr(titel,&,200)||' ...' "titel", klantproriteitid, interneprioriteitid,
    (select g.voornaam||' '||g.naam
    from gebruiker g
    Where g.gebruikerid = t.gebruikerid
    And t.applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd))"aangemaakt door",
    (select s.statusdefoms "status"
    From status s
    Where s.statusid = t.statusid
    And t.applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd)) "status",
    Versieid,
    Moddt,
    Row_number() over (order by ticketid desc) rn
    From ticket t
    Where applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd) )
    Order by moddt)
    Where --

    Hi Floris,
    You can also use RANK: http://www.dba-oracle.com/oracle_news/oracle_faq/faq_beg_sql_top_n_rows.htm
    Regards Pete

  • WHERE clause comparing count and RowNumber

    Hello, I have just one more question with an error I'm running into. I'm wanting to use a WHERE or HAVING (tried both) to filter the returned data to be between a calculated RowNumber. I tried setting the filter on the tablix or using variables but neither
    one worked.I had some help getting the RowNumbers to work now I'm hoping to use that RowNumber to filter the data to only show the data in the middle 80* of what is returned. So what I'm trying to do is use count to find total number of rows. Then filter out
    the both 10% and top 90& using that count and then filtered on the RowNumbers.
    I tried using different syntax of WHERE and HAVING and I tried putting those clauses under the first WHERE clause or by itself outside of the second select (shown in the example now below). Nothing I've tried works. Is what I'm trying to do possible or is
    there another way I could do this if not?
    Thanks for the help, much appreciated!
    SELECT *,ROW_NUMBER() OVER (ORDER BY TTR) AS RowNumber FROM (
    SELECT
    FilteredIncidentResolution.incidentid,
    FilteredIncident.createdon,
    FilteredIncidentResolution.actualend,
    FilteredIncident.statecodename,
    FilteredIncident.casetypecodename,
    FilteredIncidentResolution.timespent,
    DATEDIFF(minute, FilteredIncident.createdon, FilteredIncidentResolution.actualend) as TTR
    FROM FilteredIncident INNER JOIN
    FilteredIncidentResolution ON FilteredIncident.incidentid = FilteredIncidentResolution.incidentid
    WHERE (FilteredIncident.statecodename = N'Resolved') AND (FilteredIncident.casetypecodename = N'Support') AND (FilteredIncidentResolution.actualend >= @start) AND
    (FilteredIncidentResolution.actualend <= @end)
    ) X
    WHERE RowNumber >= count(FilteredIncidentResolution.incidentid)*.1 AND RowNumber <= count(FilteredIncidentResolution.incidentid)*.9
    ORDER BY TTR

    You're making the same mistake as before. Calculated column can not be used in the WHERE clause. I think you're actually looking for the NTILE() function, but I will just fix your query:
    select * FROM (SELECT *,ROW_NUMBER() OVER (ORDER BY TTR) AS RowNumber FROM (
    SELECT
    FilteredIncidentResolution.incidentid,
    FilteredIncident.createdon,
    FilteredIncidentResolution.actualend,
    FilteredIncident.statecodename,
    FilteredIncident.casetypecodename,
    FilteredIncidentResolution.timespent,
    DATEDIFF(minute, FilteredIncident.createdon, FilteredIncidentResolution.actualend) as TTR,
    COUNT(FilteredIncidentResolution.incidentid)
    OVER() as TotalIncidents
    FROM FilteredIncident INNER JOIN
    FilteredIncidentResolution ON FilteredIncident.incidentid = FilteredIncidentResolution.incidentid
    WHERE (FilteredIncident.statecodename = N'Resolved') AND (FilteredIncident.casetypecodename = N'Support') AND (FilteredIncidentResolution.actualend >= @start) AND
    (FilteredIncidentResolution.actualend <= @end)
    ) X
    ) Y
    WHERE RowNumber >= TotalIncidents*.1 AND RowNumber <= TotalIncidents*.9 -- we're excluding top 10 and bottom 10
    ORDER BY TTR
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Deactivate Report re-ordering

    Hello,
    I'm using jQuery UI Sortable to order items in a Report using a custom template. As soon as a row gets a new rownumber I call a page process (type: AJAX Callback) which also changes some numbers on the source table. All this works quite fine, but as soon as I drop the item at a different row, it jumps back to where it came from. I guess this is because of the order function in my report. As soon as I refresh the page all lines are in the correct new order.
    Is there any possibility to tell the report, that it should only order the rows once in the beginning?
    If you want to see some Code as well:
    Javascript which listens for Changes:
    $( "#sortableList" ).sortable({
      items: "li",
      stop: function (event, ui) {
        var newIndex = $(this).find('li').index(ui.item)+1;
        $(this).sortable('cancel');  // revert changes
        var oldIndex = $(this).find('li').index(ui.item)+1;
        var get;
        get = new htmldb_Get(null, $v('pFlowId'), 'APPLICATION_PROCESS=ChangeOrderWHERE', $v('pFlowStepId'));
        get.add('PS1',oldIndex);
        get.add('PS2',newIndex);
        var gReturn = get.get();
    Format of the Report:
    <ul>
    <li><p>Informations about item 1</p></li>
    <li><p>Informations about item 2</p></li>
    </ul>

    Hi Nik,
    The sort shouldn't matter to be honest, as long as your not refreshing the report then your just working in the browser and it doesn't matter what changes you make.
    I find this piece interesting:
      var newIndex = $(this).find('li').index(ui.item)+1;
        $(this).sortable('cancel');  // revert changes
        var oldIndex = $(this).find('li').index(ui.item)+1;
    Your collecting the new indexes and then your sending them to the database. But I don't see anywhere were you are also changing the indexes on the client side to the new indexes.
    That would explain why they jump back I think, because they think the old index is the new index.
    Regards,
    Joni

  • Open Sales Orders Backlog Report

    Hi All: I have been asked to create Backlog reports for Open Sales Orders and the revenue amounts for the next 15days, one month, 2 months, 3 months 6 months etc etc. Does anyone know of a standard report that covers that and the business content and cues that go with it?
    Thanks in advance
    Bobby

    I haven't seen any standard content for it, with my client, we actually developed the open order report from Item extractor and status extractor. And compare the created on date to the system data to see how long it has been opened for and put it in different buckets.
    Hopes that help.
    thanks.
    Wond.

  • Open sale order aging report

    Need a report on open order aging.  The open order means not delivered or partially delivered. Further with days range since its open or not fully delievered i.e. > 15 days or 15-30 days and so on.
    The standard transactions Va05 and VL10c can provide the list but dont provide any aging info.
    Kindly help in this.
    thanks
    anu

    Dear Anu
    1. First in VA05 you can use Variants and get the report as desired by you,create one variant and use Filter along with greater then, less then (all are in selection option icon)
    This way you can create three variants.
    But limitation is dates has to be manually changed in variants each time.
    2. Try this Tcodes
    S_ALR_87014387 Display Document Flow
    S_ALR_87014392 Display Document Flow
    This reports will give you document flow run report with ticking checkbox for sales order,delivery and goods isse then after getting the list expand all (Shift+F12)
    you will get the quantities for sales order, and what is delivered and what is issued.
    3. As such if you want exactly the report you can take help of ABAP to create the ALV
    4. Report or create Queries in SQVI , or else create MCSI report
    Regards
    Jitesh

  • Necessary Fields For Creation of Service PO of Order Type Relaese Order.

    Dear Guru,
    I have encountered an issue which i am trying to resolve...
    My this requirment will seem little okward the way i am asking but i have no way...
    The issue is I have to create a Service PO of Order type Release order (RO) using BAPI Function Module .BAPI_PO_CREATE1.
    The service PO should be of multiple Item and services for particular line item should be multiple.
    When I am creating this using ME21 or ME21N i am facing no issue.
    But when i am using BAPI Function Module .BAPI_PO_CREATE1
    i am getting following errors ;; The error which i am getting as below                                                                               
    T ID                   NUM MESSAGE                                                                               
    E BAPI                001 No instance of object type PurchaseOrder has been created. External reference:
    E MEPO              000 Purchase order still contains faulty items                                    
    E SE                   029 Please maintain services or limits                                            
    E SE                   140 Service HIRING OF LCD: please specify unit of measure
    But I am failing to findout in which field services  or limits and unit of measurement have to maintain.
    What are the necessary fields have to pass in Bapi import parameter and the table i am unable to findout.
    Please show some way how to resolve this or give me some guideline to resolve this
    Dear Moderator request your kind intervane to move this qurry into correct forum if i have asked this in wrong forum
    Thanks and regards
    saifur rahaman

    Hi Saifur
    Can you please elaborate how did you resolve the issue we are also facing same problem when we are trying to create the PO for service items through SRM it is throwing same error while creating the PO in SAP.
    Email Id : [email protected]
    Thank you in advance!!
    Regards
    Deepika

  • How to restrict manual changing of free goods in sales order

    Hi ,
    Goodmorning ,
    We have some requirement : In sales order free goods quantity determination by system  should not be allowed to change manually , where can we do this ?
    Looking for your inputs
    Thanks and regards
    Venkat

    As per SAP Standard, when the main Item quantity is changed, the Free Goods are redetermined. In this case any manual changes to Free Goods Quantities are lost.
    But your requirement is for restricting the Chages of the Quantity of Free Goods Correct?
    I believe there is no SAP standard solution for this. You will have to apply a User Exit, which will check the Item category of each LIne item & if it is free goods (TANN) then changes are not permitted.
    Hope this helps.
    Thanks,
    Jignesh Mehta

Maybe you are looking for