Condition in the order by clause?

Hello

my version of db is,
     Oracle9i Enterprise Edition Release 9.2.0.8.0 - Production 
    
Im having a query like this,
    select a,b,c,d,sum(e) from f group by a,b,c,d order by a,b,c,d
    
Now if the value of one is 1 I want the result of the following query
    select a,b,c,d,sum(e) from f group by a,b,c,d order by b,a,c,d
    
The only change between the two queries above are sorted by the clause.

How to get there?

Good help will be appreciated.

Concerning
Sankar MN

Published by: SankarMCA on October 5, 2010 04:51

Hello

You can use CASE expressions in the ORDER BY clause.
For example:

ORDER BY  CASE
              WHEN  a  = 1  THEN  b
                          ELSE  c
          END
,         CASE
              WHEN  a = 1  THEN  c
                          ELSE  b
          END
,         d

Tags: Database

Similar Questions

  • How to remove the Order By clause

    How can I get rid of the Order By clause in the underlying SQL query? I created a simple hierarchy, but when I use the hierarchy in the analysis and then come down, the results show multiple occurrences of each child. For some reason, I was able to reduce the number of occurrences of each child by adding a saved filter.

    I was expecting this:

    Expected.jpg

    Instead, I got this:

    Actual.jpg

    The generated physical query looks like this:

    SET VARIABLE QUERY_SRC_CD = "report"; SELECT s_0, s_1, s_2, s_3, s_4 s_5, (FROM s_6)

    SELECT

    s_0 0,.

    CAST (NULL AS VARCHAR s_1 (1)).

    "Registration - College". «Dimensions of the inscription '.» "' Exercise ' s_2,.

    'All the colleges' s_3,.

    IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". ("' S_4 all Colleges").

    MOUNT s_5 (NULL AS DOUBLE),

    "Registration - College". "" Counties of schooling. "" Full-time student "s_6

    "REGISTRATION - College".

    UNION ALL

    SELECT

    1 s_0

    "Registration - College". «Dimensions of the inscription '.» "" Name of College "s_1,.

    "Registration - College". «Dimensions of the inscription '.» "' Exercise ' s_2,.

    'All the colleges' s_3,.

    IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". ("' S_4 all Colleges").

    IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". ("' S_5 College ').

    "Registration - College". "" Counties of schooling. "" Full-time student "s_6

    "REGISTRATION - College".

    WHERE

    ("Registration - College". «Dimensions of the inscription '.» ("' Exercise ' IN ('201213')) AND (IDOF ("registration - College". «Hierarchies of the inscription '.» "College". ". (("' Colleges ') (1))

    ) djm ORDER OF 1, 3 ASC NULLS LAST, 4 ASC NULLS FIRST, 5 ASC NULLS FIRST, 2 ASC NULLS FIRST, NULLS FIRST CSA 6

    EXTRACT FIRST 10000000 LINES ONLY

    HI mbengue,.

    Check the report you are running any column presentation sorted in the user interface (in which case the order by clause will creep into generated sqls Physics). Also, I think that its worth it to check the settings of the hierarchy you have configured and if the installation program for the calculation of the measured column (number of students in this case), has been done correctly.

    Kind regards

    Arko

  • How does the order by clause in oracle 10G?

    Hi This is my table called Master.I want to order by sno. so I run the below mentioned query.

    SNO DESC STIME, ETIME CCODE ADD SID

    11 11 11 1 10 s11

    1 1 s1 09:00 12:00 10

    2 2 s2 06:00 07:00 9

    3        3      S3        9:00       23:00                         0

    SELECT * FROM MASTER BY SNO

    SNO DESC STIME, ETIME CCODE ADD SID

    1 1 s1 09:00 12:00 10

    11      11         s11        11             1              10

    2         2         s2           6:00        7:00           9

    3         3         S3           09:00     23:00                        0

    but I had bad results. Help kindly me.i can't understand how the order by clause is fetching the record.

    Hello

    Most probably because that SNO is not digital, but a tank.

    If it contains a number onlly, try

    SELECT * FROM MASTER BY TO_NUMBER (SNO);

  • Purpose of the ORDER BY clause in the analytic function Min Max

    I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.

    user10566312 wrote:
    I was always using analytical functions like Min Max without ORDER BY clause. But today I used with the ORDER BY clause. The results are very different. I would like to know the purpose of the ORDER BY clause in Min, Max and analogues of analytical functions.

    It is a good point that many developers are not so aware. As far as I understand it the way it works.

    Some analytical functions do not need an order by or windowing clause (SUM, COUNT, MIN, etc.). If there is no specified window, then the full score is the window.
    As soon as you add a command also add you a windowing clause. This window has the default value of 'rank ofrows between unbounded preceding and current_row. So as soon as you add an order by clause, you get a sliding window.

    Documentation: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions001.htm

    windowing_clause
    ...
    You cannot specify this clause unless you specified the order_by_clause. Window limits defined by the clause RANGE you can not specify only a single expression to the > order_by_clause. Please refer to 'Restrictions on the ORDER BY Clause'.

    example of

    with testdata as (select 10 numval, level lv from dual connect by level < 10)
    select lv, numval, sum(numval) over () sum1, sum(numval) over (order by lv) sum2
    from testdata;
    
    LV NUMVAL SUM1 SUM2
    -- ------ ---- ----
     1     10   90   10
     2     10   90   20
     3     10   90   30
     4     10   90   40
     5     10   90   50
     6     10   90   60
     7     10   90   70
     8     10   90   80
     9     10   90   90 
    

    Published by: Sven w. on 25 Sep 2012 16:57 - default behavior has been corrected. Thanks to Chris

  • Evaluate the Expression in the order by Clause

    Hello

    I'm struggling to run after JPQL.

    Select r.firstname, r.lastname, (e.distance/e.duration) from Runner r Inner Join r.event e Order BY (e.distance/e.duration) Desc;

    Error suggests that ' (' character is unacceptable in the Order By Clause.) Here is the error.

    javax.servlet.ServletException: java.lang.IllegalArgumentException: an exception occurred while creating a query in EntityManager:
    Description of the exception: syntax error parsing the query [Select r.firstname, r.lastname, (e.distance/e.duration) of Runner r Inner Join r.event e Order BY Desc (e.distance/e.duration);], line 1, column 101: unexpected token [()].
    Inner exception: NoViableAltException (81! = [1328:1: orderByItem returns [object node]: (n = stateFieldPathExpression (a = ASC | DESC = d |) | I = IDENT (a CSA = | d = DESC |)) ;])])

    Can someone show me please how to fix it.

    Thank you
    Adam

    What version do you use? It should work in EclipseLink > 2.1.

    ---
    James: http://www.eclipselink.org

  • What's the point of having several columns in the ORDER BY clause?

    DB version: 10 gr 2

    When you use the ORDER BY clause, the lines are always sorted by the first column in the ORDER BY clause. So, what's the point of having several columns in the ORDER BY clause (I always see this in production codes)?

    For the below SQLs' schema SCOTT, result sets are always classified according to the first column ename. When I added use asc and desc of employment, does not change the result set.
    SQL> select * from emp order by ename;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.
    
    SQL> select * from emp order by ename, job;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.
    
    SQL>  select * from emp order by ename, job desc;
    
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       2450                    20
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7839 KING       PRESIDENT            17-NOV-81       5000                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7934 MILLER     CLERK           7782 23-JAN-82       1300                    20
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7369 SMITH      CLERK           7902 17-DEC-80        800                    20
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
    
    14 rows selected.

    Search in this example, you will see the difference

    SQL> create table test_order (name varchar2(10), surname varchar2(10), age number);
    
    Table created.
    
    SQL> insert into test_order values('Kamran','Agayev',26);
    
    1 row created.
    
    SQL> insert into test_order values('Kamran','Taghiyev',26);
    
    1 row created.
    
    SQL> insert into test_order values('John','Kevin',23);
    
    1 row created.
    
    SQL> select * from test_order;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    Kamran     Agayev             26
    Kamran     Taghiyev           26
    John       Kevin              23
    
    SQL> select * from test_order
      2  order by age;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    John       Kevin              23
    Kamran     Agayev             26
    Kamran     Taghiyev           26
    
    SQL> select * from test_order
      2  order by age asc, surname desc;
    
    NAME       SURNAME           AGE
    ---------- ---------- ----------
    John       Kevin              23
    Kamran     Taghiyev           26
    Kamran     Agayev             26
    
    SQL>
    

    When in the second query, I sorted out only for age, you saw it there two 26 years old Keita, there was first Agayev, then Taghiyev. But if I want to get the family names in descending order when there are two very old person, then I will add the second column in the order by clause

    - - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev a. (10g OCP)
    http://kamranagayev.WordPress.com

  • process of execution of the order by clause

    What is the process of execution of the order clause in the sql statement and how it will affect the performance of the query.

    Siddharth Singh says:
    What is the process of execution of the order clause in the sql statement

    Depends on. First of all, that you mean "alrogithmically, how Oracle data products ordered"? There are a number of different approaches. Data can be ordered as you pick up sequentially from an index. Or it can be explicitly materialized and sorted.

    and how it will affect the performance of the query.

    Depends on. There could be no impact because it relies on the index to classify the data and index is the most effective path independently of the presence of an ORDER BY. Or it could require a huge amount of time to materialize and sort several GB of data.

    Justin

  • Problem in the SQL because of the order by clause

    Hi all
    I am facing a problem in a sql query. I use Oracle 10 g 2.
    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.SEQ
    The query Plan 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 request.

    If I remove order by clause query that the query performance is quite perfect, but with order by clause its take time.

    I already set SORT_AREA_SIZE, but still nothing improves.

    Welcome and thank you for your suggestions.

    Thank you

    Published by: BluShadow on June 23, 2011 07:55
    addition of {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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

    Hey, a quick test, try:

    select ename from (
    SELECT t1.ename, T2.SEQ
    FROM T1, T2
    WHERE T1.EMPNO = 1234
    AND T1.ACCOUNTNO = T2.ACCOUNTNO
    AND T1.SEQ = T2.SEQ
    and rownum > 0)
    ORDER BY SEQ
    

    Amiel Davis

  • WITH the ORDER BY clause and bug SDO_GEOMETRY?

    I'm having a problem using SDO_GEOMETRY in a WITH clause. Specifically with ORDER BY. I'll show a shortened version of SQL here. I'm doing something wrong or is this a bug?

    It works:
                         SELECT 
            loc.location_id,
                        SDO_GEOM.SDO_DISTANCE(cent.lat_long, 
                        MDSYS.SDO_GEOMETRY
                        (
                        2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2.
                        '4326', 
                        SDO_POINT_TYPE(-78.6386145, 35.772096, NULL),
                        NULL,
                        NULL
                        ),
                       0.01, -- tolerance
                        'unit=mile') result_center_distance
                        
              
                         FROM location loc
                         JOIN centroid cent ON loc.centroid_id = cent.centroid_id
             ORDER BY result_center_distance
    After the statement select in a with clause, this does not work, which gives an identifier not valid "SDO_GEOMETRY" ORA-00904:
    WITH location_distance AS
    (
                         SELECT 
            loc.location_id,
                        SDO_GEOM.SDO_DISTANCE(cent.lat_long, 
                        MDSYS.SDO_GEOMETRY
                        (
                        2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2.
                        '4326', 
                        SDO_POINT_TYPE(-78.6386145, 35.772096, NULL),
                        NULL,
                        NULL
                        ),
                       0.01, -- tolerance
                        'unit=mile') result_center_distance                    
              
                         FROM location loc
                         JOIN centroid cent ON loc.centroid_id = cent.centroid_id
             ORDER BY result_center_distance
      ) SELECT * from location_distance
    If I duplicate the function of the distance in the ORDER BY, it works:
    WITH location_distance AS
    (
                         SELECT 
            loc.location_id,
                        SDO_GEOM.SDO_DISTANCE(cent.lat_long, 
                        MDSYS.SDO_GEOMETRY
                        (
                        2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2.
                        '4326', 
                        SDO_POINT_TYPE(-78.6386145, 35.772096, NULL),
                        NULL,
                        NULL
                        ),
                       0.01, -- tolerance
                        'unit=mile') result_center_distance                    
              
                         FROM location loc
                         JOIN centroid cent ON loc.centroid_id = cent.centroid_id
             ORDER BY                     SDO_GEOM.SDO_DISTANCE(cent.lat_long, 
                MDSYS.SDO_GEOMETRY
                (
                2001, -- SDO_GTYPE attribute: 2 in 2001 specifies dimensionality is 2.
                '4326', 
                SDO_POINT_TYPE(-78.6386145, 35.772096, NULL),
                NULL,
                NULL
                ),
                  0.01, -- tolerance
                'unit=mile')
      ) SELECT * from location_distance

    This is a bug. But it is set to 11g R2. Note that this is not a space bug, but a bug in generic compilation.

  • passing parameters in the order by clause of the cursor

    Hi friends,
    I am facing a strange problem

    I have a cursor with an order by clause.

    OPEN FOR Cursor_nomrpt
    SELECT DISTINCT
    CAST (plano.desc3 AS VARCHAR2 (50)) category
    plano.name plan_name
    , chip nvl (CAST (plano.desc6 AS VARCHAR2 (50)), 'not applicable')
    , nvl (trunc(plano.value18,2), 0) nominal_slm
    , nvl (trunc(plano.value19,2), 0) blm
    plano.dbdateeffectivefrom date_live
    ,
    Plano.DBKEY pog_id
    , case when plano.value47 < 0 THEN 0 when plano.value47 IS NULL THEN 0 ELSE plano.value47 END as parent_id
    Of
    Plano dplapro1.ix_spc_planogram
    INNER JOIN dplapro1.ix_spc_performance ON plano.dbkey = perf.dbparentplanogramkey perf
    Produces INNER JOIN dplapro1.ix_spc_product ON perf.dbparentproductkey = product.dbkey
    INNER JOIN dplapro1.ix_spc_product_key ON product.dbkey2 = prodkey.dbkey prodkey
    AND prodkey.keylevel = 2
    WHERE
    Plano.value50 = 0
    AND plano.dbkey4 = p_subcatkey
    ORDER BY ltrim (rtrim (p_orderby)) CSA;

    p_orderby is the parameter that is passed. But the result is not sorted. But when I run the cursor to hardcode the value of parameter, that it works fine...

    Need your help on this

    Hello

    When you use a local variable in a cursor, it's as if you had hard-coded literal in its place, you cannot use a variable to a column name.

    If you know all the possible values for p_orderby, you can do something like this:

    ...
    ORDER BY  TRIM ( CASE  p_orderby
                   WHEN  'DESC'     THEN  plano.desc
                   WHEN  'VALUE'     THEN  plano.value
                   ...
               END
                ) ASC;
    

    If you don't know not all possible values, you can use dynamic SQL statements.

    By the way

    TRIM (x)
    

    Returns the same results as

    LTRIM ( RTRIM (x))
    
  • Error because the ORDER BY clause

    Hi gurus
    I have this formula for a formula column

    function CF_PREVIOUS_QUANTITY returns the number is
    quantity number;
    Start
    SELECT QUANTITY_REMAINING IN the amount
    Of
    (
    SELECT
    QUANTITY_REMAINING
    Of...
    WHERE THE...
    -ORDER BY trx_date DESC
    )
    WHERE rownum = 1;
    return quantity;
    end;

    Copy the following code compiles only if COMMAND LINE is commented out, otherwise I get this:
    Met the ORDER symbol when waiting for him...

    The code compiles ok in SQLDeveloper. I want to just get the first record in a recordset.
    What's not here?

    I use 6-speed

    Thanks in advance
    Oscar

    A problem of M - to-1.

    try either:

    ... (- preferred)
    for (SELECT in c
    QUANTITY_REMAINING
    Of...
    WHERE THE...
    ORDER BY trx_date DESC) loop
    Return c.QUANTITY_REMAINING;
    end loop;

    ... (- awkwardly)
    SELECT QUANTITY_REMAINING IN the amount
    Of
    (SELECT QUANTITY_REMAINING
    (
    SELECT
    QUANTITY_REMAINING
    Of...
    WHERE THE...
    ORDER BY trx_date DESC
    )
    WHERE rownum = 1
    );

  • How to use the order by clause

    Hi Al
    order_tracker1 is a tabular_block that I use this to search I want to order by when I search by serch_value
    Please guide


    The code given is used to find
    declare
    l_where varchar2 (4000);
    Start

    If: search_type = "ALL" then
    l_where: = ' id | party_name | COMMENT1 | del_date like "%' | : serch_value | » %''' ;
    on the other
    l_where: =: search_type |' as "%' | : serch_value | » %''';
    end if;

    set_block_property ('order_tracker1', default_WHERE, l_where);
    go_block ('order_tracker1');
    execute_query;
    end;


    Thanks and greetings
    Vikas Singhal

    Hai,

    Change the line set_block_property ('order_tracker1', default_WHERE, l_where); TO

    set_block_property ('order_tracker1', default_WHERE, l_where |) "order by serch_value");

    or in time design, you can give in the palette of the ORDER BY Clauesproperty.

    or you can write to set_block_property (ORDER_BY, 'order_tracker1', 'serch_value');

    Kind regards

    Manu.

    If this answer is useful or appropriate, please mark. Thank you.

  • the order by clause

    That's what I'm trying to someone can help me with that: -.

    create table test (env varchar (05), dbname varchar (08), priority varchar (05))

    Insert into test values ('prod', 'proddb1', 'C');
    Insert into test values ('train', 'traindb1', 'C');
    Insert into test values ('train', 'traindb1', 'H');
    Insert into test values ('prod', 'proddb1', 'W');
    Insert into test values ('test', 'testdb1', 'C');
    Insert into test values ('test', 'testdb1', 'W');
    Insert test values ('prod', 'proddb1', ' don't);
    Insert into test values ('dev', 'devdb1', 'H');
    Insert into test values ('dev', 'devdb1', 'C');
    Insert into test values ('prod', 'proddb1', 'H');
    Insert test values ('train', 'traindb1', ' don't);
    Insert into test values ('dev', 'devdb1', 'W');
    Insert test values ('test', 'testdb1', ' don't);
    Insert into test values ('train', 'traindb1', 'W');
    Insert test values ('dev', 'devdb1', ' don't);


    I'm trying to get an output format like this below someone can help me: -.

    PRIORITY OF THE ENV
    ----- --------
    prod C
    Test C
    C train
    Dev C

    prod W
    train W
    test W
    dev W

    prod:
    train:
    H-test
    dev:

    prod N
    N train
    test N
    dev N
    select env, priority
    from test
    order by decode(priority,'C',1,'W',2,'H',3,'N',4);
    

    You could order env also by a decoding, but I do not see a specific sequence in the output.
    Once 'test' is before 'train', another time 'train' is of 'test '.
    If you want to 'train' before 'test', it looks like this:

    select env, priority
    from test
    order by decode(priority,'C',1,'W',2,'H',3,'N',4),
             decode(env,'prod',1,'train',2,'test',3,'dev',4);
    

    When there are other values for env or priority scheduling of these values would be undefined for the latter.

    Published by: hm on 06.10.2011 02:23

  • How to use the "Order by" clause dynamically on values LOV Forms 10g r2

    Hello

    I have following requirement, please guide me.

    1. create a list of values with 2 fields, Code and Description

    2. do not use the command clause contained in the registration request Group

    3. fix this LOV on a form field

    4. when the user calls the user LOV will see two fields in LOV with header as Code and Description

    5. when the user clicks the column header "Code" then LOV should be arranged on Code

    6 and if the user clicks on the header of the column "Description" then LOV must be sorted on the Description


    Thanks in advance.

    Please post this problem in this forum->

    [Formulas Forum | http://forums.oracle.com/forums/forum.jspa?forumID=82]

    And close this thread by he scored as replied. ;)

    Kind regards.

    LOULOU.

  • order by clause based on the value of the parameter

    Hello

    I use reports 6i with db 10 g

    I need to create a report sorted in the order of four fields. There is a field selection parameter which should come first in the order by clause.

    IE the user has available to display the report in a sorted order selected

    Assume that the four fields are emp_id, name, dept_id desig.

    If the user selects dept_id, then the order by clause should be in order of dept_id emp_id, name, desig

    Please help solve this scenario.

    Thank you

    Hi Clement,.

    Use the query as follows:

    select column_name1, column_name1, ....
    from  table_name
    &order_by_clause
    

    Now in the trigger AFTER-PARAMETER-SHAPE has the order by clause below according to requirements:

    if :sort_column = dept_id then
    
      :order_by_clause := 'order by dept_id,emp_id,name,desig';
    
    else
    
      :order_by_clause := 'order by emp_id, dept_id, name,desig';
    
    end if;
     
    

    Here's sort_column setting user who will be selected by the user, provide the list of values for it.

    Hope this helps

    Best regards

    Arif Khadas

Maybe you are looking for