First clause with order by

Hi,
I have a requirement where I need to display a list of employees, performance rating and manager id. I want to display the emplyees first whos manager is as manager_id as input parameter. So lets say a manager logs in, he should see his reportees first and then therest. How can I implemet this in SQL? I am trying first clause with order by but not sure how to do that here. A help on this would be appreciated.
procedure
display_list(manager_id in varchar2)
Output is:
emp_id
manager_id
performance_rating
Edited by: Nandini on Apr 28, 2013 10:48 PM

You can use a CASE statment, which will check the MANGER_ID column against the passed manager id value, as shown below..
order by
  case when manager_id = :input_manager_id then 0
         else 1
  end,manager_id,performace_rating desc

Similar Messages

  • IN clause with ORDER BY clause in sub-queries

    Hello,
    We generate dynamic queries with the following statement pattern (could be many union/intersect sub-queries):
    select my_col
    from my_table
    where my_col IN
    select table_2.my_col , x_col from table_2 where x_col > 10
    UNION
    select table_3.my_col , y_col from table_3 where y_col > 20
    INTERSECT
    select table_4.my_col , z_col from table_4 where z_col is between 30 and 50
    I know that I can do just the sub-queries w/ an ORDER BY clause as follows (as long as the 2nd parameter in the select stmts are of the same type):
    select table_2.my_col , x_col from table_2 where x_col > 10
    UNION
    select table_3.my_col , y_col from table_3 where y_col > 20
    INTERSECT
    select table_4.my_col , z_col from table_4 where z_col is between 30 and 50
    order by 2 desc
    But my questions are:
    1. What is (if there is) the syntax that will ensure that the result set order will be that of the ordering of the sub-queries?
    Or does my SQL stmt have to have syntactically (but not semantically) change to achieve this?
    Thanks,
    Jim

    Randolf Geist wrote:
    just a minor doubt - I think it is not officially supported to have separate ORDER BYs in a compound query with set operators (e.g. UNION / UNION ALL subsets). Of course one could use inline views with NO_MERGE + NO_ELIMINATE_OBY hints, but I think the only officially supported approach is to use a single, final ORDER BY (that needs to use positional notation as far as I remember).
    Randolf,
    You're right, of course, about the separate "order by" clauses.
    Interestingly the following type of thing does work though (in 10.2.0.3, at least):
    with v1 as (
        select * from t1 where col1 = 'ABC' order by col2
    v2 as (
        select * from t1 where col1 = 'DEF' order by col2
    select * from v1
    union all
    select * from v2
    ;A quick check the execution plan suggsts that Oracle appears to be convering this to the following - even though its technically not acceptable in normal circumstances:
    select * from t1 where col1 = 'ABC' order by col2
    union all
    select * from t1 where col1 = 'DEF' order by col2
    ;Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
    "Science is more than a body of knowledge; it is a way of thinking"
    Carl Sagan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Default where with order by clause

    Hi all
    How to use Default where with order by clause
    for example i want to use Default_where clause with order by clause
    Regards
    Shahzaib ismail

    Hi,
    I have a similar query for where clause.
    my query-find form is a multi record form like below:
    Criteria - Condition - Value
    Item/Category/Planner (List_Item) - Equals/Among (List_Item) - text_FIELD
    Item - Equals - ITEM_1
    Category - Among - ('CAT1', 'CAT2')
    Planner - Equals - PL1
    Find_BUTTON Clear_BUTTON
    User can select any criteria and condition combination and then enter the value in "Value" text field.
    My query is: how can I prepare a where clause based on user input since the user can enter any number of values/combinations? I guess I would have to use some looping to generate where clause.
    Thanks
    Imran

  • Order by clause with union

    Hi,
    I wanted to know if this is possible with order by clause and union. some how union messes up the ordering of the left part of the union statement.
    assume the data is as below in table tab1
    c1 c2
    4 1
    4 2
    5 1
    5 2
    7 1
    7 2
    8 3
    9 4
    the expected output must be for all c1 < 7 ordering must be on c1 and for all c1 > 7 ordering must be on c2.
    so the query i tried was
    select c1,c2 from tab1 where c1 <7 order by c1
    union
    select c1,c2 from tab1 where c1 >=7 order by c2
    it is giving the message 'Sql command not properly ended'.
    Suggestions are welcome

    SQL>
    SQL> With t As
      2  (
      3  Select 4 c1, 1 c2 From dual Union All
      4  Select 4 ,2       From dual Union All
      5  Select 5 ,1       From dual Union All
      6  Select 5 ,2       From dual Union All
      7  Select 7 ,1       From dual Union All
      8  Select 7 ,2       From dual Union All
      9  Select 8 ,3       From dual Union All
    10  Select 9 ,4       From dual
    11  ), t1 As (Select c1,c2 From t Where c1 <7 Order By c1)
    12  ,t2 As (select c1,c2 from t where c1 >=7 Order By c2)
    13  Select * From t1 Union All
    14  Select * From t2;
            C1         C2
             4          1
             4          2
             5          1
             5          2
             7          1
             7          2
             8          3
             9          4
    8 rows selected
    SQL> /*-- Union All
      2   select c1,c2 from t where c1 >=7
      3   Order By c1,c2;
      4  */
      5 
    with union clause order by must be placed in the end,,
    select c1 from dual union all
    select c2 from dual
    order by  c1

  • Decode in order by clause with desc

    I want to user order by clause with decode + desc order.
    somthing like
    ORDER BY DECODE ('SALE', e.sale, 'SALE DESC' ????)
    ????-> How to use desc order with decode
    Thanks in advance

    I thought smart people in this OTN community will understand that I am trying to order by the thisdate column that is timestamp datatype:). My apologize for not being that specific.
    The query I gave is a simple version of the stored procedure I am using. The point is I need to order by - depending on one of the parameters that is passed to the procedure. In simplest decode statements, its something like
    order by decode(p_in_var,'ABC','thisdate asc','DEF','thisdate desc',thisdate asc)
    Here p_in_var is varchar input parameter to the stored procedure.
    Please let me know if there is any more information needed.
    Thx!

  • Oracle query tuning : query with Order-by clause

    Hi
    I am having a query in my database :
    SELECT * FROM SAPR3.HRP1001 WHERE "MANDT" = 990
    ORDER BY
    "MANDT" , "OTYPE" , "OBJID" , "PLVAR" , "RSIGN" , "RELAT" , "ISTAT" , "PRIOX" , "BEGDA" , "ENDDA" ,"VARYF" , "SEQNR" ;
    Autotrace output is :
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4649 Card=171895 Byt
    es=22862035)
    1 0 SORT (ORDER BY) (Cost=4649 Card=171895 Bytes=22862035)
    2 1 TABLE ACCESS (FULL) OF 'HRP1001' (Cost=1170 Card=171895
    Bytes=22862035)
    Statistics
    0 recursive calls
    5 db block gets
    12157 consistent gets
    11543 physical reads
    0 redo size
    38253080 bytes sent via SQL*Net to client
    376841 bytes received via SQL*Net from client
    34201 SQL*Net roundtrips to/from client
    0 sorts (memory)
    1 sorts (disk)
    512992 rows processed
    Since it is a issue with order by , it seems a PGA memory issue. there is 12GB PGA available but only 3GB gets allocated. pga_aggregate target is set in the DB. There is a index created for al the columns on order by, but it is not getting used.
    pleas suggest me as I am running into major problems, i can post the output of any query u require from my side. Any help wil be highly apprciated.
    Rishi

    > The query was alwasy spilling over to the One-Parse execution . It can be seen thru ST04N ->resource consumption-> sql work area trace.
    >
    > An undocumented oracle parameter smmmax_size was set which allowed for more usage of physical memory by single process and there was no spillover to the TEMP tablespaces.
    >
    > Also the File read time was analysed from Unix level ( From SAP thru ST04 ->filesystem wait s-> Avg rd (ms) and Ang writes (ms) which showed that reading from the File was not happening well. )
    Hi Rishi,
    the provided execution statistics prove the opposite:
    >Statistics
    >...
    >0 sorts (memory)
    > 1 sorts (disk)
    >512992 rows processed
    This indeed was a single-pass sort, which means it had to use the temp tablespace for one pass of the sorting/grouping.
    Remember that Oracle distinguishes three kinds of sorts: 1. "in memory", 2. "single-pass" and 3. "multi-pass".
    Only the first one won't need to spill out data to the disks. The others do this by definition.
    BTW: the file read times in ST04 are aquired through Oracle V$ views and not directly from the OS - that can make a big difference sometimes.
    regards,
    Lars

  • Problem with order by clause

    Hai all,
    I have problem with order by clause,
    My query is
    "select number from table1 order by number asc "
    and the output is displaying as
    1
    10
    12
    13
    15
    17
    19
    2
    20
    21
    22
    But if we give order by it should display as below only right ?
    1
    2
    10
    12
    13
    15
    17
    19
    20
    21
    22 ........
    Please help me why it is not displaying like it. and how to make the statement to display like the second case. Thanks in advance.
    Regards,
    Uraja

    The column datatype that you are selecting is not of NUMBER datatype(might be char or varchar2) hence you are getting such result set.
    And for this purpose, it is recommended to set datatype of a column appropriately.
    For now you can add TO_NUMBER function to column in ORDER BY clause, only if it has data of number type.
    Edited by: Ora on 19 Nov, 2012 3:10 AM

  • Query with order by clause

    Hi,
    I found a query with order by clause in procedure which is taking long time.
    Stats are upto date.
    Total Rows :650000.
    It is ordered by primary key column.
    select * from table_name order by col1;
    col1 is a primary key.No of cpu's used is 4.
    can anyone suggest me a better solution to improve the performance of a query.
    Is it better to use parallel hint for above scenario.
    Any help really apprecaited.
    Thanks in advance.

    Hi,
    Thanks for ur immediate reply.
    It doesn't have where clause.
    below is the plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 619071987
    | Id  | Operation                   | Name                 | Rows  | Bytes | Cos
    |   0 | SELECT STATEMENT            |                      |   671K|   255M| 125
    |   1 |  TABLE ACCESS BY INDEX ROWID| FULL_ITEM_FACILITIES |   671K|   255M| 125
    |   2 |   INDEX FULL SCAN           | FIF_PK               |   671K|       |
    9 rows selected
    Executed in 0.094 secondsThanks in advance
    Edited by: unique on Jun 22, 2009 8:26 AM

  • Long run time with ORDER by clause

    Hi,
    I am having a query which is executing fine(in 2 mins) but when i am using order by clause in it, its taking around 13 mins.
    Can anyone suggest what could be th reason and how to execute the same query are get the ordered record?
    thanks.

    Sorry for not providing complet details.
    Database version id 10g.
    Below is the execution plan when using with order by clause.
    Execution Plan
    | Id  | Operation                              | Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT                       |                   |     1 |   118 |  1538 |
    |   1 |  FILTER                                |                   |       |       |       |
    |   2 |   HASH JOIN                            |                   | 16657 |  1089K|    56 |
    |   3 |    TABLE ACCESS FULL                   | FILETYP           |     6 |    60 |     3 |
    |   4 |    TABLE ACCESS FULL                   | FILETYPSOURCEID   | 16657 |   927K|    52 |
    |   5 |   NESTED LOOPS                         |                   |     1 |    35 |     3 |
    |   6 |    TABLE ACCESS BY INDEX ROWID         | FILEWAREHOUSE     |     1 |    25 |     2 |
    |   7 |     INDEX RANGE SCAN                   | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |   8 |    TABLE ACCESS BY INDEX ROWID         | EXTFILE           |     1 |    10 |     1 |
    |   9 |     INDEX UNIQUE SCAN                  | PK_EXTFILE        |     1 |       |     1 |
    |  10 |  SORT ORDER BY                         |                   |     1 |   118 |  1538 |
    |  11 |   NESTED LOOPS                         |                   |     1 |   118 |  1534 |
    |  12 |    NESTED LOOPS OUTER                  |                   |     1 |   100 |  1533 |
    |  13 |     NESTED LOOPS OUTER                 |                   |     1 |    96 |  1532 |
    |  14 |      NESTED LOOPS                      |                   |     1 |    88 |  1531 |
    |  15 |       HASH JOIN                        |                   |     5 |   360 |  1524 |
    |  16 |        TABLE ACCESS BY INDEX ROWID     | RTXN              |     1 |    22 |     1 |
    |  17 |         NESTED LOOPS                   |                   |   117 |  5148 |  1518 |
    |  18 |          VIEW                          | VW_SQ_1           | 20869 |   448K|  1441 |
    |  19 |           HASH GROUP BY                |                   | 20869 |   427K|  1441 |
    |  20 |            FILTER                      |                   |       |       |       |
    |  21 |             TABLE ACCESS BY INDEX ROWID| RTXNSTATHIST      | 20869 |   427K|  1304 |
    |  22 |              INDEX RANGE SCAN          | RTXNSTATHIST_DX2  | 20869 |       |    29 |
    |  23 |          INDEX RANGE SCAN              | PK_RTXN           |     1 |       |     1 |
    |  24 |           NESTED LOOPS                 |                   |     1 |    24 |     3 |
    |  25 |            TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE     |     1 |    14 |     2 |
    |  26 |             INDEX RANGE SCAN           | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |  27 |            TABLE ACCESS BY INDEX ROWID | EXTFILE           |     1 |    10 |     1 |
    |  28 |             INDEX UNIQUE SCAN          | PK_EXTFILE        |     1 |       |     1 |
    |  29 |        TABLE ACCESS FULL               | RTXNTYP           |     1 |    28 |     5 |
    |  30 |       TABLE ACCESS BY INDEX ROWID      | RTXNSTATHIST      |     1 |    16 |     2 |
    |  31 |        INDEX RANGE SCAN                | PK_RTXNSTATHIST   |     1 |       |     1 |
    |  32 |      TABLE ACCESS BY INDEX ROWID       | NTWKNODE          |     1 |     8 |     1 |
    |  33 |       INDEX UNIQUE SCAN                | PK_NTWKNODE       |     1 |       |     1 |
    |  34 |     INDEX UNIQUE SCAN                  | PK_ORG            |     1 |     4 |     1 |
    |  35 |    TABLE ACCESS BY INDEX ROWID         | ACCT              |     1 |    18 |     1 |
    |  36 |     INDEX UNIQUE SCAN                  | PK_ACCT           |     1 |       |     1 |
    Below is the execution plan when running without ORDER BY clause...
    Execution Plan
    | Id  | Operation                             | Name              | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT                      |                   |     1 |   135 |  1537 |
    |   1 |  FILTER                               |                   |       |       |       |
    |   2 |   HASH JOIN                           |                   | 16657 |  1089K|    56 |
    |   3 |    TABLE ACCESS FULL                  | FILETYP           |     6 |    60 |     3 |
    |   4 |    TABLE ACCESS FULL                  | FILETYPSOURCEID   | 16657 |   927K|    52 |
    |   5 |   NESTED LOOPS                        |                   |     1 |    35 |     3 |
    |   6 |    TABLE ACCESS BY INDEX ROWID        | FILEWAREHOUSE     |     1 |    25 |     2 |
    |   7 |     INDEX RANGE SCAN                  | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |   8 |    TABLE ACCESS BY INDEX ROWID        | EXTFILE           |     1 |    10 |     1 |
    |   9 |     INDEX UNIQUE SCAN                 | PK_EXTFILE        |     1 |       |     1 |
    |  10 |  NESTED LOOPS                         |                   |     1 |   135 |  1534 |
    |  11 |   NESTED LOOPS OUTER                  |                   |     1 |   117 |  1533 |
    |  12 |    NESTED LOOPS OUTER                 |                   |     1 |   113 |  1532 |
    |  13 |     NESTED LOOPS                      |                   |     1 |   105 |  1531 |
    |  14 |      HASH JOIN                        |                   |     5 |   445 |  1524 |
    |  15 |       TABLE ACCESS FULL               | RTXNTYP           |     1 |    28 |     5 |
    |  16 |       TABLE ACCESS BY INDEX ROWID     | RTXN              |     1 |    22 |     1 |
    |  17 |        NESTED LOOPS                   |                   |   117 |  7137 |  1518 |
    |  18 |         VIEW                          | VW_SQ_1           | 20869 |   794K|  1441 |
    |  19 |          HASH GROUP BY                |                   | 20869 |   427K|  1441 |
    |  20 |           FILTER                      |                   |       |       |       |
    |  21 |            TABLE ACCESS BY INDEX ROWID| RTXNSTATHIST      | 20869 |   427K|  1304 |
    |  22 |             INDEX RANGE SCAN          | RTXNSTATHIST_DX2  | 20869 |       |    29 |
    |  23 |         INDEX RANGE SCAN              | PK_RTXN           |     1 |       |     1 |
    |  24 |          NESTED LOOPS                 |                   |     1 |    24 |     3 |
    |  25 |           TABLE ACCESS BY INDEX ROWID | FILEWAREHOUSE     |     1 |    14 |     2 |
    |  26 |            INDEX RANGE SCAN           | FILEWAREHOUSE_DX2 |     1 |       |     2 |
    |  27 |           TABLE ACCESS BY INDEX ROWID | EXTFILE           |     1 |    10 |     1 |
    |  28 |            INDEX UNIQUE SCAN          | PK_EXTFILE        |     1 |       |     1 |
    |  29 |      TABLE ACCESS BY INDEX ROWID      | RTXNSTATHIST      |     1 |    16 |     2 |
    |  30 |       INDEX RANGE SCAN                | PK_RTXNSTATHIST   |     1 |       |     1 |
    |  31 |     TABLE ACCESS BY INDEX ROWID       | NTWKNODE          |     1 |     8 |     1 |
    |  32 |      INDEX UNIQUE SCAN                | PK_NTWKNODE       |     1 |       |     1 |
    |  33 |    INDEX UNIQUE SCAN                  | PK_ORG            |     1 |     4 |     1 |
    |  34 |   TABLE ACCESS BY INDEX ROWID         | ACCT              |     1 |    18 |     1 |
    |  35 |    INDEX UNIQUE SCAN                  | PK_ACCT           |     1 |       |     1 |
    -------------------------------------------------------------------------------------------Edited by: user10754555 on Feb 5, 2010 6:02 PM

  • Move non-partition to Partition with order by cluse

    Hi,
    I have non partition table of around 9GB and want to convert it into Partiiton table. Following is the des:
    SQL> select num_rows,blocks from dba_tables where table_name='DEMAND_DRAFT_STATUS';
      NUM_ROWS     BLOCKS
      21720123    1228647
    SQL> select index_name,index_type from dba_indexes where table_name='DEMAND_DRAFT_STATUS';
    INDEX_NAME                     INDEX_TYPE
    SYS_C0011138                   NORMAL
    IDX_DEMD_DRFT_STAT_INSERTED_BY BITMAP
    IDX_DEMD_DRFT_STAT_UPDATED_BY  BITMAP
    SQL> select clustering_factor from dba_indexes where index_name='SYS_C0011138';
    CLUSTERING_FACTOR
            387978241
    SQL> select column_name,column_position from dba_ind_columns where index_name='SYS_C0011138';
    COLUMN_NAME
    COLUMN_POSITION
    ISSU_BR_CODE
                  1
    ISSU_BANK_CODE
                  2
    ISSU_EXTN_CNTR_CODE
                  3
    COLUMN_NAME
    COLUMN_POSITION
    DD_NUM
                  4
    ISSUE_DATE
                  5
    DD_CRNCY_CODE
                  6
    COLUMN_NAME
    COLUMN_POSITION
    OT_TYPE
                  7
    PRODUCT_CODE
                  8
    CURRENCY_CODE
                  9
    9 rows selected.
    SQL> desc DEMAND_DRAFT_STATUS
    Name                                                                                                              Null?    Type
    ISSU_BR_CODE                                                                                                      NOT NULL VARCHAR2(6)
    ISSU_BANK_CODE                                                                                                    NOT NULL VARCHAR2(6)
    ISSU_EXTN_CNTR_CODE                                                                                               NOT NULL VARCHAR2(2)
    DD_NUM                                                                                                            NOT NULL VARCHAR2(16)
    ISSUE_DATE                                                                                                        NOT NULL DATE
    DD_CRNCY_CODE                                                                                                     NOT NULL VARCHAR2(3)
    OT_TYPE                                                                                                           NOT NULL VARCHAR2(2)
    PRODUCT_CODE                                                                                                      NOT NULL VARCHAR2(5)
    CURRENCY_CODE                                                                                                     NOT NULL VARCHAR2(3)
    DD_STATUS                                                                                                                  CHAR(1)
    DD_STATUS_DATE                                                                                                             DATE
    DD_AMT                                                                                                                     NUMBER(20,4)
    DD_REVAL_DATE                                                                                                              DATE
    PRNT_ADVC_FLG                                                                                                              CHAR(1)
    PRNT_RMKS                                                                                                                  VARCHAR2(50)
    PAYEE_BR_CODE                                                                                                              VARCHAR2(6)
    PAYEE_BANK_CODE                                                                                                            VARCHAR2(6)
    PAYING_BR_CODE                                                                                                             VARCHAR2(6)
    PAYING_BANK_CODE                                                                                                           VARCHAR2(6)
    ROUTING_BR_CODE                                                                                                            VARCHAR2(6)
    ROUTING_BANK_CODE                                                                                                          VARCHAR2(6)
    INSTRMNT_TYPE                                                                                                              VARCHAR2(6)
    INSTRMNT_ALPHA                                                                                                             VARCHAR2(6)
    INSTRMNT_NUM                                                                                                               VARCHAR2(16)
    PUR_NAME                                                                                                                   VARCHAR2(80)
    PAYEE_NAME                                                                                                                 VARCHAR2(80)
    PRNT_OPTN                                                                                                                  CHAR(1)
    PRNT_FLG                                                                                                                   CHAR(1)
    PRNT_CNT                                                                                                                   NUMBER(3)
    DUP_ISS_CNT                                                                                                                NUMBER(3)
    DUP_ISS_DATE                                                                                                               DATE
    RECTIFED_CNT                                                                                                               NUMBER(3)
    PAID_EX_ADVC                                                                                                               CHAR(1)
    ADVC_RCV_DATE                                                                                                              DATE
    BC_FLG                                                                                                                     CHAR(1)
    ENTERED_BY                                                                                                                 CHAR(1)
    CAUTIONED_STAT                                                                                                             CHAR(1)
    CAUTIONED_REASON                                                                                                           VARCHAR2(50)
    PAID_ADVC_FLG                                                                                                              CHAR(1)
    INVT_SRL_NUM                                                                                                               VARCHAR2(16)
    PRNT_REM_CNT                                                                                                               NUMBER(2)
    INSERTED_BY                                                                                                                NUMBER(10)
    UPDATED_BY                                                                                                                 NUMBER(10)
    INSERTED_ON                                                                                                                DATE
    UPDATED_ON                                                                                                                 DATE
    DEL_FLG                                                                                                                    CHAR(1)
    LCHG_TIME                                                                                                                  DATE
    RCRE_TIME                                                                                                                  DATE
    BUSINESS_DATE                                                                                                              DATEFollowing questions:
    1) I want to Range partition by ISSUE_DATE (there is no issue), but i'm thinking of reordering the column of index i.e 'SYS_C0011138' (which is also primary key). For example low cardinality columns i will place first and high selective column i would place at last in order. Is that a good idea?
    2) While creating Partition table i want to give insert /*+ parallel 10 */ into partitiontable select * from DEMAND_DRAFT_STATUS order by CURRENCY_CODE,DD_CRNCY_CODE,PRODUCT_CODE,OT_TYPE,ISSU_BANK_CODE,ISSU_EXTN_CNTR_CODE,ISSUE_DATE,ISSU_BR_CODE,DD_NUM;
    Why i'm doing this because index is going to be created on CURRENCY_CODE,DD_CRNCY_CODE,PRODUCT_CODE,OT_TYPE,ISSU_BANK_CODE,ISSU_EXTN_CNTR_CODE,ISSUE_DATE,ISSU_BR_CODE,DD_NUM columns so clustering factore os that index would be good(this is primary key index btw). Is it good?
    3) Once partition is done i want to compress the old partitions, but i'm bit worried that i wont get enough compress ratio if i create partition table with ORDER by clause. whats your thought?
    Please give recommendation
    Regards

    rp0428 wrote:
    >
    whats your thought?
    >
    Your post raises nothing but questions about WHY you are doing any of this. We can't suggest appropriate solutions without knowing what the problems are or what goals you are trying to achieve.
    >
    I have non partition table of around 9GB and want to convert it into Partiiton table
    >
    Ok - but WHY? Are you currently having problems? What are they? Is performance poor? For what type of queries or operations? Is management a problem - can't easily roll-off old data?
    >Well its management decision to partitions the table which are expected to have high size in future. There reference of 6GB i gave only for explanation, actually we have 2-3 tables which are 500+GB and will grow.
    Its a DWH environment where daily incremental load happens. So we came out of decision to have tables(which have daily incremental load) partitioned on monthly basis. And keep last quatat partitions on Cell Flash cache(its exadata)
    CLUSTERING_FACTOR
    387978241
    >
    Yep - that is a high factor for 1.2 million blocks. But are you sure it is correct? It's 17 times greater than the number of rows in the table. That suggests that to read the entire table using the index every block has to be read 17 times. That doesn't make sense - odds are the table and index stats you provided are not current.
    Yes thats seems to be correct figure. I'll check once again and post..
    >
    And it has this quote from Tom Kyte's book Expert Oracle Database Architecture
    >
    we could also view the clustering factor as a number that represents the number of logical i/o’s against the table, that would be performed to read the entire table via the index.
    >
    Even assuming that index has a high clustering factor the next question is:
    So what? That would only be relevant if you are using that index to access the entire table or large numbers of blocks.
    Is there a problem you are having that you can identify the clustering factor as the main culprit?
    If it ain't broke, don't fix it.
    >Yes that correct but clustering factor worry me much after seeing its value which is very high as compared to # of blocks.
    1) I want to Range partition by ISSUE_DATE (there is no issue), but i'm thinking of reordering the column of index i.e 'SYS_C0011138' (which is also primary key). For example low cardinality columns i will place first and high selective column i would place at last in order. Is that a good idea?
    >
    Range partitioning by a date can be useful so lets just assume it is in your case; maybe you are thinking about dropping old data. Is your primary key going to be global or local? That will affect performance if you drop old partitions; the global index has to be maintained but the local one doesn't.
    I'm not going to drop any partitions of old data as of now but will compress them because they wont anticipate DMLS.(but might be select)
    Now the question is about Primary key > wll it be Local of Global? Well i thought of having this Key as Local(because one of my primary key column will contain the partition key as well).
    Reasons
    1) better manageability( like if i want to compress old partitions, then having a gloabl parimary key index would become unusable state)
    2) Might increase in select search criteria (assumption)
    But having this as local will it impact any performance?
    The primary key does include the partitioning column so it could be a local index. But the partitioning column is not the leading column so this would be a local nonprefixed index. Is that what you need or do you need prefixed index?
    Have you researched the difference and determined which one you need for your use case?
    No. My partition Key would not be in leading column of Primary key. But is there any difference if i not keep partition key as leading column of primary key?
    See Local Partitioned Indexes in the VLDB and Partitioning Guide
    http://docs.oracle.com/cd/B28359_01/server.111/b32024/partition.htm
    Is rearranging the key columns a good idea? Hard to say without knowing your usage pattern.
    Why are you reordering the primary key columns? Why are you putting low cardinality columns first?Well i have read some where quite lot times that having Low cardinality columns as leading coluns would increase performance and later we can get better compression ratios. Let me know if i'm wrong.
    You shouldn't be doing either of these without a solid reason. What are the reasons? How do you know that, for your usage pattern, you won't make things worse?
    >
    2) While creating Partition table i want to give insert /*+ parallel 10 */ into partitiontable select * from DEMAND_DRAFT_STATUS order by CURRENCY_CODE,DD_CRNCY_CODE,PRODUCT_CODE,OT_TYPE,ISSU_BANK_CODE,ISSU_EXTN_CNTR_CODE,ISSUE_DATE,ISSU_BR_CODE,DD_NUM;
    Why i'm doing this because index is going to be created on CURRENCY_CODE,DD_CRNCY_CODE,PRODUCT_CODE,OT_TYPE,ISSU_BANK_CODE,ISSU_EXTN_CNTR_CODE,ISSUE_DATE,ISSU_BR_CODE,DD_NUM columns so clustering factore os that index would be good(this is primary key index btw). Is it good?
    >
    That should give a good initial clustering factor for the index unless a lot of DML is done.
    >
    3) Once partition is done i want to compress the old partitions, but i'm bit worried that i wont get enough compress ratio if i create partition table with ORDER by clause. whats your thought?
    >
    You are probably correct since having the low cardinality data first will break things up more. But you are still trying to solve a problem that you don't know even exists. How much space will each partition take if uncompressed? How much if compressed?
    At a minimum you should perform a tests for a realistic subset of data (a sample issue date).
    1. Create an unordered uncompressed table (new tablespace to make size data more accurate).
    2. Create an unordered compressed table
    3. Create an ordered uncompressed table
    4. Create an ordered compressed table
    Yes i have tries to simulate this for 9GB table(only) and size of unordered compressed table is 1.2GB and size of ordered compressed table is 1.9GB out of 9B(uncompressed)
    Then you will have a good idea what the space savings might be.
    I suggest you first document the issues and problems you are having and list specific goals for any architecture changes.
    For partiioning I would focus on identifying the goals, the partition key(s), and the numbers and types (global or local) for the primary key and other indexes.
    Application team have already identified the Partitions key on tables which are supposed to be partitioned And they say most of the queries are on those date columns. Secondly as i explained having partition we will keep old partition in compressed state and new partitions in Cell flash cache.
    For the primary key index (that includes the partitioning key) determine if you need a prefixed or nonprefixed index.
    again whats the difference if i dont have partition key column in leading column of index?
    Based on your usage patterns determine the indexes and columns that are the most important for querying. The clustering factor might be ideal for the primary key but totally screwed up for the indexes and queries that really count. You can't get an ideal clustering factor for every index.
    The data order for the initial load can be in the order that gives you the best clustering factor for the main index you need it for. That assumes that you actually need the index for a purpose that the clustering factor can help with.Thanks a lot your explanation was helpful.
    This setup for tables (i.e. having high # of columns in primary key for example 6-7 out of 15 columns approx in a table) is common for mostly all of the tables which are going to be partition.
    And most of the columns in parimary key have 2-3 distinct values out of 1Million rows, so was about to think that i should put them ahead while creating a new primary key (Local) on newly created partition.
    While doing this i also take into consideration that i load the data in ORDER BY clause (i.e. order by all columns of PK) to get excellent CF and moreover we could benefit from Storage Index on Exadata. and thanks for inputs too highly appreciated

  • Problem in Outbound delivery with order reference

    Hi,
    I am facing problem with creation of outbound delivery with order reference from transaction VL01N. When i enter into the transaction with order key in, but in the tab Picking there is one column Pick quantity which is showing as grey field with zero value(Grey field don't allow to change the quantity). This Pick quantity is always allow to put us required quantity but i come across this kind of scenario very first time. Can you please help.
    Thank you.

    Hi,
    Your combination of Plant+Storage location is enabled for warehouse management. So directly putting the picking value is not possible. You have two options now.
    1. If you know howto put pickign through transfer orders, do it through LT03 and confirm teh TO for picking quantity to be updated in delivery. You have to find out teh stock in the source bin and use it in transfer order. You may get in touch with WM consultant, if you dont know how to do it.
    2. If you are ok with just doing picking without WM, then you can change the storage location in delivery and then try picking in delivery itself. The storage location should not be enabled for WM for the plant.

  • For update with order by

    Hello all,
    Does anyone know if "order by" has precedence over "for update"? In other words, using the following query. Will the resulting rows be sorted first and then locked or they will be locked first and then sorted?
    SELECT /*+ cardinality(al 1) use_nl(al t) */ NULL
    BULK COLLECT INTO l_nullvalue_list
    FROM TABLE (i_list) al, my_table t
    WHERE al.id = t.id
    ORDER BY t.id
    FOR UPDATE OF t.id;
    Any help is very much appreciated.
    Regards,
    wf

    This is the case I'm talking about:
    drop table t cascade constraints purge;
    create table t as select rownum id, cast('x' as char(100)) pad
                        from dual connect by level <= 10000;
    drop table t1 cascade constraints purge;
    create table t1(id int);
    -- 1st session
    SQL> lock table t1 in exclusive mode;
    Table(s) locked
    -- 2nd session
    declare
        type t1_type is table of rowid index by binary_integer;
        l_tab t1_type;
    begin
        execute immediate 'lock table t1 in share mode';
        select rowid bulk collect into l_tab
          from t order by dbms_random.value
           for update;
    end;
    -- 3rd session
    declare
        type t1_type is table of rowid index by binary_integer;
        l_tab t1_type;
    begin
        execute immediate 'lock table t1 in share mode';
        select rowid bulk collect into l_tab
          from t order by dbms_random.value
           for update;
    end;
    /Now 2nd & 3rd sessions are blocked by 1st. Let's release that lock:
    -- 1st session
    SQL> commit;
    Commit complete2nd & 3rd sessions are trying to lock rows of table T, and one of sessions fails with deadlock:
    declare
        type t1_type is table of rowid index by binary_integer;
        l_tab t1_type;
    begin
        execute immediate 'lock table t1 in share mode';
        select rowid bulk collect into l_tab
          from t order by dbms_random.value
           for update;
    end;
    ORA-00060: deadlock detected while waiting for resource
    ORA-06512: at line 7If you repeat the same scenario with ORDER BY id, then one session will be waiting for enqueue.
    So, it's all about order in which row locks are acquired.

  • How can i get the maximum salary first in the order of ascending

    Hi,
    How can i get the maximum salary first in the order of ascending.
    I need the sql query.
    my output should like:
    Emp_Name Salary
    A 5000
    SS 100
    AA 300
    DD 700
    WW 2000
    Thanks,
    MuthyaM.

    Here is an example :
    SQL> with mytable as
      2  ( select 'aa' as col1,  300 col2 from dual union all
      3    select 'ss' as col1,  100 col2 from dual union all
      4    select 'a'  as col1, 5000 col2 from dual union all
      5    select 'dd' as col1,  700 col2 from dual union all
      6    select 'ww' as col1, 2000 col2 from dual )
      7  select col1, col2
      8  from   mytable
      9  order by decode(row_number() over (order by col2 desc),1,0,1),col2;
    CO       COL2
    a        5000
    ss        100
    aa        300
    dd        700
    ww       2000
    SQL>Nicolas.

  • Prepared Statement with ORDER BY

    I am trying to use order by with prepared statement but it is not ordering.
    String sql = "SELECT * FROM MATERIAL WHERE (LOWER(NAMEE) LIKE ('%' || ? || '%') ORDER BY ? ";
    PreparedStatement ps=CM.getStatement(sql);
    ps.setString(1,p);
    ps.setString(2,sort);
              ResultSet r = ps.executeQuery();
    Can any one tell me how do I use prepared statement with order by

    You can not parameterize column names and such, only literals. You should build the ORDER BY clause dynamically.

  • SQL IN clause with a Tool variable

     

    We are using using Forte 3.M.2 (just upgraded from 3.G, finally).
    Platform is AIX 4.3. Database is DB2 (UDB) (version 5.2 i think).
    True, I haven't tried my code on any other platform. I think it should work on NT, because one of our other teams members has set up an NT laptop for portable demos. And it has DB2 (NT version i guess) loaded on it.
    Dynamic sql is not really that bad, if you have to go that route to build your list.
    Let me know how it goes.
    Steven Barnes
    Daniel Gonz&aacute;lez de Lucas <danieleam.es> 07/28/00 04:06AM >>>We are getinng some trouble, the DB Manager seems to try to convert
    :OfficeList to a unique integer lets say:
    :OfficeList value is 3,4,7
    so the IN clause
    trying with Oracle 8.1.5 converts 3,4,7 in a unique integer (a extrange
    value because doesn't match with 3,4 nor 7).
    trying with SQL Server 6.5 gives an error converting 3,4,7 to a unique
    tinyint.
    The idea is that with your sintax the DB Manager must split the TextData
    into 3 integer values. I think that it works fine in some DB Managers and
    not in others.
    Which release and vendor of DB Manager you use?
    Which Fort&eacute; release?
    Thank you very much in advance.
    Daniel.
    ----- Original Message -----
    From: "Steve Barnes" <DHS9126dhs.state.il.us>
    To: <danieleam.es>; <kamranaminyahoo.com>
    Sent: Thursday, July 27, 2000 1:55 PM
    Subject: Re: (forte-users) SQL IN clause with a Tool variable
    I needed to have an "IN" clause for some numbers. Here's how I did it:
    GetOffices():TextData method...
    Offices : TextData = new ;
    for (x : integer) in sql select MyIntegerColumn
    from MY_TABLE
    where whatever condition
    on session MyDBSession do
    Offices.Concat(x) ;
    Offices.Concat(',') ;
    end for ;
    return (Offices.CopyRange(0,Offices.ActualSize -1)) ; // get rid of lastcomma
    in actual sql.....
    OfficeList : TextData ;
    OfficeList = GetOffices() ;
    sql select * from MyTable where MyField in (:OfficeList)
    on session MyDBSession ;
    Works very well.
    Steven Barnes
    Daniel Gonz&aacute;lez de Lucas <danieleam.es> 07/27/00 05:32AM >>>Hello,
    To do a select we have two options:
    select * from MyTable
    where MyField in ('a','b','c')
    we would like to do the same but using a fort&eacute; variable in the IN clause.
    select * from MyTable
    where MyField in (:ToolVar)
    What should we do and what kind of variable or array of variables shouldwe use in ToolVar to do the same than in first option?
    >
    Has anybody done this without a dynamic query?
    Best regards
    Daniel
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com

Maybe you are looking for

  • Report on payments

    frnds i need to generate a report on payments with following details. Vendor no and name, Invoice no and amount, check#, and clerk name and PO # I tried to use table PAYR but i didnt get the information about invoice no and Clerk with PO#... is there

  • Using an existing connection in the Excel 2013 file in Power Query

    Hi, I've created an Excel workbook and a SQL Server data connection in this workbook. When I open Power Query I cannot to use this created data connection. In general, inside Power Query can I use a data connection created in the original Excel workb

  • Just tried to load cnet antivirus software, now computer comes up as a blue screen, no programs. Help

    just tried to load cnet antivirus software, now computer comes up as a blue screen, no programs. Help

  • Have a problem with JCWDE

    Hello, I am having some trouble when I try to run the JCWDE command. The actual command I issue is:- JCWDE JCWDE.app But I just get the following error:- Exception in thread "main" java.lang.NoClassDefFound: com/sun/javacard/jcwde/main I don't know w

  • Asset master fields display

    Dear All, In asste master im not able to change the cost center,plant , besiness area and location because of it showing a display mode. I checked in screen layout rule for asset it is "optional" mode. Any one have idea please revert. Regards