Add records in the beginning of the table

Hi,
Is that possible to add or append the records in the beginning of the table.
For example,
   CREATE TABLE app_test (n NUMBER, n1 VARCHAR2(200));
   and inserting new records
  INSERT INTO app_test
     VALUES (1, 'test');
  INSERT INTO app_test
     VALUES (2, 'test');
  INSERT INTO app_test
     VALUES (3, 'test');
  select * from app_test;
N     N1
1     test
2     test
3     test
  Is that possible to add the records like below. Appending newly inserted rows in the beginning of the table.
N     N1
3     test
2     test
1     test
  Thanks
Radha K

hI,
Radha K wrote:
To get achieve sorting order, i have done the following, but the when i
query the record, its not showing the order which i created in the index.
CREATE TABLE iot_app_test (
n NUMBER,
n1 VARCHAR2(10),
n2 TIMESTAMP);
CREATE INDEX
iot_app_test_indx
ON
iot_app_test
SUBSTR(n2,1,9) DESC, SUBSTR(n2,11) ASC);
INSERT INTO iot_app_test
VALUES (1, 'test', SYSDATE);
INSERT INTO iot_app_test
VALUES (2, 'test', SYSDATE);
INSERT INTO iot_app_test
VALUES (3, 'test', SYSDATE);
INSERT INTO iot_app_test
VALUES (1, 'test', SYSDATE + 1);
INSERT INTO iot_app_test
VALUES (2, 'test', SYSDATE + 1);
INSERT INTO iot_app_test
VALUES (3, 'test', SYSDATE + 1);
INSERT INTO iot_app_test
VALUES (1, 'test', SYSDATE + 2);
INSERT INTO iot_app_test
VALUES (2, 'test', SYSDATE + 2);
INSERT INTO iot_app_test
VALUES (3, 'test', SYSDATE + 2);
SELECT *
FROM iot_app_test
WHERE n2 <> SYSDATE + 3
N     N1     N2
1     test     4/28/2010 1:59:26.000000 PM
2     test     4/28/2010 1:59:30.000000 PM
3     test     4/28/2010 1:59:33.000000 PM
1     test     4/29/2010 1:59:38.000000 PM
2     test     4/29/2010 1:59:41.000000 PM
3     test     4/29/2010 1:59:44.000000 PM
1     test     4/30/2010 1:59:48.000000 PM
2     test     4/30/2010 1:59:51.000000 PM
3     test     4/30/2010 1:59:53.000000 PM
The query doesn't have an ORDER BY clause, so the results could be in any order. In fact, you can run the exact same query with the exact same data seconds apart, and get a different order every time.
The index doesn't change that. Someone above mentioned an Index Organized Table (which is not merely a table with an index), where you can control the order in which rows are stored (as if you wanted to). There is still no guarantee that, absent an ORDER BY clause, output will be in any particular order.
But when i use the same function in order by clause, its showing the correct result.To repeat what others have said already, the only way to get output in any particular order is to use an ORDER BY clause.
(CONNECT BY queries are the only exception of which I know. There is a partial ordering in CONNECT BY output, even if you don't use ORDER BY or ORDER SUBLINGS BY.)
>
SELECT   *
FROM iot_app_test
ORDER BY SUBSTR (n2, 1, 9) DESC, SUBSTR (n2, 11) ASC;
N     N1     N2
1     test     4/30/2010 1:59:48.000000 PM
2     test     4/30/2010 1:59:51.000000 PM
3     test     4/30/2010 1:59:53.000000 PM
1     test     4/29/2010 1:59:38.000000 PM
2     test     4/29/2010 1:59:41.000000 PM
3     test     4/29/2010 1:59:44.000000 PM
1     test     4/28/2010 1:59:26.000000 PM
2     test     4/28/2010 1:59:30.000000 PM
3     test     4/28/2010 1:59:33.000000 PMCan anyone tell me what's wrong with this.Nothing is wrong.
You're getting the correct output, in the correct order. Why do you think anything is wrong?

Similar Messages

  • To add new record into the table Data Service client

    When I am trying to add new record into the table Employeedetails using Data Service client it is giving a sql exception: "java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1."
    Code:
    DataService ds=DataServiceFactory.newDataService(getInitialContext(),"EmplDetApp","ld:EmplDetAppDataServices/EmployeeDetails");
    EmployeeDetailsDocument edoc=EmployeeDetailsDocument.Factory.newInstance();
    edoc.addNewEmployeeDetails();
    //here I set the primary key value empid
    edet.setEmpid("1212");
    edet.setEmpname("manu");
    ds.submit(edoc);
    Error
    EmpName 5 java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
    com.bea.ld.dsmediator.DataServiceException: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
         at com.bea.ld.dsmediator.update.JDBCAdaptor.save(JDBCAdaptor.java:247)
         at com.bea.ld.dsmediator.update.DataServiceMediator.submit(DataServiceMediator.java:528)
         at com.bea.ld.dsmediator.update.DataServiceMediator.submit(DataServiceMediator.java:245)
         at com.bea.ld.ServerBean.submit(ServerBean.java:529)
         at com.bea.ld.Server_ydm4ie_EOImpl.submit(Server_ydm4ie_EOImpl.java:910)
         at com.bea.ld.Server_ydm4ie_EOImpl_WLSkel.invoke(Unknown Source)
         at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:492)
         at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:108)
         at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:435)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:147)
         at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:430)
         at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:35)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:224)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:183)
         at java.lang.Thread.startThreadFromVM(Unknown Source)
    Caused by: java.sql.SQLException: Violation of PRIMARY KEY constraint 'PK__EmployeeDetails__6383C8BA'. Cannot insert duplicate key in object 'EmployeeDetails'. Severity 14, State 1, Procedure 'PC-P41403 null', Line 1
         at weblogic.jdbc.mssqlserver4.TdsStatement.processWarning(TdsStatement.java:1178)
         at weblogic.jdbc.mssqlserver4.TdsStatement.parseMsWarning(TdsStatement.java:1089)
         at weblogic.jdbc.mssqlserver4.TdsStatement.getMoreResults(TdsStatement.java:756)
         at weblogic.jdbc.mssqlserver4.TdsStatement.execute(TdsStatement.java:210)
         at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.java:97)
         at weblogic.jdbc.mssqlserver4.TdsStatement.executeUpdate(TdsStatement.java:1455)
         at weblogic.jdbc.wrapper.PreparedStatement.executeUpdate(PreparedStatement.java:147)
         at com.bea.ld.dsmediator.update.JDBCAdaptor.save(JDBCAdaptor.java:151)
         ... 15 more
    But I am not sure why it is giving an exception as Violation of PRIMARY KEY.
    The update method works fine for the same client.
    The exception only happens when I am trying to insert a new record.
    Please help me to figure out this problem.

    If you are absolutely sure that you do not have such a row already in your table, open a case with customer support and reference CR321312. I believe the work-around is to put ld-server-core.jar in your client classpath.
    Correction: put ld-server-app.jar in the client classpath
    Edited by mreiche at 09/17/2007 3:28 PM

  • Add records to the physical table from Internal table

    Hello,
    I am trying to insert the records from IT table to physical table. But, its not inserting. Please let me know how do I add the records to the table zebp_iv_cf_log.
    I have used only few fields for example *
    After looping I get about 800 records in it_non_ebp tab *
    loop at non_ebp_inv.
        it_non_ebp-zspgrv = non_ebp_inv-spgrv.
        it_non_ebp-zspgrq = non_ebp_inv-spgrq.
        it_non_ebp-zspgrs = non_ebp_inv-spgrs.
        it_non_ebp-inv_ref_num = non_ebp_inv-xblnr.
        it_non_ebp-zspgrc = non_ebp_inv-spgrc.
        it_non_ebp-zlifnr = non_ebp_inv-lifnr.
        append it_non_ebp.
        endloop.
        insert   zebp_iv_cf_log from table it_non_ebp[] accepting duplicate keys .
    I also tried inserting one by one by putting insert syntex within a loop but, it takes keeps processing.
    Shall appreciate the response.
    Thks & Rgds,
    Hemal
    Edited by: hemalgandhi on Jun 12, 2009 6:27 PM

    Hi,
    for the internal table you are using for appending , you must declare it with the header line option
    as
    data it_non_ebp type table of zebp_iv_cf_log with HEADER LINE.
    or else you can have a separate workarea of type zebp_iv_cf_log
    as
    data wa_zebp_iv_cf_log type zebp_iv_cf_log.
    then the code should be like :
    loop at non_ebp_inv.
    wa_zebp_iv_cf_log -zspgrv = non_ebp_inv-spgrv.
    wa_zebp_iv_cf_log -zspgrq = non_ebp_inv-spgrq.
    wa_zebp_iv_cf_log -zspgrs = non_ebp_inv-spgrs.
    wa_zebp_iv_cf_log -inv_ref_num = non_ebp_inv-xblnr.
    wa_zebp_iv_cf_log -zspgrc = non_ebp_inv-spgrc.
    wa_zebp_iv_cf_log -zlifnr = non_ebp_inv-lifnr.
    append wa_zebp_iv_cf_log to it_non_ebp.
    clear wa_zebp_iv_cf_log .
    endloop.
    and use 
       modify zebp_iv_cf_log from table it_non_ebp accepting duplicate keys .
    instead of
       insert zebp_iv_cf_log from table it_non_ebp[] accepting duplicate keys .
    Please try out and let me know of you face any problem

  • How to speed up the deletion of 11million records from the table

    Hi,
    How to speed up the deletion of 11million records from the table.
    I need expiditious reply. Please do the needfull in advising
    Regards

    Please try to understand the question.Well it would help if you would answer some of the questions you have been asked as your question is not complete and clear and no matter how hard we try, we really need you to try and ask the question properly.
    So as previously asked
    Which simply supports the idea that we need:
    1) better definition of the business purpose (why)
    2) oracle version
    3) operating system
    4) hardware configuration
    to give a moderately accurate answer.
    I would like to add
    5) How many rows in total in the table to begin with.
    6) What is your delete statement
    7) Is this a one time operation or will it happen regularly
    8) Can you use partitioning.

  • Using combination of insert into and select to create a new record in the table

    Hello:
    I'm trying to write a stored procedure that receives a record locator parameter
    and then uses this parameter to locate the record and then copy this record
    into the table with a few columns changed.
    I'll use a sample to clarify my question a bit further
    -- Create New Amendment
    function create_amendment(p_mipr_number in mipr.mipr_number%TYPE, p_new_amendment_number in mipr.amendment_number%TYPE)
    return integer is
    new_mipr_id integer;
    begin
    THIS is causing me grief See comments after this block of code
    insert into mipr
    (select mipr_id from mipr where mipr_number=p_mipr_number),
    (select fsc from mipr where mipr_number=p_mipr_number),
    45,
    (select price from mipr where mipr_number=p_mipr_number),
    practical,
    (select part_number from mipr where mipr_number=p_mipr_number);
    THe above will work if I say the following
    insert into mipr
    (select * from mipr where mipr_number=p_mipr_number);
    BUt, Of course this isn't what I want to do... I want to duplicate a record and change about 3 or 4 fields .
    How do I use a combination of more than one select and hard coded values to insert a new record into the table.
    /** Ignore below this is fine... I just put a snippet of a function in here ** The above insert statement is what I need help with
    select (mipr_id) into new_mipr_id from mipr where mipr_number=p_mipr_number + amendment_number=(select max(amendment_number) + 1);
    return new_mipr_id;
    end;
    THANK YOU IN ADVANCE!
    KT

    function create_amendment(p_mipr_number in mipr.mipr_number%TYPE)
    return integer is
    new_mipr_id integer;
    tmp_number number;
    tmp_mipr_id integer;
    begin
    tmp_number :=(select max(amendment_number) from mipr where mipr_number=p_mipr_number);
    Question:
    tmp_number :=1; works..
    tmp_number doesn't work with the select statement?
    Obviously I'm a novice! I can't find anything in my book regarding tmp variables... What should I look under is tmp_number a
    variable or what? In my Oracle book, variable means something different.
    Thanks!
    KT
    I have the following code in my stored procedure:
    Good luck,
    Eric Kamradt

  • Override the unique record of the table

    friends
    i am having a record in the table , and always i want the latest value in the table.
    the record is with 4 fields.
    mandt primary key
    numb  primary key
    username
    date
    now in the program i read the numb from the ztable and after reading that
    i want to update the field with +1 ie override the old record.
    I tried with update and modify statement  but they are inserting the new record,
    i tried the where clause but that is not working.
    when i am using modify statement i am using numb+1 , so it is inserting the new record.
      How to handle this situation , please advice

    Hi,
      As Number is primary key, After reading and adding Number then you need to delete the existing latest record and Insert the new record.
    For EX
    NUM  USERNAME
    0001  NAREN
    0002 SATISH
    0003 RAVI
    Then last number is 0003 , add 1 then num is 0004.Then delete 0003 RAVI
    and add 0004 RAVI
    then DATA becomes
    NUM  USERNAME
    0001  NAREN
    0002 SATISH
    0004 RAVI
    Hope this will help  you.
    Thanks and Regards,
    Narendra.Soma

  • Incomplete Data on report (report does not show all records from the table)

    Hello,
    I have problem with CR XI, I'm running the same report on the same data with simple select all records from the table (no sorting, no grouping, no filters)
    Sometimes report shows me all records sometimes not. Mostly not all records on the report. When report incomplete sometimes it shows different number of records.
    I'm using CR XI runtime on Windows Server 2003
    Any help appreciated
    Thanks!

    Sorry Alexander. I missed the last line where you clearly say it is runtime.
    A few more questions:
    - Which CR SDK are you using? The Report Designer Component or the CR assemblies for .NET?
    - What is the exact version of CR you are using (from help | about)
    - What CR Service Pack are you on?
    And a troubleshooting suggestion:
    Since this works on some machines, it will be a good idea to compare all the runtime (both CR and non CR) being loaded on a working and non working machines.
    Download the modules utility from here:
    https://smpdl.sap-ag.de/~sapidp/012002523100006252802008E/modules.zip
    and follow the steps as described in this thread:
    https://forums.sdn.sap.com/click.jspa?searchID=18424085&messageID=6186767
    The download also includes instructions on how to use modules.
    Ludek

  • Selecting records in the table control

    Hi Friends,
    I have the requirement to be displayed in the table control, I got the data displayed in the table control. Now I need to select some of the records from the table control and update in the database. When I am trying to do that i am able to select only one records instead of some number of records. When I try to select the second record the first record which i selected is being unselected. Can any one tell me how to select more than one record in the table control.
    Regards,
    Line

    hello,
    to select more then 1 record
    1> you need to put CHECK BOX FEILD
             or
    1> you have to manually use control and select the feilds.
    hope i have replied to your query
    thankx
    bhanu malik

  • No. of records in the table

    Is any system table or a program that gives us the # of records by SAP metadata table name ?.. i have a list of table names & need to know the # of recs in all of them...so can try looking at the larger ones for analysis.. ?

    Hi Venugopal,
    if you want to know the no of records in a table follow these steps.
    1)go to se11 and open the table
    2)go to utilities->tablecontents->display
    3)click on Number of Entries button which is application tollbar wihtout entering any values in the screen .
    you will get the no of records existed in the table
    if you want to know the no of records for all the tabels at a time then you have to write a program.follow the code below.
    data:cnt type i.
    SELECT COUNT(*) FROM mara BYPASSING BUFFER.
    cnt = sy-dbcnt.
    write:cnt.
    you will get the no of records in the table in cnt.
    rewards points if helpful.

  • How to rerieve records from the table starting with character 'D'

    Hi Folks,
    How to get the records from the table starting with character 'D'.
    Select Max (fld1) fron tab1 into tab1-fld1 where fld 2 = l_fld2 and starting character of fld(1) is 'D'.
    last record in the table starting with character 'D'
    How can i do that??
    Pl explain.
    Thanks,
    Matt

    Hi,
    Select Max (fld1) fron tab1 into tab1-fld1 where fld 2 = l_fld2 and starting character of fld(1) is 'D'.
    Select MAX (fld1)
       From  tab1
    into table itab
    where fld 2 = l_fld2
       and fld1 like 'D%'.

  • SQL query to get last 10 records in the table?

    Hi,
    Can anyone tell me the SQL query to get last 10 records in the table?
    Thanks!!
    MCP

    Please, define what "last" means. Sets are unordered by definition, so if you want to retrieve rows from a table in a specific order you need to specify what that order is - e.g. by maintaining a value in a column (or a combination of columns) that you can use in the ORDER BY clause of the SELECT statement.
    If, for instance, you kept the time when the row was inserted in a special column (InsertedTime), you could use this in your query like this:
    select top (10)
      <column list>
      from <table or view>
      where <restriction(s)>
      order by InsertedTime desc;
    ML
    Matija Lah, SQL Server MVP
    http://milambda.blogspot.com

  • How to find last inserted record in the table.

    Version: Oracle 10g
    I have a table called "Manufacture" and 3 columns as mfno,itemname,quantity.
    How to find last inserted record in the table "Manufacture".
    As i come to know that Rowid is not result perfect results. Please provide your inputs.

    user13416294 wrote:
    Version: Oracle 10gThat is not a version. That is a product name. A version is 10.1.0.2 or 10.2.0.4, etc.
    I have a table called "Manufacture" and 3 columns as mfno,itemname,quantity.
    How to find last inserted record in the table "Manufacture".Not possible as your data model does not cater for it. That simple.
    If there is a need to determine some order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or more attributes are needed to represent that information. Thus your data model in this case is unable to meet your requirements.
    If the requirements are valid, fix the data model. In other words - your question has nothing to do with Oracle and nothing to do with rowid, rowscn or other pseudo columns in Oracle. It is a pure data modeling issue. Nothing more.

  • How to make records  to the table TRFCQIN

    hi all,
    anyone can tell me
    how to make records  to the table TRFCQIN
    regards

    Hi Wanna,
                    Write a module pool program to enter record into table TRFCQIN.
    Take fields to which u want to make entries in module pool.
    Use insert command to append data in table TRFCQIN.
    Refer this code :
    CASE OK_CODE_101.
    WHEN 'SAV1'.
    TRFCQIN-QNAME = 'XYZ'.
    TRFCQIN-QCOUNT = "Screen field name at which user will enter value
    INSERT TRFCQIN.
    if sy-subrc <> 0.
    message e007.
    else.
    clear TRFCQIN.
    clear ok_code_101.
    endif.
    endcase.
    Reward points if helpful.
    Regards,
    Heamnt

  • How to find the last records of the table in adventure work db

    hi all,
    i want to find out " how to receive a last records of the table (eg:  person.emailaddress ) in sql 2008 and 2005"
    Thanks

    If you are looking for the latest record( the one which got inserted/modified last) then use this query
    select top 1 * from person.emailaddress
    Order by ModifiedDate desc
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Best way to insert millions of records into the table

    Hi,
    Performance point of view, I am looking for the suggestion to choose best way to insert millions of records into the table.
    Also guide me How to implement in easier way to make better performance.
    Thanks,
    Orahar.

    Orahar wrote:
    Its Distributed data. No. of clients and N no. of Transaction data fetching from the database based on the different conditions and insert into another transaction table which is like batch process.Sounds contradictory.
    If the source data is already in the database, it is centralised.
    In that case you ideally do not want the overhead of shipping that data to a client, the client processing it, and the client shipping the results back to the database to be stored (inserted).
    It is must faster and more scalable for the client to instruct the database (via a stored proc or package) what to do, and that code (running on the database) to process the data.
    For a stored proc, the same principle applies. It is faster for it to instruct the SQL engine what to do (via an INSERT..SELECT statement), then pulling the data from the SQL engine using a cursor fetch loop, and then pushing that data again to the SQL engine using an insert statement.
    An INSERT..SELECT can also be done as a direct path insert. This introduces some limitations, but is faster than a normal insert.
    If the data processing is too complex for an INSERT..SELECT, then pulling the data into PL/SQL, processing it there, and pushing it back into the database is the next best option. This should be done using bulk processing though in order to optimise the data transfer process between the PL/SQL and SQL engines.
    Other performance considerations are the constraints on the insert table, the triggers, the indexes and so on. Make sure that data integrity is guaranteed (e.g. via PKs and FKs), and optimal (e.g. FKs should be indexes on the referenced table). Using triggers - well, that may not be the best approach (like for exampling using a trigger to assign a sequence value when it can be faster done in the insert SQL itself). Personally, I avoid using triggers - I rather have that code residing in a PL/SQL API for manipulating data in that table.
    The type of table also plays a role. Make sure that the decision about the table structure, hashed, indexed, partitioned, etc, is the optimal one for the data structure that is to reside in that table.

  • How find just one record on the table

    Hi,
    I've this table TAB_DV:
    COD_ID.........DV_ID
    001............A
    002............A
    002............B
    002............C
    002.............
    003............
    004............GG
    004............DD
    004............FF
    004............MM
    004............TT
    008.............BB
    0022..............
    0033..............
    0044............A
    0044............
    0055............FF
    0066............
    I'd like to find only the COD_ID that have one record (in the table TAB_DV) without dv_id:
    In my case:
    COD_ID.........DV_ID
    003............
    0022..............
    0033..............
    0066............
    If I run:
    SELECT COD_ID, DV_ID
    FROM TAB_DV
    WHERE DV_ID IS NULL
    GROUP BY COD_ID, DV_ID;
    I get also COD_ID with more records.
    How can I write this query?
    Thanks in advance.

    try this
    select cod_id
      from tab_dv
    where dv_id is null
    having count(cod_id) = 1
    group by cod_id
    or
    select t1.cod_id, t1.dv_id
      from tab_dv t1
    where t1.cod1 in (select cod_id
                         from tab_dv t2
                       having count(t2.cod_id) = 1
                       group by t2.cod_id)
       and t1.dv_id is null

Maybe you are looking for

  • Buying Credits in Taiwan - Only Foreigners Must Pr...

    The Taiwan government requires that foreigners in Taiwan submit a scanned copy of their passport in order to buy Skype credits. So the sole third party website that collects payments for Skype must require this. The law applies only to foreigners, i.

  • Migrating When Tables Are In Seperate .mdb File

    I am new to migrating databases from Access to Oracle so I hope this is not too basic a question. In the Access world it is not uncommon to put the tables for a database in a seperate .mdb file. Then all the other database objects are in another .mdb

  • Ftp data transfering drops when failover from active to backup

    Hi All, I did a failover testing with 2 CSS11503 and found a ftp problem. I ftp one file from the server which behind 2 CSS, I tried to force failover happen by shutdown external interface. The ftp transfering was also terminated. How can I keep file

  • I have no sound on my hp pavilion dv6.

    The sound on my pavilion dv6 is gone. I was looking at the forum and saw a post about downliading IDT sound driver (I think thats right). I did the download and still have no sound. What do I do??

  • Cannot reinstall CS3 after corrupt OS repair. Request assistance/suggestions/support.

    My Windows XP system was recently reinstalled. Now I have to go back and install all my programs.(Sound familiar?!) I have tried several times to download CS3 from my original disks, but have been unsuccessful. I have restarted my machine. I have clo