Select query gives result in abc order instead of creation order

Hi,
I used the following command in sql command window to insert some rows to my table:
SQL>
SQL> insert into regions (Region_ID, Region_Name) values (1 , 'Zafon');
1 row inserted
SQL> insert into regions (Region_ID, Region_Name) values (2 , 'Hasharon');
1 row inserted
SQL> insert into regions (Region_ID, Region_Name) values (3 , 'Merkaz');
1 row inserted
SQL> insert into regions (Region_ID, Region_Name) values (4 , 'Jerusalem');
1 row inserted
SQL> insert into regions (Region_ID, Region_Name) values (5 , 'Hashfela');
1 row inserted
SQL> insert into regions (Region_ID, Region_Name) values (6 , 'Darom');
1 row insertedWhen I use select * query to see the table, I get the content in abc order:
SQL> SELECT * FROM REGIONS;
REGION_ID REGION_NAME
        6 Darom
        2 Hasharon
        5 Hashfela
        4 Jerusalem
        3 Merkaz
        1 Zafon
6 rows selectedHow can I get the result in the creation order (first created- first shown)?
Thanks

>
How can I get the result in the creation order (first created- first shown)?
>
You can't - not unless you use a solution that you should NEVER use unless absolutely necessary.
WHY do you need to do this? You never provide a reason.
To get a result in creation order there are two requirements:
1. Use an ORDER BY when you query the table - this is the only requirement others have mentioned
2. Control and specify the creation order when you INSERT the data
Unfortunately there is only ONE way that I am aware of to implement #2 above (i.e. to control the insertion order) and that is to SERIALIZE the insertion of rows into the table. That means that only ONE user can insert rows into the table at a time perhaps by using a stored procedure to perform the insert.
In a multi-user system a USER can NOT see uncommitted data of other users. If a user uses a trigger and a SEQUENCE generator to generate ascending numbers another user can use that same trigger and sequence to generate numbers also. If the first user performs an INSERT and gets number 37 but doesn't commit a second user can perform an INSERT, get number 38 and COMMIT before the first user commits.
That means that the row with 38 was created (committed) first but has a higher sequence than the row with 37.
The best you can do is use a sequence generator to generate unique ascending numbers. Then you can query the data using an ORDER BY on the column that contains the sequence value. But, as shown above, that doesn't guarantee that the rows were actually committed in that order.
That may sound like a trivial distinction but it has a very important implication. It means that you can NOT use that sequenced column to extract data reliably for batch-type processing. For the above example supposed your batch process extracted data for values from 1 to 38 and then that first user did a COMMIT.
The next extract would be for values from 39 to 50 (or some other value) and the row with 37 would never be extracted. For the same reasons you can't use a CREATION_DATE value for such extract purposes either since you would have the same issue.

