SQL Query rewrite, remove ORDER BY clause

Hello,
we've just installed a proprietary application which uses an Oracle 11.2.0.2 RAC database. We've seen that one of the auto-generated application's queries
has poor performance (3-5 minutes for results), the query does a SELECT and at the end it uses an ORDER BY clause. If we remove the ORDER BY clause
the query returns the results in less than 5 seconds. Unfortunately, we can't re-write the query in the application since we don't have any access to it and
i was wondering if there is a way to rewrite the specific query from the database.
We've already seen the SQL Patch but we can change only the hints of the query so we can't remove the ORDER BY clause from it. From what we've seen
outlines also change only the hints and not the actual sql statement.
Is there a way to rewrite the specific query from the database ?
thanks in advance,
Giannis

Maybe DBMS_ADVANCED_REWRITE can help but this a SQL question than has very likely nothing to do with RAC.
See http://www.oracle-base.com/articles/10g/dbms_advanced_rewrite.php.

Similar Messages

  • Problem in sql query because of order by clause

    Hi All,
    I am facing a one problem in my one sql query.I am using Oracle 10gR2.
    Query is given below:
    SELECT t1.ename
            FROM T1, T2
           WHERE T1.EMPNO = 1234
             AND T1.ACCOUNTNO = T2.ACCOUNTNO
             AND T1.SEQ = T2.SEQ
           ORDER BY T2.SEQThe Plan of the query is :
    | Id  | Operation                     | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID  | T1                   |     1 |    89 |     1   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS                |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| T2                   |     2 |    40 | 11715   (1)| 00:00:41 |
    |   4 |     INDEX FULL SCAN           | PK_T2_SEQ            | 58752 |       |   122   (5)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN           | FK_ACCOUNTNO         |     3 |       |     0   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------Now i want to reduce the time of this query.
    If i am removing Order by clause from query than performance of the query is totally perfect but with order by clause its taking a time.
    I have already set SORT_AREA_SIZE but still nothing is improving.
    Welcome and thanks for your suggestions.
    Thanks,
    Edited by: BluShadow on 23-Jun-2011 07:55
    added {noformat}{noformat} tags and formatted explain plan to make it readable.  Please see {message:id=9360002} for details on how to post code and data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    There are a couple of things I do not understand.
    1. Why don't you put {noformat}{noformat} around your code, it makes it so much easier to read, especially your explain plan
    2. You claim that the ORDER BY is problematic compared to no order by. Then why do you choose to post only one plan?
    3. It is hard to understand how your tables relate, and which indexes you have and which you don't.
    - PK_T2_SEQ, does this mean that SEQ alone is primary key of T2?
    - If SEQ is primary key of T2, why do you join on accountno, seq and not just seq?
    - If SEQ is primary key of T2 one of the tables is denormalized.
    4. FK_ACCOUNTNO, is this an index on accountno, alone?
    - Or is this AccountNo, Seq?
    5. Is there no index on T1.EMPNO?
    Above could of course just be a case of my not understanding the names of your indexes.
    So, here are my guesses:
    Above plan is for the ORDER BY query. That means the optimizer, has chosen to full scan PK_T2_SEQ, since data is then read according to the ORDER BY.
    (This could be a bad choice)I
    You could try and order by t1.seq, instead. Result should be the same.
    Regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem with SQL query region source containing OLAP clauses

    Hi team,
    I believe I found a bug when HTMLDB validates the SQL Query in a report region.
    My query includes an ORDER BY clause within a windowing function and HTMLDB refuses to accept the source owing to the presence of the ORDER BY and the column heading sort preference.
    Clearly the order-by in a window function has little to do with the column heading sort, but this error prevents me from updating the conditional display item in the page definition.
    Note also that the page was imported smoothly from the 1.5 version, so probably the region source is not checked at that time, but only when you update it "manually".
    So, in the end, if I don't change anything the page works because the sql query is assumed to be correct but unfortunately I need to change the condition and I cannot.
    The problem shows up in page 126 of app 21670, SQL query region.
    Bye,
    Flavio
    PS: may be I can work around this by using the pl/sql function returning the sql query.

    Flavio,
    We're aware of this problem. For now, your workaround is described in this thread:
    HTMLDB 1.6 and "order by" in analytic functions
    Sergio

  • How to write a SQL Query without using group by clause

    Hi,
    Can anyone help me to find out if there is a approach to build a SQL Query without using group by clause.
    Please site an example if is it so,
    Regards

    I hope this example could illuminate danepc on is problem.
    CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
    CREATE OR REPLACE FUNCTION GET_ARR return my_array
    as
         arr my_array;
    begin
         arr := my_array();
         for i in 1..10 loop
              arr.extend;
              arr(i) := i mod 7;
         end loop;
         return arr;
    end;
    select column_value
    from table(get_arr)
    order by column_value;
    select column_value,count(*) occurences
    from table(get_arr)
    group by column_value
    order by column_value;And the output should be something like this:
    SQL> CREATE or replace TYPE MY_ARRAY AS TABLE OF INTEGER
      2  /
    Tipo creato.
    SQL>
    SQL> CREATE OR REPLACE FUNCTION GET_ARR return my_array
      2  as
      3   arr my_array;
      4  begin
      5   arr := my_array();
      6   for i in 1..10 loop
      7    arr.extend;
      8    arr(i) := i mod 7;
      9   end loop;
    10   return arr;
    11  end;
    12  /
    Funzione creata.
    SQL>
    SQL>
    SQL> select column_value
      2  from table(get_arr)
      3  order by column_value;
    COLUMN_VALUE
               0
               1
               1
               2
               2
               3
               3
               4
               5
               6
    Selezionate 10 righe.
    SQL>
    SQL> select column_value,count(*) occurences
      2  from table(get_arr)
      3  group by column_value
      4  order by column_value;
    COLUMN_VALUE OCCURENCES
               0          1
               1          2
               2          2
               3          2
               4          1
               5          1
               6          1
    Selezionate 7 righe.
    SQL> Bye Alessandro

  • Help: PL/SQL passing paramter to ORDER BY clause

    I am working on a procedure that using a parameter to pass sorting order. If there parameter, say p_order which is varchar2, can I just use the it directly passing the field name to the order by clause?
    What I really want to know is that do I have to use decode together with p_order to achieve the goal?
    WJH

    Hi,
    The positional notaion in ORDER BY, e.g.
    ORDER BY 2, 1is one of the rare cases in which a numeric literal is required. Using an expression, even a bind variable, won't raise an error, but won't sort, either. (It's equivalent to sorting by a constant, which doesn't sort at all.)
    Like Centinul said, you have to use dynamic SQL to construct the ORDER BY clause, or use some kind of IF-THEN-ELSE logic (such as CASE), like this:
    SELECT    ename, sal
    FROM      scott.emp
    ORDER BY  CASE
                  WHEN  :x = 1  THEN ename
                  ELSE  TO_CHAR (sal, '000000')
              END;

  • SQl query to remove all dbms_output statement

    Hi
    Can u please tell me Single SQl query to remove all dbms_output statement from package and procedure
    Umesh

    >
    Can u please tell me Single SQl query to remove all
    dbms_output statement from package and procedure
    If you are comfortable with scripting languages like Perl, Python, Ruby etc., then removing lines having the dbms_output statements from your files should be a trivial matter.
    pratz

  • 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.

  • Need sql query to remove duplicates using UNION ALL clause

    Hi,
    I have a sql query which has UNION clause.But the UNION clause is causing some performance issues.
    To overcome that I have used UNION ALL to improve performance but its returning duplicates.
    Kindly anyone send a sample SQL query where my primary objective is used to use UNION ALL clause and to consider unique rows (elimating duplicate
    ones)
    Any help will be needful for me
    Thanks and Regards

    why not UNION? :(
    another way also use MINUS
    SQL>
    SQL> with t as
      2  (
      3  select 1 if from dual union all
      4  select 2 if from dual union all
      5  select 1 if from dual union all
      6  select 3 if from dual union all
      7  select 3 if from dual
      8  )
      9  ,t2 as
    10  (
    11  select 1 if from dual union all
    12  select 2 if from dual union all
    13  select 3 if from dual union all
    14  select 4 if from dual union all
    15  select 5 if from dual
    16  )
    17  (select if from t
    18  union all
    19  select if from t2)
    20  /
            IF
             1
             2
             1
             3
             3
             1
             2
             3
             4
             5
    10 rows selected
    SQL> so
    SQL>
    SQL> with t as
      2  (
      3  select 1 if from dual union all
      4  select 2 if from dual union all
      5  select 1 if from dual union all
      6  select 3 if from dual union all
      7  select 3 if from dual
      8  )
      9  ,t2 as
    10  (
    11  select 1 if from dual union all
    12  select 2 if from dual union all
    13  select 3 if from dual union all
    14  select 4 if from dual union all
    15  select 5 if from dual
    16  )
    17  (select if from t
    18  union all
    19  select if from t2)
    20  minus
    21  select -99 from dual
    22  /
            IF
             1
             2
             3
             4
             5
    SQL>

  • Sql count function in order by clause

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Hi Guys
    Can i ask a quick question. I am trying to retrieve data remotely from a SQL Server via crystal reports.
    Within the Database Expert I have entered a SQL query to retrive the number of (call center) support calls raised by our customers:-
    Select `Primary_Company`, COUNT(`Calls`)From  `SPRT_Issue` GROUP BY  `Primary_Company`ORDER BY  COUNT(`Calls`) desc
    The customer's column is called 'Primary Company' and the calls they raise are in the 'Calls' column. the above is a normal sql query.
    However Crystal fails to run the query and generates an error message :-
    Failed to open a rowset. Details: 420: Driver&#93; Expected lexical element not found: <identifier>
    I dont understand why it wont run. In the ORDER BY clause if i replace field 'Calls' by the field 'Primary Company' then it works.
    I think the problem is that it wont accept the count function in the order by clause. which is what i want it to do i.e display the calls in descending order by each customer.
    Could someone tell me if there is a way around it.
    Thanks
    Krypton

    Post Author: krypton
    CA Forum: Data Connectivity and SQL
    Thanks Lynn
    I tried your suggestion. But there is one probelm.
    When i sort the data in descending order using the count(calls) field, the data is returned but the customer's name appears multiple times along with their calls raised.
    E.g, if customer Mark raised multiple calls i.e. 2, 5, and 10 calls, then the report will show
    Mark   2
    Mark  5
    Mark 10
    But is there a way to aggregate all the calls for mark and show them only once:
    such as Mark   17
    Thanks

  • Visual Web - How to 'setObject' for an SQL query with an IN  ? clause

    Hello, I am relatively new to visual web pack. I am stuck at writing the java code for passing parameters to the SQL query. In a normal scenario, where we need to check if some variable is present in a column (= ?), we would pass the parameter as :
    setObject(1, whatevervalue);
    How do we pass parameters if we need to check for more than one variable? The query editor in VWP has the option IN, which allows us to check for more than one match in a column. The IN clause is supposed to allow the format ('ex1', 'ex2' ...). I tried using an array as a parameter, like, setObject(1, somearray). It gives me a null exception. I even tried sending a variable in ('ex1', 'ex2' ...) format; doesn't like it either.
    Any help is greatly appreciated.

    Check the following docs:
    http://www.netbeans.org/kb/60/web/databoundcomponents.html
    http://www.netbeans.org/kb/60/web/inserts-updates-deletes.html
    See also:
    http://developers.sun.com/jscreator/reference/techart/2/query-editor.html

  • Using Parameters in SQL-Query not only in where clauses

    Hi,
    I try to use Publisher parameters in the SQL Query from a Data Set.
    All of them have default values.
    So far, this is no problem, unless I try to use such a parameter value as an ordinary attribute value:
    >
    select
         case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."BETR_TEIL"
                                            else :pv_some_Text end                                                                  as Betr_Teil,
         case when (:pv_Group = 'no') then "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM"
                                            else :pv_some_Text end                                                        as Suva_Nr,
         case when (:pv_Group = 'no') then "DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH"
                                            else sum("DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") end      as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in (:pv_nim100)
         fetch first 65001 rows ONLY
    >
    The parameters 'pv_Group' and 'pv_nim100' are working fine. (when or where clauses)
    The parameter 'pv_some_Text' unfortunately not. (simple literals)
    When I try to validate the above SQL, I get the following Error:
    <font color="red">
    java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46033] Datatype: 25 is not supported.
    </font>
    After use a cast function:
    >
    else CAST(:pv_some_Text AS CHARACTER)
    >
    I get this ERROR:
    <font color="red">
    java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 19002] Incorrect use of parameters. The parameters used in CAST cannot be resolved without ambiguity.
    </font>
    We use OBIEE 11.1.1.6.4 on a Win64-System.
    Thank's for any help.

    Hi Alex,
    let's leave away any unnecessary details.
    This is the SQL, inserted in the window 'Edit Data Set' of BIP Data Model:
    >
    select
         '--1'     as Betr_Teil,
         '--2'      as Suva_Nr,
         sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
         fetch first 65001 rows ONLY
    >
    Everything is fine when I click OK, the script goes back to the metadata.
    Let's try this script with bind values in ORACLE SQL Developer.
    This SQL is the physical part, found in the OBIEE-Log (Log level 5), except the bind values. Therefore we find, in the where clause, the join. In the logical sql, we don't have to join, because it's handled in the Common Enterprise Information Model (CEIM)
    >
    with
    sawith0 as
    select
    sum(t39617.ris_vollbesch) as c1
    from
    dm15d_betriebsteil t39455,
    dm15k_ris_fakten_pro_btt_jhr t39617
    where
    t39455.id_betriebsteil = t39617.id_betriebsteil
    and t39455.suva_nr_form = '122-4.4'
    select
    d1.c1 as c1,
    d1.c2 as c2,
    d1.c3 as c3
    from
    select
    :pv_some_text as c1,
    :pv_some_text as c2,
    sum(d1.c1) as c3
    from
    sawith0 d1
    d1
    where
    rownum <= 65001
    >
    This SQL works fine, even with bind values for 'pv_some_text'.
    But, when using the following SQL in the BIP Data Model:
    >
    select
         :pv_Text as Betr_Teil,
         :pv_Text as Suva_Nr,
         sum("GDWH05"."DM15K_RIS_FAKTEN_PRO_BTT_JHR"."RIS_VOLLBESCH") as Vollbesch
    from "GDWH05"
    where
         "DM15D_BETRIEBSTEIL"."SUVA_NR_FORM" in ('122-4.4')
         fetch first 65001 rows ONLY
    >
    The following ERROR occurs:
    <font color="red">java.io.IOException: prepare query failed[nQSError: 43113] Message returned from OBIS. [nQSError: 46008] Internal error: File server\Query\Optimizer\ServiceInterfaceMgr\Utility\Src\SQOIUTypeVisitor.cpp, line 643.</font>
    In my opinion, either I use a wrong syntax, or BIP has a problem with parsing the script.
    Thank you for your most welcome help.

  • SEQUENCE Select within an SQL Query with an ORDER BY statement

    Does anyone know why you cannot use an ORDER BY statement within an SQL query when also selecting from a SEQUENCE? My query was selecting production data as a result of a filtered search. I want to take the results of the filtered search and create a transaction. I have a sequence for generating transaction numbers where I select NEXTVAL. Since I could possibly obtain multiple, yet distinct, rows based upon my search criteria, I wanted to use an ORDER BY statement to simplify and order the resulting row(s).
    I was able to get the SQL select with SEQUENCE.NEXTVAL to work without the ORDER BY, so I know that my SQL is correct. Thanks in-advance.

    Okay,
    I understand. You want the sequence assigned first and the you want to ORDER BY. You
    can do this using pipelined functions. See here:
    CREATE OR REPLACE TYPE emp_rec_seq AS OBJECT (
       seq     NUMBER,
       ename   VARCHAR2 (20),
       job     VARCHAR2 (20),
       sal     NUMBER
    CREATE OR REPLACE TYPE emp_tab_seq AS TABLE OF emp_rec_seq;
    CREATE OR REPLACE FUNCTION get_emp_with_sequence
       RETURN emp_tab_seq PIPELINED
    IS
       my_record   emp_rec_seq := emp_rec_seq (NULL, NULL, NULL, NULL);
    BEGIN
       FOR c IN (SELECT dummy.NEXTVAL seq, ename, job, sal
                   FROM emp)
       LOOP
          my_record.seq := c.seq;
          my_record.ename := c.ename;
          my_record.job := c.job;
          my_record.sal := c.sal;
          PIPE ROW (my_record);
       END LOOP;
       RETURN;
    END get_emp_with_sequence;after that, you can do a select like this:
    SELECT seq, ename, job, sal
      FROM TABLE (get_emp_with_sequence)
      order by enamewhich will get you this:
           SEQ ENAME                JOB                         SAL
          1053 BLAKE                MANAGER                    2850
          1054 CLARK                MANAGER                    2450
          1057 FORD                 ANALYST                    3000
          1062 JAMES                CLERK                       950
          1055 JONES                MANAGER                    2975
          1052 KING                 MANAGER                   20000
          1060 MARTIN               SALESMAN                   1250
          1063 MILLER               CLERK                      1300
          1064 DKUBICEK             MANAGER                   12000
          1056 SCOTT                ANALYST                    3000
          1058 SMITH                CLERK                       800
          1061 TURNER               SALESMAN                   1500
          1059 WARD                 SALESMAN                   1250Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://htmldb.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • SQL - Query rewrite ?

    Hi
    I have this query
    SELECT a.col1,
    a.col2,
    a.col3,
    a.col4
    FROM table1 a
    WHERE a.id = (SELECT MAX (id)
    FROM table1
    WHERE table1.datecol <= p_date AND table1.col5 = p_number);
    This is a cursor in a function so p_date and p_number are in parameters.
    In the example above table1 contains abot 300 million rows, and the query does 2 scans
    of the table1.
    Is there anyway to rewrite this SQL statment with one access only ?

    Both query will not give the same results
    WITH table1 AS
    (select 1 id, 1 col1, 1 col2, 1 col3, 1 col4, 1 col5, to_date('01/01/2011','dd/mm/yyyy') datecol from dual
    union
    select 1 id, 2 col1, 2 col2, 2 col3, 2 col4, 2 col5, to_date('02/01/2011','dd/mm/yyyy') datecol from dual
    union
    select 3 id, 3 col1, 3 col2, 3 col3, 3 col4, 3 col5, to_date('03/01/2011','dd/mm/yyyy') datecol from dual
    union
    select 4 id, 4 col1, 4 col2, 4 col3, 4 col4, 3 col5, to_date('03/01/2011','dd/mm/yyyy') datecol from dual
    SELECT a.col1,
    a.col2,
    a.col3,
    a.col4
    FROM table1 a
    WHERE a.id = (SELECT MAX (id)
    FROM table1
    WHERE table1.datecol <= to_date('03/01/2011','dd/mm/yyyy')
    AND table1.col5 = 3);
    WITH table1 AS
    (select 1 id, 1 col1, 1 col2, 1 col3, 1 col4, 1 col5, to_date('01/01/2011','dd/mm/yyyy') datecol from dual
    union
    select 1 id, 2 col1, 2 col2, 2 col3, 2 col4, 2 col5, to_date('02/01/2011','dd/mm/yyyy') datecol from dual
    union
    select 3 id, 3 col1, 3 col2, 3 col3, 3 col4, 3 col5, to_date('03/01/2011','dd/mm/yyyy') datecol from dual
    union
    select 4 id, 4 col1, 4 col2, 4 col3, 4 col4, 3 col5, to_date('03/01/2011','dd/mm/yyyy') datecol from dual
    SELECT * FROM
    (SELECT
    a.id,
    max(a.id) over (partition by a.id order by a.id) maxid,
    a.col1,
    a.col2,
    a.col3,
    a.col4,
    a.datecol,
    a.col5 
    FROM table1 a)
    WHERE datecol <= to_date('03/01/2011','dd/mm/yyyy')
        AND col5 =3    
        AND id = maxid;Best regards
    Mohamed Houri

  • SQL QUERY TO REMOVE ONE OF THE THE RESULT SET

    Hello Everyone,
    I need some advise on how to achieve the subject. My query is as follows:
    select t2.post_date a, trunc(sysdate - (&num + 1))
    from trans_hist t2
    where t2.post_date >= trunc(sysdate - (&num + 1))
    and 'xxxxxxxxxxxxxxx' in
    (t2.reference_from_account_id, t2.reference_to_account_id)
    and decode(t2.reference_from_account_id,
    'xxxxxxxxxxxxxxx',
    t2.from_account_balance,
    t2.to_account_balance) = 150
    order by t2.post_date
    It will give me the following result:
    4-JUN-2007
    5-JUN-2007
    6-JUN-2007
    I will would to build my query so that it excludes the last row. My aim is to come up with something like the below:
    select max(t2.post_date)
    from trans_hist t2
    where t2.post_date >= trunc(sysdate - (&num + 1))
    and 'xxxxxxxxxxxxxxx' in
    (t2.reference_from_account_id, t2.reference_to_account_id)
    and decode(t2.reference_from_account_id,
    'xxxxxxxxxxxxxxx',
    t2.from_account_balance,
    t2.to_account_balance) = 150
    order by t2.post_date
    Thank you for your help.
    Randy

    maybe something like:
    SQL> with trans_hist as
      2  (select to_date('4-JUN-2007','DD-MON-YYYY') post_date from dual union all
      3   select to_date('5-JUN-2007','DD-MON-YYYY') post_date from dual union all
      4   select to_date('6-JUN-2007','DD-MON-YYYY') post_date from dual)
      5  select * from trans_hist;
    POST_DATE
    04-JUN-07
    05-JUN-07
    06-JUN-07
    SQL> with trans_hist as
      2  (select to_date('4-JUN-2007','DD-MON-YYYY') post_date from dual union all
      3   select to_date('5-JUN-2007','DD-MON-YYYY') post_date from dual union all
      4   select to_date('6-JUN-2007','DD-MON-YYYY') post_date from dual)
      5  select transaction_history.post_date
      6    from (select post_date,
      7                 row_number() over (order by post_date desc) rn
      8            from trans_hist) transaction_history
      9   where transaction_history.rn > 1;
    POST_DATE
    05-JUN-07
    04-JUN-07
    SQL> in your code it will be something like:
    select t3.a, t3.b
      from (select t2.post_date a, trunc(sysdate - (&num + 1)) b,
                   row_number() over (order by t2.post_date desc) rn
              from trans_hist t2
             where t2.post_date >= trunc(sysdate - (&num + 1))
               and 'xxxxxxxxxxxxxxx' in (t2.reference_from_account_id, t2.reference_to_account_id)
               and decode(t2.reference_from_account_id,'xxxxxxxxxxxxxxx',t2.from_account_balance,t2.to_account_balance) = 150) t3
    where t3.rn > 1
    order by t3.a

  • SQL Query to re-order the columns

    Hello All,
    I want to know if it is possible to re-order the columns of a table once the rows has been inserted in all the columns.
    So for e.g I have initially a table containing 3 columns COL1, COL2 & COL3.
    Now after data has been inserted into the table, I want to re-order the columns like COL3, COL2, COl1 or may be COL2, COL1, COL3 etc keeping the data intact.
    Cheers,
    Parag

    Parag Kalra wrote:
    I want to know if it is possible to re-order the columns of a table once the rows has been inserted in all the columns.
    So for e.g I have initially a table containing 3 columns COL1, COL2 & COL3.
    Now after data has been inserted into the table, I want to re-order the columns like COL3, COL2, COl1 or may be COL2, COL1, COL3 etc keeping the data intact.Why? What is your reason for wanting to do this? What do you want to achieve by it? If we understand the actual problem, then we may be able to provide some usable suggestions.
    The reason why your request makes very little sense is that the physical sequence of columns in a row in a datablock, has no impact on you as developer writing code.
    Why? Because you control the order in which you want to select columns. You control the order in which you insert columns. You control the order in which you update columns.
    SQL allows you the programmer to specify the sequence of columns, and subset of columns, that you want to use in your SQL.
    Why would you want to change the physical table definition, and rewrite the entire table on disk (using very expensive I/O) to reorder the physical column sequence?

Maybe you are looking for

  • How do I put a DVD in and transfer it as one file to my external?

    How do I put a DVD in and transfer it as one file to my external?

  • 'New Discussion' form

    Hello everyone I have a Discussion Groups page in a collaboration room template.  When a user goes to create a new discussion in one of the discussion groups, the discussion topic title field is labeled as 'Name'.  I'm interested in changing this lab

  • Marking text as non-printing

    I read that in ID CS4 it's possible to mark text as non-printing (while still including it in a TOC). However, I can't find where this command is ... Can anyone help?

  • Extending Extreme 5GHz signal with Express?

    I have a airport extreme setup in the bedroom running dual band 2.4ghz and 5ghz. I'm trying to force my macbook pro in the living room to only use the 5ghz band but it falls to the 2.4 band because I believe there are too many walls from point A to p

  • Error when I try to look at the files backed up

    Every time I use time machine it seems like its fine and I have an external disk. When I take my external disk so my friend can use it to take photos it comes up with an error that says error code-10657 which I have no idea what that means. I can't g