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.

Similar Messages

  • Query result set ordered incorrectly

    Hallo,
    I have this problem.
    I have a table (lisitab) with a list of codes, for example:
    A0001
    A0002
    AD063
    AY064
    In my java class I run a query (select lisi_codi from lisitab order by lisi_codi) and I expect the following order:
    A0001
    A0002
    AD063
    AY064
    but I have this result:
    AD063
    AD064
    A0001
    A0002
    What is strange it's that if I execute the query in SQL*Plus or other tools (PLSQLDeveloper for example) it works fine! When run my JDeveloper application I have the bad ordered result set.
    My DB is Oracle 8.1.7 on Windows2000(SP2). The DB language is set as AMERICAN_AMERICA.WE8DEC.
    The client is set with NLS_LANG AMERICAN_AMERICA.WE8DEC and I'm using Oracle OCI JDBC Drivers 8.1.7 deployed with JDeveloper 3.2.
    I presume there's a bug (a BIG BUG!!!) into JDBC Drivers.
    How can I work without trusting in order by ?
    Could anyone help me?
    Thanks
    G.Grimoldi
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Joaquin Sanchez Jimenez ([email protected]):
    Hi:
    Could you send table description and complete query?. What version of JDBC and database ...
    J.<HR></BLOCKQUOTE>
    The table (lisitab) is very simple:
    lisi_codi varchar2(16) not null (PK)
    lisi_desc varchar2(40)
    The select is:
    select lisi_codi from lisitab order by lisi_codi
    I'm working on Oracle 8.1.7 on Windows 2000 and JDBC drivers are Oracle JDBC 8.1.7 deployed with Jdeveloper 3.2.
    I also tried with an Oracle 8.1.7 DB with charset WE8ISO8859P1 and a client with the same charset, but the result is same: bad ordered result set!
    Is there anybody at Oracle who could tell me why and how to resolve (or workaround) this tedious and dangerous problem?
    Thanks
    null

  • Xml parsing error while selecting whole result set for sql query

    Hi All,
    I am having xml parsing error while selecting whole query result set. The data is coming fine for default result set of 50 rows.
    My exception is below.
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00234: namespace prefix "xsi" is not declared
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 254
    ORA-06512: at line 1
    *31011. 00000 - "XML parsing failed"*
    **Cause: XML parser returned an error while trying to parse the document.*
    **Action: Check if the document to be parsed is valid.*
    My sql query is below that is giving results for default result set of 50 rows.
    select extract(xmlType(clob_xml_colm_name), '//v2:node1//childnode/text()','xmlns:v2="namespace_url"').getStringVal()  from table_name
    My sql developer version is below.
    Java(TM) Platform     1.7.0_04
    Oracle IDE     3.1.07.42
    Versioning Support     3.1.07.42
    My database version is below.
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit
    Please could any one help me urgently as the sql query is supposed to be correct as it is returning query results, but the problem happening when i try to select whole result set.
    Thanks and regards,

    What does the XML look like? It appears that some of the supposed XML stored as a CLOB is not really valid XML. Find the row in the table that is causing your issue and review the "XML" in it.

  • Create a CF Query Result Set in Java

    I'd like to programatically build a ColdFusion query resultset inside of a Java class and return it to the calling application.  See the Java psudocode below to see what I'm talking about:
    public class MyClass {
         public coldfusion.sql.QueryTable getQuery() {
              // Create a query table object
              QueryTable myTable = ..?
              // Loop through some set of instance data for my class
              for(int c = 0; c < this.myWigets.length; c++) {
                   int row = c+1;
                   myTable.setField(row, nameCol, this.myWigets[c].name);
                   myTable.setField(row, colorCol, this.myWigets[c].color);
              return myTable;
    I've had stuff like this partially working in the past but had issues with things like query of queries and such probably due to the hacks used to create the QueryTable object.  I'm mainly just checking in to see if there has been any progress made in this area.  To me this seems like such an obvious thing for a Java developer working within CF to want to do.  I'm surprised Adobe doesn't have an officially supported API for doing this sort of thing (or maybe I'm just too dumb to find it.)    A few other notes... I'm not using CFX, and I'm not starting with a java.sql.ResultSet otherwise I would use the QueryTable(java.sql.ResultSet) constructor.  I need to build this thing from scratch programatically.
    Thanks for your time.  I hope this question makes sense to someone out there.
    - Mike

    I appologize.  I wasn't very clear with my original question.
    I'm creating an instance of my Java class from within CF using createObject("java", "com.example.MyClass").  So based on the sample code in my original post on the CF side I'd like to do something like this:
    <cfscript>
         myObj = createObject("java", "com.example.MyClass");
         myObj.doSomeStuff();
         myCFQuery = myObj.getQuery();  // Return a CF query from my java class
    </cfscript>
    ... then do stuff like ...
    <cfquery name="mySortedQuery" dbtype="query">
         select     *
         from       myCFQuery
         order      by color
    </cfquery>
    I appriciate your suggestions so far.  I have other solutions working already but they are not ideal.  I was just hoping someone had a clean and as-hack-free-as-possible way of creating a ColdFusion query result set in Java and passing it back to CF.
    Thanks again,
    Mike

  • Limit on Query result set

    Limit on Query result set
    Is there anyway in Oracle9i to limit query result
    I.e.: we can limit query result in MySQL
    SELECT * FROM EMP LIMIT 2;
    Will return only top 2 records
    Thanks in advance

    SELECT * FROM EMP WHERE ROWNUM <= 2;

  • How to insert the select query result into table?

    How to insert the select query result into table?
    SELECT  top 20 creation_time  
            ,last_execution_time 
            ,total_physical_reads
            ,total_logical_reads  
            ,total_logical_writes
            , execution_count 
            , total_worker_time
            , total_elapsed_time 
            , total_elapsed_time / execution_count avg_elapsed_time
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset 
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END 
                - qs.statement_start_offset)/2) + 1) AS statement_text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    ORDER BY total_elapsed_time / execution_count DESC;
    Thanks,
    Tirumala

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • Select query resulting in redo?

    Hi All,
    Does select query results in redo? In what cases this happens?
    Regards,
    Sphinx

    mtefft wrote:
    Another possibility is that the SELECT query invokes a PL/SQL function that performs insert, update or delete.
    This is a poor practice for a number of reasons but they are out there.
    Disagree with that. Proof:
    SQL> create table x(y number);                                   
    Table created.                                                   
    SQL> create function f return number as                          
      2  begin                                                       
      3  insert into x values (2);                                   
      4  return 1;                                                   
      5  end;                                                        
      6  /                                                           
    Function created.                                                
    SQL> select dummy, f() from dual;                                
    select dummy, f() from dual                                      
    ERROR at line 1:                                                 
    ORA-14551: cannot perform a DML operation inside a query         
    ORA-06512: at "HR.F", line 3                                     

  • Xcelsius with XMLA or XML Query Result Set

    Hi Experts,
    I want a direct connection from Xcelsius to my BW-Data. Because the new connection, coming with Fix Pack 2.1 is only avaiable for EHP 1 for NW 7.0 I tried to configure with XMLA and XML Query Result Set.
    This Document tells the necessary steps: How to integrate Xcelsius 2008 with SAP NetWeaver BI without Integration Kit.pdf.
    When I test my XML connection over http://<host>:<port>/TXmla/srvlet/TestXmla my Cubes will display.
    So I do a Webservice-Connection with WSDL-URL. At Input-Values there are some entries like CUBE_NAME, CATALOG_NAME...
    Output values arent avalible. How do I use these elements to show my Data in Xcelsius?
    My Problem with the XML Query Result Set Connection is, that when I Log On to VC the following error appears:
    You are not authorized to view the requested resource.
    So I get the authorisationobjects: S_DEVELOP and S_RS_COMP as describe in 'How To... Resolve Visual Composer Issues'.
    What values have I to enter by S_RS_COMP? And how can I enter my External Service in S_SERVICE. At the type WS the service isnt't avaiable.
    Regards,
    Jan

    To use XMLA web service you need a wrapper function build to convert the XMLA output to the Xcelsius format. There are some documents available in SDN on how to do this.
    You can use Live Office or Query as a Web service option to connect from Xcelsius to BW.
    S_RS_COMP is the query ID which you are trying to access, S_SERVICE you can either give * or try to set up authorization log and see the expected value.

  • Error in testing XML query result set web service

    Hi
    I was trying to test a <b>XML query result set web service</b> in BW system with tcode wsadmin but getting error like
    <b>Cannot download WSDL from http://ibmbtsb02.megacenter.de.ibm.com:8070/sap/bw/xml/soap/queyview?sap-client=001&wsdl=1.1&mode=sap_wsdl: F:\usr\sap\W70\DVEBMGS70\j2ee\cluster\server0\apps\sap.com\com.sap.engine.services.webservices.tool\servlet_jsp\wsnavigator\root\WEB-INF\temp\ws1139464945296\wsdls\wsdlroot.wsdl (The system cannot find the path specified)</b>
    I had tried it first time few days ago and was able to test it successfully with the same configuration settings.
    Could any one of you please provide any suggestion on this?
    Thanks in advance
    Sudip

    hi
    check this links it may help u.
    http://help.sap.com/saphelp_nw04/helpdata/en/c3/e3072e65f04445a010847aa970b68b/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/d8/3bfc3f8fc2c542e10000000a1550b0/frameset.htm
    Regards,
    Manoseelan

  • Downloading Query result set

    Hi forum,
    We have a requirement to download query result set and distribute it as a periodic job. Can open hub be used for this purpose?
    Thanks in advance.
    Regards,

    Hai i beleive your using BI 7 you can meet your objective by using broadcast and schedule the same hope you have the right EP access too .
    Goodday

  • Stepping through a query result set, replacing one string with another.

    I want to write a function that replaces the occurance of a string with another different string.  I need it to be a CF fuction that is callable from another CF function.  I want to "hand" this function an SQL statement (a string) like this:   (Please note, don't bother commenting that "there are eaiser ways to write this SQL..., I've made this simple example to get to the point where I need help.  I have to use a "sub_optimal" SQL syntax just to demonstrate the situation)
    Here is the string I want to pass to the function:
    SELECT
      [VERYLONGTABLENAME].FIRST_NAME,
      [VERYLONGTABLENAME].LAST_NAME,
      [VERYLONGTABLENAME].ADDRESSS
    FROM
      LONGTABLENAME [VERYLONGTABLENAME]
    Here is the contents of the ABRV table:
    TBL_NM,  ABRV    <!--- Header row--->
    VERYLONGTABLENAME, VLTN
    SOMEWHATLONGTALBENAME, SLTN
    MYTABLENAME, MTN
    ATABLENAME, ATN
    The function will return the original string, but with the abreviations in place of the long table names, example:
    SELECT
      VLTN.FIRST_NAME,
      VLTN.LAST_NAME,
      VLTN.ADDRESSS
    FROM
      LONGTABLENAME VLTN
    Notice that only the table names surrounded by brackets and that match a value in the ABRV table have been replaced.  The LONGTABLENAME immediately following the FROM is left as is.
    Now, here is my dum amatuer attempt at writing said function:  Please look at the comment lines for where I need help.
          <cffunction name="AbrvTblNms" output="false" access="remote" returntype="string" >
            <cfargument name="txt" type="string" required="true" />
            <cfset var qAbrvs="">  <!--- variable to hold the query results --->
            <cfset var output_str="#txt#">  <!--- I'm creating a local variable so I can manipulate the data handed in by the TXT parameter.  Is this necessary or can I just use the txt parameter? --->
            <cfquery name="qAbrvs" datasource="cfBAA_odbc" result="rsltAbrvs">
                SELECT TBL_NM, ABRV FROM BAA_TBL_ABRV ORDER BY 1
            </cfquery>
         <!--- I'm assuming that at this point the query has run and there are records in the result set --->
        <cfloop index="idx_str" list="#qAbrvs#">      <!--- Is this correct?  I think not. --->
        <cfset output_str = Replace(output_str, "#idx_str#", )  <!--- Is this correct?  I think not. --->
        </cfloop>               <!--- What am I looping on?  What is the index? How do I do the string replacement? --->
            <!--- The chunck below is a parital listing from my Delphi Object Pascal function that does the same thing
                   I need to know how to write this part in CF9
          while not Eof do
            begin
              s := StringReplace(s, '[' +FieldByName('TBL_NM').AsString + ']', FieldByName('ABRV').AsString, [rfReplaceAll]);
              Next;
            end;
            --->
        <cfreturn output_txt>
        </cffunction>
    I'm mainly struggling with syntax here.  I know what I want to happen, I know how to make it happen in another programming language, just not CF9.  Thanks for any help you can provide.

    RedOctober57 wrote:...
    Thanks for any help you can provide.
    One:
    <cfset var output_str="#txt#">  <!--- I'm creating a local
    variable so I can manipulate the data handed in by the TXT parameter.
    Is this necessary or can I just use the txt parameter? --->
    No you do not need to create a local variable that is a copy of the arguments variable as the arguments scope is already local to the function, but you do not properly reference the arguments scope, so you leave yourself open to using a 'txt' variable in another scope.  Thus the better practice would be to reference "arguments.txt" where you need to.
    Two:
    I know what I want to happen, I know how to make it happen in another programming language, just not CF9.
    Then a better start would be to descirbe what you want to happen and give a simple example in the other programming language.  Most of us are muti-lingual and can parse out clear and clean code in just about any syntax.
    Three:
    <cfloop index="idx_str" list="#qAbrvs#">      <!--- Is this correct?  I think not. --->
    I think you want to be looping over your "qAbrvs" record set returned by your earlier query, maybe.
    <cfloop query="qAbrvs">
    Four:
    <cfset output_str = Replace(output_str, "#idx_str#", )  <!--- Is this correct?  I think not. --->
    Continuing on that assumption I would guess you want to replace each instance of the long string with the short string form that record set.
    <cfset output_str = Replace(output_str,qAbrs.TBLNM,qAbrs.ABRV,"ALL")>
    Five:
    </cfloop>               <!--- What am I looping on?  What is the index? How do I do the string replacement? --->
    If this is true, then you are looping over the record set of tablenames and abreviations that you want to replace in the string.

  • Query result set...

    I'm having trouble determining a good way to word my question. So, I believe my pseudo code below will be sufficient in doing so.
    Oracle version: 11.2g
    Data set
    WITH temp AS
    SELECT 1 col1, 1 day FROM dual UNION ALL
    SELECT 2 col1, 1 day FROM dual UNION ALL
    SELECT 3 col1, 1 day FROM dual UNION ALL
    SELECT 4 col1, 1 day FROM dual UNION ALL
    SELECT 5 col1, 1 day FROM dual UNION ALL
    SELECT 6 col1, 1 day FROM dual UNION ALL
    SELECT 7 col1, 2 day FROM dual UNION ALL
    SELECT 8 col1, 2 day FROM dual UNION ALL
    SELECT 9 col1, 2 day FROM dual UNION ALL
    SELECT 10 col1,2 day FROM dual
    SELECT *
      FROM temp
    Result of the query above:
    COL1     DAY
    1     1
    2     1
    3     1
    4     1
    5     1
    6     1
    7     2
    8     2
    9     2
    10     2
    DESIRED result set:
    DAY COL_TOTAL
    1   21 
    2   55   -- 21 + 33 (the sum of day 1 + the sum of day 2)I realize that I can get the desired result set from above with the code below. However, for my actual issue I have several other data points and 100 of distinct days that I need to do this for. So doing a 100 UNION statement isn't exactly going to work.
    WITH temp AS
    SELECT 1 col1, 1 day FROM dual UNION ALL
    SELECT 2 col1, 1 day FROM dual UNION ALL
    SELECT 3 col1, 1 day FROM dual UNION ALL
    SELECT 4 col1, 1 day FROM dual UNION ALL
    SELECT 5 col1, 1 day FROM dual UNION ALL
    SELECT 6 col1, 1 day FROM dual UNION ALL
    SELECT 7 col1, 2 day FROM dual UNION ALL
    SELECT 8 col1, 2 day FROM dual UNION ALL
    SELECT 9 col1, 2 day FROM dual UNION ALL
    SELECT 10 col1,2 day FROM dual
    SELECT SUM(col1) AS col_total
      FROM temp
    WHERE day <= 1
    UNION ALL
    SELECT SUM(col1) AS col_total
      FROM temp
    WHERE day <= 2Edited by: user652714 on Aug 13, 2012 9:55 PM

    Hi,
    I see now what you want . You can use this:
    select *
    from tt
    order by col_1;
         COL_1        DAY
             1          1
             2          1
             3          1
             4          1
             5          1
             6          1
             7          2
             8          2
             9          2
            10          2
    10 rows selected.
    select day, sum(total) over  (order by  day) COL_TOTAL
    from
    (select day, sum(col_1) TOTAL
    from tt
    group by day
        DAY  COL_TOTAL
             1         21
             2         55
    2 rows selected.

  • How to order SQL query results in order given in IN Clause

    Hi,
    I Need to construct a query, which takes a string as input and results for those should be sorted in the order in which request was made.
    Say, we have a couple of students, and the grades in different subjects to be the result of the query.
    If John and Jane are the two students,
    and if input is John,Jane
    my output should be listing John, his subjects and grades
    and then Jane, her subjects and grades.
    I read somewhere in other posts, that i could use a query combined with regular expression to split a string into a temp table/array and use this as my input for my select query. Then use the rownum or level from this temp table to sort the data in order sent in.
    But am not able to put together a query which would work for me.
    Anyone with any pointers on this would be highly appreciated.
    Thanks

    Hi,
    [This thread|http://forums.oracle.com/forums/thread.jspa?threadID=702891&tstart=0] is about splitting up delimited lists. You'll want to keep the n-th value from the user-supplied list, as well as n itself, in a result set, so you can use it in both your WHERE- and your ORDER BY clause.
    If you're using SQL*Plus, you can also keep the whole list in a substriution variable, and use INSTR to see where individual values appeard in that list. Personally, I'd trust the first method (split and store) more.

  • Help assigning a   calculated arbitrary  ID to a query result set

    Given the sample query result..
    (sorry about the formatting of the output)
    GROUPID LAST_NAME FIRST_NAME INITIALS EMAIL PHONE count(PHONE)
    GP2001 Troy Diana s [email protected] 123-456-7890 2
    GP2001 Troy Diana s [email protected] 123-456-7890 2
    GP2006 Thomas Carl p [email protected] 789-100-1112 1
    GP2007 Riker William T [email protected] 866-908-6654 1
    GP3001 Laforge Jody m jlaforge@enterprisenet 456-789-9000 3
    GP3001 Laforge Jody m [email protected] 456-789-9000 3
    GP3001 Laforge Jody m [email protected] 456-789-9000 3
    GROUP_ID is a calculated field from a select statement.
    Individuals with one phone number (ph_cnt = 1)
    is assigned an arbitrary unique GROUP_ID.
    Individuals, appearing more than once, with more than one phone (ph_cnt > 1)
    are giving the same GROUP_ID.
    I was thinking of using a case statement in this case...but got stuck on generating the GROUP_ID based
    on the phone count.
    select case
    when ph_cnt = 1 then select 'GP'||to_char(sysdate,'hhmisssss') from dual)
    when ph_cnt > 2 then <assign a unique group_id to each set of duplicates/triplicate...etc>
    end GROUP_ID,
    last_name,
    first_name,
    initials,
    email,
    phone
    (select last_name,
    first_name,
    initials,
    email,
    phone,
    count(phone) ph_cnt
    from my tab
    group by
    last_name,first_name,initials,email,phone)
    Edited by: ch**** on Apr 25, 2011 7:20 AM

    Try this,
    SELECT 'GP' || 1000 + DENSE_RANK () OVER (ORDER BY phone ASC) groupid,
           last_name,
           first_name,
           initials,
           email,
           phone,
           COUNT (1) OVER (PARTITION BY phone) ph_cnt
      FROM my tab;G.

  • Query Result Column Order

    I'm working with an embedded db query that specifies columns
    by name in the result set, i.e., no *. However, the order of the
    columns in the result set seem to be quite random - or at least
    dependent on which column is being searched. I'm showing the
    results via "resultsGrid." How do I enforce a consistent column
    order in query results?
    Thanks,
    Al

    What you describe boils down to a reinvention of materialized views.
    Did you consider using them?
    Sybrand Bakker
    Senior Oracle DBA

Maybe you are looking for

  • While updating user Details I am gettingsome error

    Hi , While updating the user details from OIM server(OIM 9102 BP12) I am getting following error.Same is working properly on BP02.Can anybody help me to find out what is the root cause of this problem? - I am trying to ceare a user through PSFT test

  • Problem with Pattern Matching

    Hello,  I am using Vision Development Module 8.5 with VB6.   I need immediate help on coming up with a solution for an auto warranty return for incomplete "Fog Lamp" indicator symbol.  I use a match score minumum of 900, but the match score returns a

  • .html appears as .html in browser

    My uploaded local index.html file appears as .html rather than as text on two of my Macs X.4 in Safari, IE, Firefox, and iCab. It appears as .html also on Optimum Online who gives me cable and on GoDaddy.com. In Easy-cgi.com however they say it appea

  • Designer query panel and desktop intelligence query panel

    In Designer and Desktop Intelligence there is query panel. Customer want to know the query panel using the same dll file in Designer and Desktop Intelligence? And is it the same in XIR2 and XI3.1. Do you know the query panel in Designer and Desktop I

  • IChat not posting correctly (through AIM)

    As of sometime yesterday, my version of iChat (which is 6.0.2, I noticed that wasn't a version listed here, oddly) has been acting funny for blocks of text for AIM. A buddy of mine copy and pasted a paragraph of text and, although I heard the post no