How to select first several records from a database table by using select?

Hi,
   I want to select first 100 records from a database table by using select clause. How to write it?
   Thanks a lot!

hai long!
             well select statement is used to retrive
records from the database.
following is the syntax to be used.
1) select *  into corresponding fields of itab from basetable where condition.
endselect.
  ex: select * into corresponding fields of itab from mara
            where matnr >= '1' and  matnr <= '100'.
       append itab.
      endselect.
select * is a loop statement.it will execute till matnr is less than or equal to 100.
note: you can also mention the required field names in the select statement otherwise it will select all the field from table mara.
note: itab means your internal table name.
hope you got the required thing.if it really solved u r problem then award me the suitable points.<b></b>

Similar Messages

  • How to get first 10 records from the database using JSP

    i want ot get first 10 records from the database and then after clicking the next button in the page,it must show the next precceding 10 records from the database.i am getting the first 10 records .but how to post to the same page to get another preceeding 10 record.

    Search the forums - this has been asked a lot. I usually recommend experimenting with tops and order bys until you're satisfied.
    Kind regards,
      Levi

  • Selecting the last record from a database table

    In my ABAP Program, I have to use a select statement to retrieve the last record from the database table with the same key.  In other words, the Program will get more than one hit on the database table for the selected keys and I need to retrieve values from only the last record and not the first.  I know I can use an internal table to sort the records first and then retrieve the right value.   But to make things easier, is there a SELECT statement keyword than I can use to do this in one single step?  Thanks!

    hi,
    tables:mara.
        data: begin of it_mara occurs 0,
                matnr like mara-matnr,
                meins like mara-meins,
                mtart like mara-mtart,
                end of it_mara.
    select-options:s_matnr for mara-matnr.
    select matnr
              meins
              mtart
    from mara
    into table it_mara
    where matnr in s_matnr.
    if not it_mara[] is initial.
    sort it_mara by matnr descending.
    read table it_mara index 1.
    endif.
    then you get the last record of the select statement.
    reward points if useful,
    venkat.

  • How to fetch first 4 records from database.

    hi experts.i am inexperience in this field.
    please tell me suppose i want to extract only 4 records from the database ,
    what is the select statement for this .
    best regards.
    subhasis.

    Hi
    use this program as example.
    u wil get solution.
    REPORT  ZSEN_ABAP_TABLE                         .
    Tables : mara.
    data : wa_mara type mara,
           it_mara type table of mara.
    SELECT * UP TO 4 ROWS FROM MARA INTO TABLE it_mara.
    loop at it_mara into wa_mara.
    Write : / wa_mara-MATNR,
             wa_mara-MTART,
             wa_mara-BISMT.
    endloop.
    Thanks
    Senthil

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

  • How to get number of records in all user tables in one select

    Please advise how to retrieve the number of records in all user tables in one select. I would likt to extract the data to excel file.
    Many thanks,
    Andrew

    You could always analyze the tables:
    declare
    begin
      for X in (select owner, table_name from all_tables
                 minus
                select owner, table_name from all_external_tables) LOOP
          dbms_stats.Gather_Table_Stats(X.Owner, X.Table_Name) ;
      end loop;
    end;
    /Then: Select Owner, Table_Name, Num_Rows from All_Tables ;

  • How to delete the child record from the database

    how to delete a parent and child record from the database can we do it in the servlet and my database is oracle

    I'm not sure I understand the question but you could certainly use the JDBC API from within your servlet to access and modify a DB. You could also use an EJB layer to access your DB and accomplish the same tasks.

  • How to display first three records of an internal table

    hi,
    I have a requirement, in which i want to display the first 3 records of an internal table.
    Pls help me.
    Regards,
    Vipin

    Hi,
    data: count type sy-tabix.
    count = 1.
    if count <  4.
    loop at itab.
    write: / Field.
    endloop.
    endif.
    Reward if helpful.
    Regards.

  • How to retrieve a statistic sample from a database table

    Hi experts,
    Let's say I have a 100.000 rows table and I want to take a representative statistical sample from that table.
    Say, it should be 5% (or 5000 rows).
    Question is: How to ensure that the sample is representative?
    This is not guaranteed by UP TO N ROWS because the database selects without having an order by  or WHERE starting reading the first db blocks until it reaches  the limit of 5000 rows.
    SELECT * UP TO 5000 rows into table .... from ZSAMPLE.
    This means I miss mostly of the records in the table, hence the sample is not representative.
    Do you ever encounter such a problem?

    You could SELECT (with package size if desired) into an internal table.  Then:
    Select * from table into internal table........
      package size 10000.  "not really necessary for 100000 row table
    *Initialize a counter of type i.
      lv_counter = 0.
    loop at the internal table.
      lv_counter = lv_counter + 1.
       if lv_counter lt 20. "1 in 20 = 5%
         delete internal table. "drop this row.
       elseif lv_counter eq 20.
         lv_counter = 0. 
    endif.
    endloop.
    endselect.  "if you used package size.
    at the end you would have kept every 1 out of every 20 records from your original table select.  Be sure to use a package size (if needed ) that is an exact multiple of 20.  To futher randomize the table, you could sort on some field that has random values, etc. before doing the every 20th record retention.

  • How to populate last 10 records from data base table

    Hi,
    My requirement is to populate last 10 transfer order items confirmed from LTAP. as the table is too large there is no point to fetch all the records and filter them...
    Please let me know better way (in terms of performace) to get last 10 records from LTAP.
    Thanks in advance.
    Nag

    Hi brother,
    the following code is working......(sample code)
    data itmara type mara occurs 0 with header line.
    select matnr from mara into corresponding fields of table itmara up to 20 rows.
    sort itmara descending by matnr.
    loop at itmara .
    write:/ itmara-matnr.
    if sy-tabix = 10.
    exit.
    endif.
    endloop.
    plz reward with maximum points
    Edited by: sreejith gn on May 13, 2008 12:52 PM

  • How to delete the matching records from two internal tables

    Hi ,
    I have two internal tables say A and B of the same type. If A has 10 records and B has 4 records , I want to delete the 4 records in B from A .
    loop at B into wa .
    delete A where key = wa - key .
    endloop.
    takes a long time if the table B is huge. how can I improve the performance.
    Thanks.
    Gayathri

    Hi Gayathri,
    You could try field-symbols. It reduces the data transfer from the internal table B to the work area.
    field-symbols <fs_itab_b> like line of B.
    loop at B assigning <fs_itab_b>.
      delete A where key = <fs_itab_b>?-key.
    endloop.
    Regards,
    <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=zwcc%2fwm4ups%3d">anand Mandalika</a>.

  • How to get first 50 records from database using cmp beans 2.0?

    does any body know how i should write ejb-statment to do that?
    thanks
    winnicki

    if i run method for example findAll() and thereare
    500k recods my server will by out of memory ithink.
    Yes, you are right. I know some guys who wrote
    quite a large system in that style :-)
    Of course, the application didnt work in real life.
    Customer decided to throw the system away and later
    er some other guys rewrote it ....... in .NET
    What a pity! sigh

  • How to skip first 5 lines from a txt file when using sql*loader

    Hi,
    I have a txt file that contains header info tat i dont need. how can i skip those line when importing the file to my database?
    Cheers

    Danny Fasen wrote:
    I think most of us would process this report using pl/sql:
    - read the file until you've read the column headers
    - read the account info and insert the data in the table until you have read the last account info line
    - read the file until you've read a new set of column headers (page 2)
    - read the account info and insert the data in the table until you have read the last account info line (page 2)
    - etc. until you reach the total block idenfitied by Count On-line ...
    - read the totals and compare them with the data inserted in the tableOr maybe like this...
    First create an external table to read the report as whole lines...
    SQL> ed
    Wrote file afiedt.buf
      1  CREATE TABLE ext_report (
      2    line VARCHAR2(200)
      3          )
      4  ORGANIZATION EXTERNAL (
      5    TYPE oracle_loader
      6    DEFAULT DIRECTORY TEST_DIR
      7    ACCESS PARAMETERS (
      8      RECORDS DELIMITED BY NEWLINE
      9      BADFILE 'bad_report.bad'
    10      DISCARDFILE 'dis_report.dis'
    11      LOGFILE 'log_report.log'
    12      FIELDS TERMINATED BY X'0D' RTRIM
    13      MISSING FIELD VALUES ARE NULL
    14      REJECT ROWS WITH ALL NULL FIELDS
    15        (
    16         line
    17        )
    18      )
    19      LOCATION ('report.txt')
    20    )
    21  PARALLEL
    22* REJECT LIMIT UNLIMITED
    SQL> /
    Table created.
    SQL> select * from ext_report;
    LINE
    x report page1
    CDC:00220 / Sat Aug-08-2009 xxxxp for 02/08/09 - 08/08/09 Effective Date 11/08/09 Wed Sep-30-2009 08:25:43
    Bill to
    Retailer Retailer Name                  Name on Bank Account           Bank ABA   Bank Acct            On-line Amount  Instant Amount  Total Amount
    ======== ============================== ============================== ========== ==================== =============== =============== ===============
    0100103  BANK Terminal                  raji                           123456789  123456789            -29,999.98    9 0.00         99 -29,999.98
    0100105  Independent 1                  Savings                        123456789  100000002            -1,905.00     9 0.00         99 -1,905.00
    0100106  Independent 2                  system                         123456789  100000003            -800.00       9 -15.00       99 -815.00
    LARGE SPACE
    weekly_eft_repo 1.0 Page: 2
    CDC:00220 / Sat Aug-08-2009 Weekly EFT Sweep for 02/08/09 - 08/08/09 Effective Date 11/08/09 Wed Sep-30-2009 08:25:43
    Bill to
    Retailer Retailer Name Name on Bank Account Bank ABA Bank Acct On-line Amount Instant Amount Total Amount
    ======== ============================== ============================== ========== ==================== =============== =============== ===============
    Count On-line Amount Instant Amount Total Amount
    ============== ====================== ====================== ======================
    Debits 0 0.00 0.00 0.00
    Credits 3 -32,704.98 -15.00 -32,719.98
    Totals 3 -32,704.98 -15.00 -32,719.98
    Total Tape Records / Blocks / Hash : 3 1 37037034
    End of Report
    23 rows selected.Then we can check we can just pull out the lines of data we're interested in from that...
    SQL> ed
    Wrote file afiedt.buf
      1  create view vw_report as
      2* select line from ext_report where regexp_like(line, '^[0-9]')
    SQL> /
    View created.
    SQL> select * from vw_report;
    LINE
    0100103  BANK Terminal                  raji                           123456789  123456789            -29,999.98    9 0.00         99 -29,999.98
    0100105  Independent 1                  Savings                        123456789  100000002            -1,905.00     9 0.00         99 -1,905.00
    0100106  Independent 2                  system                         123456789  100000003            -800.00       9 -15.00       99 -815.00And then we adapt that view to extract the data from those lines as actual columns...
    SQL> col retailer format a10
    SQL> col retailer_name format a20
    SQL> col name_on_bank_account format a20
    SQL> col online_amount format 999,990.00
    SQL> col instant_amount format 999,990.00
    SQL> col total_amount format 999,990.00
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace view vw_report as
      2  select regexp_substr(line, '[^ ]+', 1, 1) as retailer
      3        ,trim(regexp_replace(regexp_substr(line, '[[:alpha:]][[:alnum:] ]*[[:alpha:]]', 1, 1), '(.*) +[^ ]+$', '\1')) as retailer_name
      4        ,trim(regexp_replace(regexp_substr(line, '[[:alpha:]][[:alnum:] ]*[[:alpha:]]', 1, 1), '.* ([^ ]+)$', '\1')) as name_on_bank_account
      5        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 1)) as bank_aba
      6        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 2)) as bank_account
      7        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 3),'999,999.00') as online_amount
      8        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 5),'999,999.00') as instant_amount
      9        ,to_number(regexp_substr(regexp_replace(line,'.*[[:alpha:]]([^[:alpha:]]+)','\1'), '[^ ]+', 1, 7),'999,999.00') as total_amount
    10* from (select line from ext_report where regexp_like(line, '^[0-9]'))
    SQL> /
    View created.
    SQL> select * from vw_report;
    RETAILER   RETAILER_NAME        NAME_ON_BANK_ACCOUNT   BANK_ABA BANK_ACCOUNT ONLINE_AMOUNT INSTANT_AMOUNT TOTAL_AMOUNT
    0100103    BANK Terminal        raji                  123456789    123456789    -29,999.98           0.00   -29,999.98
    0100105    Independent 1        Savings               123456789    100000002     -1,905.00           0.00    -1,905.00
    0100106    Independent 2        system                123456789    100000003       -800.00         -15.00      -815.00
    SQL>I couldn't quite figure out the "9" and the "99" data that was on those lines so I assume it should just be ignored. I also formatted the report data to fixed columns width in my external text file as I'd assume that's how the data would be generated, not that that would make much difference when extracting the values with regular expressions as I've done.
    So... something like that anyway. ;)

  • How can i fetch numeriic records from data dictionary table

    hi friends..
    let assume one data dictionary table ztable which contain
    fields like 1. key datatype c length 2
                  2. data datatype c length 10
    which contain data like
    aa      varehouse
    bb      material
    cc      sales
    01      one
    02      two
    03      three
    from these i want to fetch only 01, 02 and 03 records...
    i.e i want all the records that is in numbers only in key field of ztable
    can you guide me how to get tis?

    select * into table itab
    from ztable
    where key eq '01'
    or key eq '02'
    or key eq '03'.
    declare itab of the type same as ur ztable..
    the above select query will giv u required records..
    Edited by: Rudra Prasanna Mohapatra on Jul 14, 2008 11:13 AM

  • How to get the last record from the database

    I am using MS Access database and Swings as GUI. I want to get the last record of a particular column from the table and store it as a varaible.

    Hi
    To get Last record of resultset, you have pass some parameter in constructor of CreateStatement.In such case Resultset should be scrollable and Readonly
    Example
    objStatement=objCon.createStatement ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    mwwResultSet=cwwStatement.executeQuery(mwwSqlQuery);
    while(mwwResultSet.next())
    if(mwwResultSet.isLast())
    //Fetch the required column record.
    String abc=mwwResultSet.getString(1);
    I think this will work. Try it.
    bye

