Select statement without using Rownum or Rowid

Hi,
I have a requirement where I have delete the first 100 records from table without using the rownum or rowid.
Thanks to all for your time
Narain

Hi
delete from yourtab x where (select count(*) from yourtab where yourpk <= x.yourpk) < 101;HTH
Laurent Schneider
OCM DBA

Similar Messages

  • Needs  help to retrive the last row in a  select query without using rownum

    Hi ,
    i need to retrive the last row from the select sub query without using rownum.
    is there any other way to retrive the last row other than the below query.
    is that the ROWNUM=1 will always retrive the 1 row of the select query ?
    select from*
    *(select ename from employee where dept_id=5 order by desc) where rownum=1;*
    Please advise.
    thanks for your help advance,
    regards,
    Senthur

    957595 wrote:
    Actually my problem is ithat while selecting the parents hiearchy of the child data using
    CONNECT BY PRIOIR query
    I need the immediate parent of my child data.
    For example my connect BY query returns
    AAA --- ROOT
    BBB --PARENT -2
    CCC --PARENT-1
    DDD IS my input child to the connect by query
    Immediate parent of my child data "DDD" ---> CCC(parent -1)
    i want the data "CCC" from the select query,for that i am taking the last row of the query with rownum.
    I got to hear that using ROWNUM to retrive the data will leads to some problem.It is a like a magic number.I am not sure what the problem will be.
    So confusing with using this rownum in my query.
    Please advice!!!It's not quite clear what you're wanting, but perhaps this may help?
    you can select the PRIOR values to get the parent details if you want...
    SQL> ed
    Wrote file afiedt.buf
      1  select empno, lpad(' ',(level-1)*2,' ')||ename as ename, prior empno as mgr
      2  from emp
      3  connect by mgr = prior empno
      4* start with mgr is null
    SQL> /
         EMPNO ENAME                                 MGR
          7839 KING
          7566   JONES                              7839
          7788     SCOTT                            7566
          7876       ADAMS                          7788
          7902     FORD                             7566
          7369       SMITH                          7902
          7698   BLAKE                              7839
          7499     ALLEN                            7698
          7521     WARD                             7698
          7654     MARTIN                           7698
          7844     TURNER                           7698
          7900     JAMES                            7698
          7782   CLARK                              7839
          7934     MILLER                           7782
    14 rows selected.(ok, not the best of examples as the mgr is already known for a row, but it demonstrates you can select prior data)

  • Case sensitivity select statement without using native sql

    please help me ,
    i have a selection screen as select-options : s_vbeln, s_kunnr(mandt),s_matnr and
    p_name as a parameter (type name1) which is case sensitive in sap abap database and i want to get
    output  from these fields in an alv.[vbeln,kunnr,name1,audat,auart,matnr,kwmeng,netwr]
    How to do it? Can any one give me solution please.[i have to handle case sensitivity plz give me solution]

    this is my code : but its not working as i expected plz tell me where did i went wrong...
    type-pools slis.
    tables : vbak , vbap.
    select-options : s_vbeln for vbak-vbeln,
                     s_kunnr for vbak-kunnr,
                     s_matnr for vbap-matnr.
    parameters p_name1 type NAME1_GP.
    ranges r_name for kna1-name1.
    types : begin of ty_vbak,
            vbeln type vbeln_va,
            audat type audat,
            auart type auart,
            kunnr type kunnr,
            end of ty_vbak,
            begin of ty_vbap,
            vbeln type vbeln_va,
            matnr type matnr,
            netwr type netwr_ap,
           kwmeng type kwmeng,
            end of ty_vbap,
            begin of ty_kna1,
            kunnr type kunnr,
            name1 type name1,
            end of ty_kna1,
            begin of ty_final,
            vbeln type vbeln_va,
            audat type audat,
            auart type auart,
            matnr type matnr,
            netwr type netwr_ap,
           kwmeng type kwmeng,
            kunnr type kunnr,
            name1 type name1,
            end of ty_final.
    data : t_vbak type standard table of ty_vbak initial size 1,
           t_vbap type standard table of ty_vbap initial size 1,
           t_kna1 type standard table of ty_kna1 initial size 1.
    data : t_final type standard table of ty_final initial size 1,
           w_final type ty_final,
           w_vbap  type ty_vbap,
           w_kna1  type ty_kna1,
           w_vbak  type ty_vbak.
    data : t_fcat type slis_t_fieldcat_alv,
           w_fcat type slis_fieldcat_alv.
    DATA T_FINAL2 TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 1.
    data v_name1 type name1.
    if p_name1 is not initial.
    r_name-sign = 'I'.
    r_name-option = 'EQ'.
    if p_name1 ca '*'.
    r_name-option = 'CP'.
    endif.
    r_name-low = p_name1.
    append r_name.
    endif.
    start-of-selection.
    select vbeln audat auart kunnr from vbak
    into table t_vbak
    where vbeln in s_vbeln and
          kunnr in s_kunnr.
    if sy-subrc <> 0.
    message 'plz enter a valid entry' type 'I'.
    leave list-processing.
    endif.
    if t_vbak[] is not initial.
    select vbeln matnr netwr kwmeng from vbap
    into table t_vbap
    for all entries in t_vbak
    where vbeln = t_vbak-vbeln and
    matnr in s_matnr.
    if sy-subrc <> 0.
    message 'no rec found' type 'I'.
    leave list-processing.
    endif.
    select kunnr name1 from kna1
    into table t_kna1
    for all entries in t_vbak
    where kunnr = t_vbak-kunnr.
    if sy-subrc = 0.
    sort t_kna1 by kunnr.
    endif.
    endif.
    end-of-selection.
    loop at t_vbap into w_vbap.
    read table t_vbak into w_vbak with key vbeln = w_vbap-vbeln binary search.
    read table t_kna1 into w_kna1 with key kunnr = w_vbak-kunnr binary search.
    w_final-vbeln = w_vbak-vbeln.
    w_final-audat = w_vbak-audat.
    w_final-auart = w_vbak-auart.
    w_final-matnr = w_vbap-matnr.
    w_final-netwr = w_vbap-netwr.
    w_final-kwmeng = w_vbap-kwmeng.
    w_final-kunnr  = w_kna1-kunnr.
    w_final-name1  = w_kna1-name1.
    append w_final to t_final.
    endloop.
    delete t_final where name1 not in r_name.
    perform sub_fill_fcat using 'VBELN' 'SALE ORDER NUM'.
    perform sub_fill_fcat using 'KUNNR' 'CUSTOMER NUMBER'.
    perform sub_fill_fcat using 'NAME1' 'NAME OF A CUST'.
    perform sub_fill_fcat using 'AUDAT' 'SALE ORDER DATE'.
    perform sub_fill_fcat using 'AUART' 'SALE DOC TYPE'.
    perform sub_fill_fcat using 'MATNR' 'MATERIAL NUM'.
    perform sub_fill_fcat using 'KWMENG' 'QUANTITY'.
    perform sub_fill_fcat using 'NETWR' 'PRICE'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
        IT_FIELDCAT                       = T_FCAT
      TABLES
        T_OUTTAB                          = T_FINAL
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
    IF SY-SUBRC <> 0.
    * Implement suitable error handling here
    ENDIF.
    *&      Form  SUB_FILL_FCAT
    *       text
    *      -->P_0389   text
    *      -->P_0390   text
    FORM SUB_FILL_FCAT  USING P_FNAM P_TEXT.
    clear w_fcat.
    w_fcat-fieldname = p_fnam.
    w_fcat-seltext_m = p_text.
    append w_fcat to t_fcat.
    ENDFORM.

  • Select criteria without using SELECTION SCREENs

    Hi everybody,
    I have a report with a single screen, 4 fields for search criteria and 2 alv grids for the output.
    I search db tables with a select statement.
    Is it possible to define a select statement that searches for 3 out of 4 criteria, if the fourth input field isn't filled it?
    Because right now the select statement doesn't return any data if I leave one parameter blank.
    And how can I provide the possibility to define more than one search criteria of one kind withour adding several input fields on the screen?
    For example: Data created on 20070101 and 20070105.
    I know that most of this can be done with selection screens, but is there a possibility to do this without a selection screen?
    Best regards
    Tobias

    You should use SELECT-OPTIONS on your selection screen.  This allows the user to enter all kinds of possiblities, including leaving something blank.  Then in your SELECT statement, you use the IN operator.
    select-options: s_datum for sy-datum.
    select * into table itab
               from ztable
                      where datum IN s_datum.
    If you truly do not want to use a Selection-screen, you could hard code values in the SELECT statement or create a range using the RANGE statement.  The RANGE statement works exactly like SELECT-OPTION statement but without the selection-screen.
    Regards,
    Rich Heilman

  • How to compile the hint to force selection statement to use index

    Hello expert,
    will you please tell me how to compile the hint to force selection statement to use index?
    Many Thanks,

    Not sure what you mean by compile, but hint is enclosed in /*+ hint */. Index hint is INDEX(table_name,index_name). For example:
    SQL> explain plan for
      2  select * from emp
      3  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 3956160932
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |    14 |   546 |     3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| EMP  |    14 |   546 |     3   (0)| 00:00:01 |
    8 rows selected.
    SQL> explain plan for
      2  select /*+ index(emp,pk_emp) */ *
      3  from emp
      4  /
    Explained.
    SQL> @?\rdbms\admin\utlxpls
    PLAN_TABLE_OUTPUT
    Plan hash value: 4170700152
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |        |    14 |   546 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| EMP    |    14 |   546 |     2   (0)| 00:00:01 |
    |   2 |   INDEX FULL SCAN           | PK_EMP |    14 |       |     1   (0)| 00:00:01 |
    9 rows selected.
    SQL> Hint in the above example is forcing optimizer to use index which resul;ts in a bad execution plan. Most of the time optimizer does not need hints and chooses an optimal plan. In most cases sub-optimal plan is result of stale or incomplete statistics.
    SY.

  • Restricting number of rows in EJB  QL    using rowNum or rowId

    Hii Javaites
    I am using EJB finder methods to get a a list of records from database.
    Now i want that only particular number of records should be fetched.
    For tht i want 2 use rownum or rowId.
    Can anyone plz tell me can we do tht in EJB QL.
    I m using Weblogic 8

    shouldn't use rownum or rowid to do such a thing.
    %

  • How to display icons on selection screen ,without using classes.

    Hi Experts,
    How can we display icons on the selection-screen ..?
    one of the methods i heard frm my frnds was to use                   ->cl_gui_picture_viewer
    but as a begginer i am not tht comfortable with classes .So is there a way around to display icons on my selection screen without using classes .
    Thanx in Advance,
    Regards ,
    Rajesh .

    Hi,
    here a short example:
    REPORT Z_TEST2.
    TABLES: SSCRFIELDS.   "Felder auf Selektionsbildern
    INCLUDE .
    SELECTION-SCREEN: BEGIN OF BLOCK A01 WITH FRAME TITLE MELDUNG1.
    SELECTION-SCREEN: SKIP 2.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 10(04) T_ICON.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: SKIP.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFSD.
    PARAMETERS:       P_AUFSD  AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFCO.
    PARAMETERS:       P_AUFCO  AS CHECKBOX DEFAULT ' '.
    SELECTION-SCREEN: PUSHBUTTON 45(04) PB01 USER-COMMAND SALL.
    SELECTION-SCREEN: PUSHBUTTON 50(04) PB02 USER-COMMAND DALL.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFCS.
    PARAMETERS:       P_AUFCS  AS CHECKBOX DEFAULT ' '.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 01(34) T_AUFPP.
    PARAMETERS:       P_AUFPP  AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN: PUSHBUTTON 45(15) PB03 USER-COMMAND INIT.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: SKIP 2.
    SELECTION-SCREEN: BEGIN OF LINE.
    SELECTION-SCREEN: PUSHBUTTON 45(15) PB04 USER-COMMAND ONLI.
    SELECTION-SCREEN: END   OF LINE.
    SELECTION-SCREEN: SKIP 2.
    SELECTION-SCREEN: END   OF BLOCK A01.
    AT SELECTION-SCREEN.
      IF SSCRFIELDS-UCOMM = 'SALL'. "alle selektieren
        P_AUFSD = 'X'.
        P_AUFCO = 'X'.
        P_AUFCS = 'X'.
        P_AUFPP = 'X'.
      ENDIF.
      IF SSCRFIELDS-UCOMM = 'DALL'. "alle deselektieren
        P_AUFSD = ' '.
        P_AUFCO = ' '.
        P_AUFCS = ' '.
        P_AUFPP = ' '.
      ENDIF.
      IF SSCRFIELDS-UCOMM = 'INIT'. "initialisiern
        P_AUFSD = 'X'.
        P_AUFCO = ' '.
        P_AUFCS = ' '.
        P_AUFPP = 'X'.
      ENDIF.
    INITIALIZATION.
      MELDUNG1 = 'Datenbankselektion'.
      T_ICON   = ICON_PRINT.
      T_AUFSD  = 'Kundenauftrag'.
      T_AUFCO  = 'Innenauftrag'.
      T_AUFCS  = 'Serviceauftrag'.
      T_AUFPP  = 'Fertingungsauftrag'.
      PB01     = ICON_SELECT_ALL.
      PB02     = ICON_DESELECT_ALL.
      CONCATENATE ICON_REFRESH 'Initial' INTO PB03.
      CONCATENATE ICON_EXECUTE_OBJECT 'Ausführen' INTO PB04.
    START-OF-SELECTION.
    write: / 'Test'.
    END-OF-SELECTION.
    Regards, Dieter

  • Using temporary tablespace for sort in select statement without spacifying

    how can i use some particular temporary tablespace in select statement for sording without allocating any temporary tablespace to that user

    Try to set for the current session the in memory sorting space to 0 before running your query:
    SQL> alter session set sort_area_size = 0;The query should use the temporary tablespace.
    Message was edited by:
    Pierre Forstmann

  • Using Rownum and ROwid returns duplicate records

    Hi All,
    We have implemented pagination as below using rowid and rownum
    SELECT
    id
    FROM
    emp
    WHERE
    ROWID IN
    SELECT RID FROM (SELECT
    ROWID RID,
    ROWNUM RNUM
    FROM
    SELECT ID FROM emp
    WHERE
    ((T_ID IN (200005,200229,200230,200249,200250,200049))) AND
    (dte >= sysdate-90) AND
    (LOWER(DESC) = LOWER ('A') AND
    LOWER(NVL(FLAG,'0')) != LOWER ('3') AND
    LOWER(MODDE) like LOWER ('%210%')) ORDER BY dte ASC ))
    WHERE ROWNUM < 11) WHERE RNUM>= 1)) ORDER BY dte emp.ASC
    But, we face that - the query inserts duplicate records in consecutive pages. For Eg:
    1.if a,b,c,d,e - is returned for first iteration, then for the next iteration - f,g,h,a,y is returned.
    Is it because that the Order by clause doesnt have a Unique key column.
    Please help. or suggest how to efficietly implement pagination without performance hit

    try distinct since you are using only one column it will eliminate any duplicates.
    SELECT distinct id
      FROM emp
    WHERE (ROWID IN ( SELECT RID
                         FROM (SELECT ROWID RID,ROWNUM RNUM
                                 FROM (SELECT ID
                                         FROM emp
                                        WHERE ((T_ID IN (200005,200229,200230,200249,200250,200049)))
                                          AND (dte >= sysdate-90)
                                          AND (LOWER(DESC) = LOWER ('A')
                                          AND LOWER(NVL(FLAG,'0')) != LOWER ('3')
                                          AND LOWER(MODDE) like LOWER ('%210%'))
                                       ORDER BY dte ASC ))
                                WHERE ROWNUM < 11) 
                        WHERE RNUM>= 1))
    ORDER BY dte emp.ASC

  • Inserting multiple rows using a single Insert statement without using dual

    Hi all,
    i am trying to insert multiple rows using a single insert statement like the below one.
    The below one works fine..
    But is there any other change that can be done in the below one without using dual...
    insert all
    into ps_hd_samp (num1,num2) values (1,1)
    into ps_hd_samp (num1,num2) values (2,2)
    into ps_hd_samp (num1,num2) values (3,3)
    select 1 from dual;

    NiranjanSe wrote:
    Hi all,
    i am trying to insert multiple rows using a single insert statement like the below one.
    The below one works fine..
    But is there any other change that can be done in the below one without using dual...
    insert all
    into ps_hd_samp (num1,num2) values (1,1)
    into ps_hd_samp (num1,num2) values (2,2)
    into ps_hd_samp (num1,num2) values (3,3)
    select 1 from dual;
    SQL> create table ps_hd_samp (num1 number,num2 number);
    Table created.
    SQL> insert all
      2  into ps_hd_samp (num1,num2) values (1,1)
      3  into ps_hd_samp (num1,num2) values (2,2)
      4  into ps_hd_samp (num1,num2) values (3,3)
      5  select count(*)
      6  from ps_hd_samp;
    3 rows created.
    SQL> select * from ps_hd_samp;
          NUM1       NUM2
             1          1
             2          2
             3          3

  • Using Refcursor in Callable Statement without using the Oracle Drivers

    Hello all,
    Is there anyway to have a stored procedure (Oracle 8i) return a refcursor to my CallableStatement without using the Oracle Thin drivers (i'm now using jdbcodbc). I've tried registering my out parameter with every possible type i can think of...REF, JAVA_OBJECT, OTHER, etc. but with no luck.
    Help!!!!

    Certainly...I connect to the database using the
    jdbcodbc driver and when i execute any of the code, i
    get the following error:
    java.sql.SQLException: [Oracle][ODBC][Ora]ORA-06550:
    line 1, column 7:
    PLS-00306: wrong number or types of arguments in call
    to 'PVISUAL_GET'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    It's bombing on the line that i attempt to register
    OracleTypes.CURSOR. It works fine when i use the
    oracle thin drivers, but i want to get this puppy
    working with the JdbcOdbcDriver. Here's the code:
    CallableStatement dbCall =
    nt dbCall =
    (CallableStatement)connection.prepareCall("{ call
    PAK_VISUAL_GET.pvisual_get(?, ?, ?, ?, ?, ?) }");
    dbCall.setString(1, sessionKey);
    dbCall.setInt(2,
    l.setInt(2, Integer.parseInt(storedVizID));
    dbCall.registerOutParameter(3,
    arameter(3, OracleTypes.CURSOR);
    dbCall.registerOutParameter(4,
    arameter(4, OracleTypes.NUMBER);
    dbCall.registerOutParameter(5,
    arameter(5, OracleTypes.VARCHAR);
    dbCall.registerOutParameter(6,
    arameter(6, OracleTypes.NUMBER);
    dbCall.execute();when you don't use oracle thin driver, you cannot use the OracleTypes. but, instead use the java.sql.Types values.Replace dbCall.registerOutParameter(3, OracleTypes.CURSOR); with
    dbCall.registerOutParameter(3,java.sql.Types.OTHER). things should be fine.
    Ganesh

  • How to set client within SQL statement without using another pl/sql stmt.

    I have a following select statement
    SELECT SUM (w.prior_forecasted_costs + w.prior_committed_costs)
    FROM xxsuf.job_cost_summary_table w,
    apps.pa_periods p,
    pa.pa_resources bz,
    pa.pa_resource_list_members cz,
    pa.pa_tasks dz
    WHERE w.project_id = z.project_id
    AND w.task_id = dz.task_id
    AND dz.task_number '98000'
    AND w.resource_list_member_id = cz.resource_list_member_id
    AND cz.resource_id = bz.resource_id
    AND NOT EXISTS (SELECT NULL
    FROM pa.pa_tasks zz
    WHERE zz.parent_task_id = dz.task_id)
    AND w.resource_list_member_id != 1000
    AND p.period_name = w.pa_period
    AND p.current_pa_period_flag = 'Y'
    Above select statement uses pa_periods view which only works when I set my client using "exec DBMS_Application_Info.set_client_info(83);" in Toad or SQL*Plus session.
    I was wondering how can I achieve it within select statement. so that I don't have to use another PL/SQL statement to set my client. Is there anyway to set client with my org id within above select statement ?
    Please advise.
    --Rakesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You can simply create a function which calls dbms_application_info and use that in your sql statement as in
    SQL> create or replace function set_client_info (i_info varchar2)
       return varchar2
    as
    begin
       dbms_application_info.set_client_info (i_info);
       return i_info;
    end set_client_info;
    Function created.
    SQL> create or replace view v_emp
    as
      select * from emp where empno = to_number(sys_context('userenv','client_info'))
    View created.
    SQL> select ename from v_emp where set_client_info(7788) is not null
    ENAME    
    SCOTT    
    1 row selected.
    SQL> select ename from v_emp where set_client_info(7900) is not null
    ENAME    
    JAMES    
    1 row selected.

  • Passing parameter into select statement by using function in discoverer

    I have created two functions in database named Period_in and Period_out and a global variable  g_period_name
    I have called Period_out function in VIEW(Select statement where condition).
    I have registered Period_in function in discoverer admin then created calculation (called Period_in(:input parameter))in discoverer plus.
    My expectation is user will enter period name and that will hit Period_in function and returns 1 and stores entered period name in g_period_name at runtime. then VIEW will executed and fetches data.
    But i am getting no data found.
    Problem is 2 functions running at the same time in select statement. Please help me to overcome this. Thanks in advance
    FUNCTION period_in (p_period VARCHAR2)
          RETURN NUMBER
       AS
       BEGIN
          g_period_name := p_period;
          RETURN 1;
       END period_in;
       FUNCTION period_out
          RETURN VARCHAR2
       AS
       BEGIN
          RETURN g_period_name;
       END period_out;

    You can use this code: 
    WITH cte
    AS ( SELECT EmpID ,
    EmpName ,
    [dbo].[udf_testFunction](EmpID) AS testfunctionvalue
    FROM #Temp
    SELECT EmpID ,
    EmpName ,
    testfunctionvalue ,
    testfunctionvalue * EmpID ,
    testfunctionvalue + 2
    FROM cte
    But using scalar functions in select clause can hurt the performance. Please see this link: 
    SQL Server Scalar User Defined Function Performance
    T-SQL Articles
    T-SQL e-book by TechNet Wiki Community
    T-SQL blog

  • Select statement without into

    Hi ,
    I am currently working with a include which is already written. The include has a select statement where the into clause is not available.
    SELECT SINGLE * FROM cnvmbtrename
            WHERE packid    = p_pack
              AND domname   = space
              AND param     = gc_rfcdest
              AND value_old = ls_rename1-value_old
              AND value_new = ls_rename1-value_new.
    This statement works fine when it is sued in some other program, but i does not work in mine. Can someone help me on this front.
    Regards,
    Rishav

    Hi
    U make sure all global data are defined in your program too, so:
    - Database table:
    TABLES cnvmbtrename.
    - Selection screen (I suppose):
    PARAMETERS: P_PACK....
    - Data:
    DATA: gc_rfcdest
    Max

  • Need sequence on resultset without using ROWNUM

    I need to query some data from a SQLServer 2000 database (which don't
    have analytic SQl capibilities) and load it into Oracle 10g Warehouse. It must be
    done in a query, SQLServer don't do cursor very well. So I need a ANSI standard Query.
    I need a way of putting a sequential number on a result set. SQLServer does not have ROWNUM.
    I need a slick equivalent of: select rownum, value1, value2 from <some table>
    Can't use ROWNUM

    Only for MS SQL Server:
    set nocount on
    if exists (select * from sysobjects where type = 'U' and  name = 'test')
    begin
         drop table test
    end
    /* Create TEST table */
    create table test
         id_test int identity not null,
         string char (7),
         constraint pk_test primary key (id_test)
    set identity_insert test on
    insert into test (id_test, string)
    values (1,'string1')
    insert into test (id_test, string)
    values (4,'string2')
    insert into test (id_test, string)
    values (12,'string3')
    insert into test (id_test, string)
    values (17,'string4')
    insert into test (id_test, string)
    values (29,'string5')
    insert into test (id_test, string)
    values (31,'string6')
    insert into test (id_test, string)
    values (42,'string7')
    insert into test (id_test, string)
    values (45,'string8')
    insert into test (id_test, string)
    values (61,'string9')
    set identity_insert test off
    go
    /* Solution #1, Create VIEW */
    if exists (select * from sysobjects where type = 'V' and name = 'ranked_table')
    begin
         drop view ranked_table
    end
    go
    create view ranked_table (rank, id_test, sting)
    as
         select (
                   select count(*)
                   from test as test_2
                   where test_2.id_test <= test_1.id_test
              ) as rank,
              test_1.id_test,
              test_1.string
         from test as test_1
    go
    select *
    from ranked_table
    order by rank
    go
    /* Solution #2 STANDART ANSI-SQL (SELF-JOIN + GROUP BY)*/
    select count (test_2.id_test) as rank, test_1.id_test, test_1.string
    from test as test_1 inner join test as test_2 on
         test_1.id_test >= test_2.id_test
    group by test_1.id_test, test_1.string
    order by rank
    go
    /* Solution #3 STANDART ANSI-SQL (SCALAR SUBQUERY IN SELECT-clause)*/
    select test_3.rank, test_3.id_test, test_3.string
    from (select test_1.id_test,
              test_1.string,
              (select count(*)
                   from test as test_2
                   where test_2.id_test <= test_1.id_test
              ) as rank
         from test as test_1) as test_3
    order by rank
    go
    /* Solution #4, TEMPORARY TABLE WITH IDENTITY-FIELD */
    create table #rank_table
         rank int identity not null,
         id_test int null,
         string char (7),
         constraint pk_test primary key (rank)
    go
    insert into #rank_table (id_test, string)
    select id_test, string
    from test
    order by id_test
    select * from #rank_table
    go
    /* Solution #5, TABLE-TYPE VARIABLE WITH IDENTITY */
    declare @rank_table table
         rank int identity not null,
         id_test int null,
         string char (7)
    insert into @rank_table (id_test, string)
    select id_test, string
    from test
    order by id_test
    select * from @rank_table
    go
    /* Solution #6, CURSOR */
    declare @rank int,
         @id_test int,
         @string char (7)
    declare rank_cursor cursor
    for select id_test, string
         from test
         order by id_test
    open rank_cursor
    fetch next from rank_cursor into @id_test, @string
    set @rank = 1
    while (@@fetch_status <> -1)
    begin
         select @rank, @id_test, @string
         set @rank = @rank + 1
         fetch next from rank_cursor into @id_test, @string
    end
    close rank_cursor
    deallocate rank_cursor

Maybe you are looking for

  • Crystal Report Preview

    Hello All, I have developed AddOn application which includes crystal report files created with Crystal Report 2008.i wants to able load the report and preview them within my AddOn application.Which Crytsal report 2008 Components do i need to import t

  • Serious problem with ipod!

    Hi people, Having a bit of a nightmare with my ipod...it came up with the sad face on holiday and when I came home I checked the support site and tried resetting and restoring it...however my PC now doesn't recognise my ipod even in Device Manager an

  • How do I download flash player to my Samsung note 10.1?

    My grandma purchased a samsung note 10.1 and she wants to play pogo on her device. She has the app from the play store but wants to playit using her browser. When she clicks the games to play them it says she doesnt have the latest flash p, ayer. Eve

  • How to migrate SQL serveer table-valued functions into Oracle 10g

    hi , i'm trying to migrate from SQL server to Oracle. There are some Table_valued functions ( Function that returns table). while migrating using SQL Developer it uses cursor for every table query. is this is the only solution to migrate functions re

  • Load swf into an instance

    In the first frame of my movie, I want to load a swf into 'cwgmap' mc instance, which is inside 'thumbs' mc instance. I am attempting (with no joy!) thumbs.cwgmap.loadMovie("2014_map/thumbs.swf"); Any ideas how I can achieve this? The action must be