Similar Messages

  • MDO select query: how to control sort order using parameter

    Hi experts, is there a way of controling the sort order of an MDO select query using some parameter?
    I was thinking about using some statement like CASE [Param.1] WHEN 'abc' THEN [ORDER_NO]...END in sort section of the query but it is not working.
    Of course I colud go for various select queries...but I am wondering if it can be done using only one?
    Any ideas?
    Thanks for any help

    Hi Marco,
    Yes this can be achieved dynamically using SortExpr under dynamic link assignment in MDOAction block if you are using a transaction to call it.
    Please check below thread:
    Re: MDO Query Action Block In MII Transaction
    Or else, this [Param.1] thing should work as well provided it doesn't get the logic part in it, just pass the columns names separated by comma. Haven't tried it though, will check it for you.
    Best Regards,
    Swaroop

  • Select query gives error in Code inspector and extended program check

    Hi,
    I have a query .
    SELECT pernr
      FROM pa9100
      INTO TABLE t_nca_tab
      WHERE endda EQ c_date AND
      z_nca_required EQ c_yes.
    This query gives me an error in Code inspector like :
    Large table pa0001: No first field of table index in WHERE  condition
    I have one more query that gives error in extended program check
    SELECT SINGLE stell ename
          INTO (g_stell, g_name)
          FROM pa0001
          WHERE pernr EQ wa_nca_tab-pernr AND
                endda EQ c_date.
    The warning says:
    *In "SELECT SINGLE ...", the WHERE condition for the key field "SEQNR" does not
    test for equality. Therefore, the single record in question may not be unique.*
    Its too urgent.
    Please reply.
    Regards,
    Binay.

    The first field is PERNR .. so if UR not giving pernr it will fetch
    all the data from the said table and between the given dates ..
    Check if this is your requirement ...
    write the select as ...
    where r_pernr is a range ...
    SELECT pernr
    FROM pa9100
    INTO TABLE t_nca_tab
    WHERE pernr in r_pernr  <----
                 endda EQ c_date AND
                 z_nca_required EQ c_yes.
    As UR using select single it's expecting to use all the key
    fields in the where condition ...
    U can ignore this warning message

  • SQL Insert from "Select Query" Not Work when use Order By

    Hai every body...
    I have a problem with T-SQL. I use SQL Server 2012 Express with SP2 on Windows 7 32-bit SP1.
    This is the problem
    -- first, create table
    create table dtoth.tableA (
    id_data TINYINT PRIMARY KEY,
    kd_data VARCHAR(20),
    nm_data VARCHAR(200)
    -- then, insert values
    INSERT INTO dtoth.tableA VALUES (0,'100.001','KAS');
    INSERT INTO dtoth.tableA VALUES (1,'110.001','BANK');
    INSERT INTO dtoth.tableA VALUES (2,'120.001','PIUTANG DAGANG');
    INSERT INTO dtoth.tableA VALUES (3,'121.001','PIUTANG GIRO');
    INSERT INTO dtoth.tableA VALUES (4,'130.001','PERSEDIAAN BARANG DAGANGAN');
    -- then, i create a temporary table
    create table dtoth.temp_tableA (
    kd_data VARCHAR(20),
    nm_data VARCHAR(200)
    -- then, i create a store procedure to call data from temporary table
    CREATE procedure dtoth.report
    AS
    BEGIN
    DELETE FROM dtoth.temp_tableA;
    INSERT INTO dtoth.temp_tableA SELECT kd_data, nm_data FROM dtoth.tableA ORDER BY kd_data desc;
    SELECT * FROM dtoth.temp_tableA;
    END
    GO
    When i execute the the store procedure with
    EXEC dtoth.report;
    the result is not accurate like this (kd_data not sorted desc):
    I want the column "kd_data" sort descending because i use ORDER BY kd_data DESC in insert statement on the store procedure.
    By the way, if i execute code like :
    SELECT kd_data, nm_data FROM dtoth.tableA ORDER BY kd_data desc;
    the result is correct like this
    So, what solution for my code in the store procedure ?
    Thanks.

    to get the data sorted, you should order by in your select in the stored procedure
    sorting while inserting does not guarenatee order..
    remove the order by in insert statement and put that in the select statement
    so, your procedure should be 
    -- then, i create a store procedure to call data from temporary table
    CREATE procedure dtoth.report
    AS
    BEGIN
    DELETE FROM dtoth.temp_tableA;
    INSERT INTO dtoth.temp_tableA SELECT kd_data, nm_data FROM dtoth.tableA;
    SELECT * FROM dtoth.temp_tableA ORDER BY kd_data desc;
    END
    GO
    Hope it Helps!!

  • SELECT QUERY: LINKING  DELIVERY TO SALES-ORDER

    Hello All,
      I'm working on an output on delivery .Tr. Cd. vl03n.
    I'm required fetch ship-to-party and sold-to-party address from
    the sales order corresponding to which delivery is generated.
    In project system i cannot directly relate sale-order to delivery
    number. But there is a way to find link between sales-order and delivery number.
    The link is as follows.
    LIPS-PSPNR(PROJECT. DEFINATION)  MATCHES  FIRST FEW CHARACTERS OF VBAP-PS_PSP_PNR (WBSELEMENT).
    The query i have written is as follows:
      select single vbap~vbeln into s_vbeln from vbap where
             vbap~ps_psp_pnr = ( select distinct pspnr from lips where vbeln = wa_hd_gen-deliv_numb ).
    s_vbeln : to fetch sales order number.
    wa_hd_gen-deliv_numb : holds delivery number value.
    The above query is not working because the number of characters of the two fields are not matching.
    I cannot use 'LIKE' CLAUSE.
    Please help in creating SQL query.
    Thanks.
    Edited by: Ushma Jain on Aug 8, 2008 9:12 AM
    Edited by: Ushma Jain on Aug 8, 2008 12:08 PM

    Hi Ushma,
    In LIPS table there is a field VGBEL which contains sales document number of corresponding delivery document number.
    You can directly get sales document number from LIPS table i.e field VGBEL.
    Thanks,
    Naveen Kumar.

  • Select query need result

    I have table T_PROCESS ,here there are contains 2 columns...
    Process_flag
    Process_type
    1
       END DATE CHANGE:PLAN ID CHANGE
    1
        PLAN ID CHANGE
    1
        MENU OPTION INSERT
    1
        END DATE CHANGE:PLAN ID CHANGE:MENU OPTION INSERT
    1
       END DATE CHANGE:PLAN ID CHANGE:MENU OPTION CHANGE
    1
        PLAN ID CHANGE:MENU OPTION INSERT
    My  requirement is ,need report only contain PLAN ID CHANGE or MENU OPTION INSERT
    need out put only
    Process_type
    Process_type
    1
        PLAN ID CHANGE
    1
        MENU OPTION INSERT
    1
        PLAN ID CHANGE:MENU OPTION INSERT
    Please help me on this..

    24c14495-35a9-4391-8c06-25ca6abf36bd wrote:
    To get the Third row alos as output, we also need to make ":" also as NULL
    Replace(Replace(Replace(process_type,'PLAN ID CHANGE',null),'MENU OPTION INSERT',null),':', null) is null
    sure, i forgot about it
    Ramin Hashimzade

  • Update only one select query field

    hello
    how i can update select query result field in original table.
    update table1 set field_1 from(select field_1 from table 1,table2,table3,table4 where table1.field_1=table1.field_1 and table2.field_2=table3.field_2 and table4.field_3=table1.field_4)
    like that.is it possible!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!can u please help me to rewrite query/
    select query returns result like that from different tables
    lets example field_1 field_2 field_3 field_4
    TIGER 1 V A
    TIGER 2 F B
    TIGER 3 R C
    I need to update 'TIGER' instead of 'LION' in original table.
    THANKS

    Maybe something like
    update table1
       set beast = (select animal
                      from <table_list>
                     where <predicates>
    where beast = 'LION'when your query returns a single row
    or when multiple rows are returned
    update (select t1.beast,t2.animal
              from (select beast,
                           <join_columns_list>
                      from table1
                     where beast = 'LION'
                   ) t1,
                   (select animal,
                           <join_columns_list>
                      from <table_list>
                     where <predicates>
                   ) t2
             where t1.<join_columns_list> = t2.<join_columns_list>
       set beast = animalRegards
    Etbin

  • Select query taking more time..

    Hi friends..
    The below inner join statement is taking more time ,  can any  body sugget me to improve the performance . I tried FOR ALL ENTRIES also but that also taking more time than inner join statement .
    SELECT a~vbeln from vbap as a inner join vakpa as b
          on avbeln = bvbeln
          into corresponding fields of table IT_VAKPA
          where a~WERKS IN S_IWERKS
          and a~pstyv NE 'ZRS'
          and b~vkorg = IVKORG
          and b~audat IN IAUDAT
          and b~vtweg IN IVTWEG.
    Regards
    Chetan

    Hi Chetan ,
    VAKPA is an index table. From the select query , it has been observed that you are not fetching any data from VAKPA. Only you have added some selection paramenters in where clause of select query.
    My suggestion will be instead of using VAKPA in inner join you use VBAK along with VBAP. All the fields that you are using as selection condition from VAKPA are there in VBAK.
    I am sure performance of query will be improved.
    If still duo to business logic you need to use VAKPA, try to create secondary non unique index on fields VKORD,AUDATand VTWEG on table VAKPA.
    However I will recommend you to go for first option only. If this does not work then go for second option.
    Hopfully this will help you.
    Regards,
    Nikhil

  • Select query result set order

    Hi,
    Can I know the order in which Oracle outputs the result set of a simple SELECT query ? Will the output always be same as the order in which rows got inserted ?
    Please advise,
    Thanks,
    Smitha

    If you include an ORDER BY than the order of the result set is known.
    It will not always be the same as the order in which rows got inserted.

  • Strange result from insert into...select query

    Hello guys,
    I need your preciuos help for a question maybe simple, but that I can't explain by myself!
    I have a query of "insert into...select" that, as I have explained in the title, returns a strange result. In facts, If I execute ONLY the SELECT statement the query returns the expected result (so 2 rows); instead If I execute the entire statement, that is the "insert into...select", the query returns 0 rows inserted!!
    Following an example of the query:
    INSERT
    INTO TITOLI_ORI
    COD_TITOLO_RICCONS ,
    D_ESTRAZIONE ,
    COD_SOCIETA ,
    COD_PIANO_CONTABILE ,
    COD_CONTO_CONTABILE ,
    COD_RUBRICATO_STATISTICO_1 ,
    COD_NDG ,
    NUM_ESEGUITO ,
    CUR_IMPORTO_RICCONS ,
    CUR_IMPORTO_BICO ,
    FLG_MODIFICATO ,
    CUR_NON_ASSEGNATO ,
    FLG_QUOTATO ,
    COD_CATEG ,
    TIP_COPERTURA ,
    TIPTAS_TITOLO
    SELECT NEWID,
    '28-feb-2111',
    COD_SOCIETA,
    COD_PIANO_CONTABILE,
    COD_CONTO_CONTABILE,
    COD_RUBRICATO_STATISTICO_1,
    COD_NDG,
    NUM_ESEGUITO,
    CUR_VAL_IMPEGNI,
    'ABC' as CUR_IMPORTO_BICO,
    0 as FLG_MODIFICATO,
    NULL as CUR_NON_ASSEGNATO,
    FLG_QUOTATO,
    COD_CATEG,
    TIP_COPERTURA,
    TIP_TASSO
    FROM
    (SELECT S.COD_SOC AS COD_SOCIETA,
    S.TIP_PIANO_CNTB AS COD_PIANO_CONTABILE,
    S.COD_CONTO_CNTB AS COD_CONTO_CONTABILE,
    S.COD_RUBR_STAT AS COD_RUBRICATO_STATISTICO_1,
    TRC.COD_RAGGR_IAS AS COD_RAGGRUPPAMENTO_IAS,
    TRC.COD_NDG AS COD_NDG,
    TRC.COD_ESEG AS NUM_ESEGUITO,
    CAST((TRC.IMP_PLUS_MINUS_VAL/TRC.IMP_CAMB) AS FLOAT) AS CUR_VAL_IMPEGNI,
    TRC.TIP_QUOTAZ AS FLG_QUOTATO,
    TRC.COD_CAT_TIT AS COD_CATEG,
    TIP_COP AS TIP_COPERTURA,
    T.TIP_TASSO AS TIP_TASSO
    FROM S_SLD_CNTB S
    INNER JOIN
    (SELECT DISTINCT COD_SOC,
    TIP_PIANO_CNTB,
    COD_CONTO_CNTB,
    COD_RUBR_STAT ,
    COD_INTER_TIT AS COD_INTER
    FROM S_COLLEG_CONTO_CNTB_TIT
    WHERE COD_SOC = 'ME'
    ) CCC
    ON S.COD_SOC = CCC.COD_SOC
    AND S.TIP_PIANO_CNTB = CCC.TIP_PIANO_CNTB
    AND S.COD_CONTO_CNTB = CCC.COD_CONTO_CNTB
    AND S.COD_RUBR_STAT = CCC.COD_RUBR_STAT
    INNER JOIN S_TIT_RICCONS TRC
    ON CCC.COD_INTER = TRC.COD_INTER_TIT
    AND CCC.COD_SOC = TRC.COD_SOC
    AND TRC.COD_RAGGR_IAS = RTRIM('VALUE1 ')
    AND TRC.COD_RAGGR_IAS NOT IN ('VALUE2')
    AND TRC.DES_TIP_SLD_TIT_RICCONS IN ('VALUE3')
    AND TRC.DES_MOV_TIT = RTRIM('VALUE4 ')
    AND TRC.COD_CAT_TIT = RTRIM('VALUE4 ')
    AND TRC.COD_INTER_TIT = RTRIM('VALUE5')
    AND '28-feb-2011' = TRC.DAT_RIF
    LEFT JOIN S_TIT T
    ON T.COD_INTER_TIT = TRC.COD_INTER_TIT
    AND T.COD_SOC = TRC.COD_SOC
    AND '28-feb-2011' = T.DAT_RIF
    INNER JOIN S_ANAG_SOGG AG
    ON TRC.COD_NDG = AG.COD_NDG
    AND AG.COD_SOC = TRC.COD_SOC
    AND '28-feb-2011' = AG.DAT_RIF
    WHERE S.DAT_RIF = '28-feb-2011'
    AND (S.FLG_ANULL_BICO = 0
    OR S.FLG_ANULL_BICO IS NULL)
    AND S.COD_SOC = 'V6'
    AND LENGTH(RTRIM(S.COD_CONTO_CNTB)) = 10
    AND S.TIP_PIANO_CNTB = 'V7'
    AND TRC.IMP_PLUS_MINUS_VAL < 0
    AND SUBSTR(S.COD_CONTO_CNTB,1,7) IN (RTRIM('VALUE8 '))
    Thanks a lot

    Right, I have executed this steps:
    - I have changed the query with the select count(*)
    - Changed the insert into with the select count(*)
    - Executed the insert into
    These are the result:
    SQL> select count(*) from TITOLI_ORI2;
    COUNT(*)
    1
    BUT:
    SQL> select * from TITOLI_ORI2;
    A
    0
    The insert into that I've modified is this:
    INSERT INTO bsc.TITOLI_ORI2
    select count(*)
    FROM
    (SELECT bsc.NEWID,
    TO_DATE('28-feb-2111','DD-MON-YYYY') as data,
    COD_SOCIETA,
    COD_PIANO_CONTABILE,
    COD_CONTO_CONTABILE,
    COD_RUBRICATO_STATISTICO_1,
    COD_NDG,
    NUM_ESEGUITO,
    CUR_VAL_IMPEGNI,
    'ABC' AS CUR_IMPORTO_BICO,
    0 AS FLG_MODIFICATO,
    NULL CUR_NON_ASSEGNATO,
    FLG_QUOTATO,
    COD_CATEG,
    TIP_COPERTURA,
    TIP_TASSO
    FROM
    (SELECT S.COD_SOC AS COD_SOCIETA,
    S.TIP_PIANO_CNTB AS COD_PIANO_CONTABILE,
    S.COD_CONTO_CNTB AS COD_CONTO_CONTABILE,
    S.COD_RUBR_STAT AS COD_RUBRICATO_STATISTICO_1,
    TRC.COD_RAGGR_IAS AS COD_RAGGRUPPAMENTO_IAS,
    TRC.COD_NDG AS COD_NDG,
    TRC.COD_ESEG AS NUM_ESEGUITO,
    CAST((TRC.IMP_PLUS_MINUS_VAL/TRC.IMP_CAMB) AS FLOAT) AS CUR_VAL_IMPEGNI,
    TRC.TIP_QUOTAZ AS FLG_QUOTATO,
    TRC.COD_CAT_TIT AS COD_CATEG,
    TIP_COP AS TIP_COPERTURA,
    T.TIP_TASSO AS TIP_TASSO
    FROM bsc.S_SLD_CNTB S
    INNER JOIN
    (SELECT DISTINCT COD_SOC,
    TIP_PIANO_CNTB,
    COD_CONTO_CNTB,
    COD_RUBR_STAT ,
    COD_INTER_TIT AS COD_INTER
    FROM bsc.S_COLLEG_CONTO_CNTB_TIT
    WHERE COD_SOC = 'ME'
    ) CCC
    ON S.COD_SOC = CCC.COD_SOC
    AND S.TIP_PIANO_CNTB = CCC.TIP_PIANO_CNTB
    AND S.COD_CONTO_CNTB = CCC.COD_CONTO_CNTB
    AND S.COD_RUBR_STAT = CCC.COD_RUBR_STAT
    INNER JOIN bsc.S_TIT_RICCONS TRC
    ON CCC.COD_INTER = TRC.COD_INTER_TIT
    AND CCC.COD_SOC = TRC.COD_SOC
    AND TRC.COD_RAGGR_IAS = RTRIM('HFT ')
    AND TRC.COD_RAGGR_IAS NOT IN ('GPO')
    AND TRC.DES_TIP_SLD_TIT_RICCONS IN ('DISPONIBILI')
    AND TRC.DES_MOV_TIT = RTRIM('CONSEGNARE ')
    AND TRC.COD_CAT_TIT = RTRIM('OBBLIGAZIONE ')
    AND TRC.COD_INTER_TIT = RTRIM('334058')
    AND '28-feb-2011' = TRC.DAT_RIF
    LEFT JOIN bsc.S_TIT T
    ON T.COD_INTER_TIT = TRC.COD_INTER_TIT
    AND T.COD_SOC = TRC.COD_SOC
    AND '28-feb-2011' = T.DAT_RIF
    INNER JOIN bsc.S_ANAG_SOGG AG
    ON TRC.COD_NDG = AG.COD_NDG
    AND AG.COD_SOC = TRC.COD_SOC
    AND '28-feb-2011' = AG.DAT_RIF
    WHERE S.DAT_RIF = '28-feb-2011'
    AND (S.FLG_ANULL_BICO = 0
    OR S.FLG_ANULL_BICO IS NULL)
    AND S.COD_SOC = 'ME'
    AND LENGTH(RTRIM(S.COD_CONTO_CNTB)) = 10
    AND S.TIP_PIANO_CNTB = 'IS'
    AND TRC.IMP_PLUS_MINUS_VAL < 0
    AND SUBSTR(S.COD_CONTO_CNTB,1,7) IN (RTRIM('P044C11 '))
    Another time the strange result returns!!
    And I've created the table TITOLI_ORI2 as create table TITOLI_ORI2 (a number); to contain the number result of the query.

  • Problem with ordering in select query.

    Hi,
    We have the following query:
    SELECT s.surveyid, m.messageid, m.text FROM MS_SURVEY s, MS_MESSAGES m where (m.messageid=s.survey_desc or m.messageid=s.survey_heading or m.messageid=s.user_profiles) and s.surveyid=xxx
    This query selects 3 rows, one for description, one for heading and one for user profiles.
    The problem is that, we have 4 databases. 2 Oracle 8.1.5, one Oracle 8.1.6 and one 8.1.7
    This query when run on 8.1.7 and 8.1.5 will give us the result in the order:
    1...description
    2...heading
    3...user profile
    But, when run on 8.1.6 (which is the client setup of oracle)
    The result is in the order:
    1...user profile
    2...heading
    3...description
    This project has still not been delivered because of this problem and we are already late by 2 months.
    Please somebody let me know why this is happening?
    I cannot change the code...as it has been tested for 1 month on staging setup, where it is working fine.
    I have no clue as to why this is happening on the Client setup ONLY.
    Is it a problem of different oracle versions, or any client side db trigger is there, or any options which the client has selected during his/her db installation or whatever...?
    Kindly help.
    Thank you.
    Regards,
    - Ram

    Your query has no ORDER BY clause. Oracle does not guarantee (nor does any other RDB that I know of) to return rows in any particular order in the absence of an ORDER BY.
    There are many factors that could affect the order in which rows will be returned in the absence of an eplicit ORDER BY clause. Among these are things like order of insertion of rows, access path chosen by the optimizer, the shoe size of the requestor.
    You are going to have to change your code if you want a guaranteed order of the records.
    TTFN
    John

  • Order mismatch in selected data using Select query

    Hello Experts,
    We are upgrading from 4.6C to ECC6. I came across a select query on a custom table, which gives different order of data from 4.6C to ECC6. Data (no. of records) is same in both the servers but order is different. Table doesn't have indexes in either 4.6C or ECC6. What would be the cause for order change?
    Further, in 4,6C, ECC6 and data bases order of the data is totally different. Select query have some conditions in where clause with select options, but in both the cases (4.6C and ECC6) I am not passing any data from the selection screen so am getting entire data from the data base.
    Thanks in advance
    Phalani

    From the SAP service market place I found that
    1. Unless we use SORT or ORDER BY clause the order of the data is not in our control.
    2. In 4.6C, two same select queries never give the result in the same order, if the primary key contains character fields.
    Thanks for your help.
    Phalani

  • Column order in a select * query

    Suppose I have 256 columns in a table and if I query select * from  tablename ,what will the column order in the result.Will this be always same as order as in created statement?

    If the columns were all in the original CREATE TABLE statement, then, yes, the ordering of columns in SELECT * FROM will match the order from the CREATE TABLE statement.
    If columns were added after the initial create, then the original columns will come first (in their order) and then the added columns (in their order), etc.
    In the real world, it is a very bad practice to use SELECT * and have expectations about the ordering of the columns. Consider this scenario:
    Table T was created and implemented in production a year ago with columns A, B, C
    A project started up three months ago and added column D but the project is stalled in development. So in development T had columns A, B, C, D
    Later, another project started up and added columns E and F. Unlike the other project, it has progressed to Test. and Production. So in Development the table has columns A, B, C, D, E, F. In test and production the table has columns A, B, C, E, F.
    Now that stuck project has progressed to Test and Production. Now T has columns A, B, C, E, F, D in test and production but still A, B, C, D, E, F in development.
    Until someone notices and decides to fix it (where and how?)
    Be very, very careful about using SELECT *.

  • Find Time, when I give a SELECT query in oracle  ... ...

    Dear Friends ,
    Using the below query we got the username , sid with the CURRENT_SQL information .
    SELECT s.sid sid, s.serial# serial_id, s.status session_status, s.username oracle_username, s.osuser os_username, p.spid os_pid, s.machine session_machine, s.program session_program
    , s.client_info , SUBSTR(sa.sql_text, 1, 1024) current_sql FROM v$process p , v$session s , v$sqlarea sa WHERE p.addr = s.paddr AND s.sql_address = sa.address(+)
    AND s.sql_hash_value = sa.hash_value(+) AND s.audsid <> userenv('SESSIONID') AND s.username IS NOT NULL AND s.status = 'ACTIVE' AND s.username not in ('SYS','SYSTEM','DBSNMP','SYSMAN') ORDER BY sid;
    But I need to know in which time with date ,  I execute this SELECT query .
    Here I explain my problem and that is , In my centralized database , we have a lot of clients . so If any client gives a command to show a report , I need to find out in which time he/she executes the report ?
    Waiting for kind reply ... ...

    The issue as you have described just does not make sense unless the recorders ae not ordered by the test number.
    Does the number of records returned match the number in the DB?
    Ben
    PS: No Mike, you are still the DB guy. Relax. 
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Default in "order by" in select query may be different in 11g from 10g

    Hi, I am wondering if when you are querying a table in 11g and you use the order by clause and there is more than one occurrences with the same values in the order by, if the 11g default is different than from 10g.  For instance.
    DECLARE MHBulk CURSOR FOR                       
      select invoice_nbr,
                   customer_nbr,
                    post_century,
                    post_yymmdd,
         from CUSTOMERS
         where customer_nbr = 1234
         order by
               post_century,
               post_yymmdd;
    If you have more than one occurrence of the same customer_nbr, post_century, and post_yymmdd it looks like the default order for how 11g retrieves the records is a bit different than the 10g default.   Does anyone know why this is?

    JustinCave wrote:
    In any version of Oracle, if your ORDER BY does not specify a completely unique order, the order in which ties are broken is arbitrary.  Realistically, it will depend on things like the specific query plan chosen, the physical order of data on disk, which parallel query slave read the row, etc.  So it is subject to change within the same version of the database when, for example, a query plan changes.  It is entirely plausible that the results would be returned in the same order for years and then suddenly change one day.  If you care about the order of ties, you should add additional logic to the ORDER BY clause that specifies the order you want rather than assuming that there is a "default" order applied.
    Upgrading to a new version of Oracle, particularly if that was done via something like exporting and importing the data so that you're changing the Oracle version and the physical order of data and various object statistics, it is not at all unusual that you would get slightly different plans and that ties would be broken differently.  I wouldn't assume that there is a new "default" order, though.  It's entirely possible for the order to change if the query plan changes again.
    Justin
    Well, what happened is we've gotten a few new customers and those customers are on Linux oracle 11g.  All the other customers are on regular unix 10g.  So, it sounds like we've just been lucky with the order until now.  In our system we have a sequence number column which is unique and I solved this by adding that in the ORDER BY clause.  I was just curious as to whether oracle had a default when it found duplicate fields in the ORDER BY clause.  I can't imagine that oracle doesn't have a default like unique_session_id or something like that.

Maybe you are looking for

  • The report can not retrieve the data from the DB

    Dear all, I am facing a problem is that i have ready designed reports in Crystal. While refreshing the report in Crystal, it gives an error that it can not retrive the information from the database. But, if i am using the application which the report

  • 8.1.5 installs on Redhat 6.1, but ORA-12545 error

    I carefully followed all of the installation instructions, and the installation procedure seemed to go as expected. But when I attempt to create a database with dbassist, I get an error: ORA-12545 Connect failed because target host or object does not

  • IDOC - Delete unwanted segments and reprocess the IDOC by WE19

    HI all, I have an issue and wanted your help at this point of time. Case - Assume that an Idoc has been rejected by system due to few bad segments. Later i dentfied that in the Idoc few segments were bad and rest are good. If i use transaction WE19 f

  • What's up with the Iphone-5 ?

    What's up with the Iphone-5 that my wife and I just purchased? Neither one is now connecting to my WiFi Network.  All other devices in my home network work fine, including my old Droidx.  Did we just make a mistake by switching to the Iphone 5?

  • Difficulty with converted jpegs

    Howdy All!! I shot a job in RAW using a Canon 30D and imported into the AP library. I renamed all images when importing to reflect the job name, but of course all retained their .crw extension. I am now having trouble opening them in any other progra