Maybe you are looking for

  • Creative Cloud Desktop App crashes on new Mac Pro 2013

    After using Migration Assistant to move apps from my 2010 MBP to a new Mac Pro 6,1 (OSX 10.9.1), I find that the Creative Cloud Desktop App consistently crashes right after entering my ID and password (whether started as a menu bar item or separate w

  • Can't load Logic Pro X loops.

    I can't get my Logic loops to appear in FCP X 10.1.1 I have repeatedly opened Logic Pro X and FCP X and also trashed the preferences to no avail. Dragging the "Logic" folder to the FCP X music browser does no good as not even a + sign will appear. I'

  • How can I group student scores into quintile using SQL Server 2008

    Can anyone help me to group student scores into quintile. I think there is a feature in SQL Server 2012, but still we are have not upgrade to it as we are using 2008R2. I tried Ntile(5) but it not generating the desired result. I need below Quintile

  • BAM startup error

    Hi all, when I start the BAM server, this error give back: <Error> <oracle.bam.adc> <BEA-000000> <ActiveDataCache: Exception occurred in method startup() Exception: java.lang.NoClassDefFoundError: com/sun/tools/javac/Main at oracle.bam.adc.kernel.exp

  • Ideas for Apple

    Hello know someone where you can sign ideas for Apple?