Help with order by clause

Hello

I have a table with the data below, when I run my select with order option gives me
1 card

as a first line, but I need it
12 atm

as the first line, how this is possible.



create table test
(Identification number,
Val varchar2 (20)
)


insert into test values (1, 'Card')
Insert test values (2, ' map')
Insert test values (3, ' map')

Insert test values (4, 'cash')
Insert test values (5, 'Cash')
Insert test values (6, 'cash')

Insert test values (7, "Checque")
Insert test values (8, "Checque")
Insert test values (9, "Checque")

Insert test values (10, 'atm')
insert into test values (11, 'atm')
Insert test values (12, 'atm')



Select * from test
order by ASC of val

Or try again with

 select * from test order by upper(val) asc, id desc 

Tags: Database

Similar Questions

  • Need help with order by clause row_number() Fn

    with t as
    (
     select 123 id, 'brwr' lstatus from dual
     union all
     select 123 id, 'ca' lstatus from dual
     union all
     select 123 id, 'fac' lstatus from dual
     union all
     select 345 id, 'ca' lstatus from dual
     union all
     select 345 id, 'brwr' lstatus from dual
     union all
     select 567 id, 'brwr' lstatus from dual
     union all
     select 789 id, 'brwr' lstatus from dual
     union all
     select 1011 id, 'fac' lstatus from dual
    union all
     select 1011 id, 'xyz' lstatus from dual
    )select id,lstatus,row_number() over(partition by id order by lstatus)rw
     from t;
    Desired output
    id           lstatus       rn
    
    123         brwr         3
    123         ca          1
    123         fac         2
    345         ca          1
    345         brwr         2
    567         brwr         1
    789         brwr         1
    1011         fac        1
    1011  xyz         2
    That is, my first priority is to 'ca', then 'College '.

    I am aware that this can be done through the use of CASE within the order by clause
    but could not find the logic of the apt.

    Please help me.

    A solution just for data given to samples...

    with t as
    (
     select 123 id, 'brwr' lstatus from dual
     union all
     select 123 id, 'ca' lstatus from dual
     union all
     select 123 id, 'fac' lstatus from dual
     union all
     select 345 id, 'ca' lstatus from dual
     union all
     select 345 id, 'brwr' lstatus from dual
     union all
     select 567 id, 'brwr' lstatus from dual
     union all
     select 789 id, 'brwr' lstatus from dual
     union all
     select 1011 id, 'fac' lstatus from dual
    union all
     select 1011 id, 'xyz' lstatus from dual
    )select id,lstatus,row_number() over(partition by id order by (case  when lstatus <> 'brwr' THEN UPPER(lstatus) else lstatus end)) rw
     from t;
    

    Basically, it shows how to use the CASE statement. You can change based on your actual data.

    Concerning
    Arun

  • Problem with order by clause

    Hai all,

    I have problem with order by clause,

    My query is

    "Select number from table1 order number CSA.

    and the output as

    1
    10
    12
    13
    15
    17
    19
    2
    20
    21
    22
    .
    ........

    But if we give the order that it should display below the only good?

    1
    2
    10
    12
    13
    15
    17
    19
    20
    21
    22 ........

    Help me please why it is not displayed as she. and how to make the statement to display as in the second case. Thanks in advance.

    Kind regards
    Uraja

    In your table, the column is VARCHAR2 data type.

    It is a string, even if it is to store numeric values, it will get condemn as strings

    Try the below

    select your_column from table1 order by to_number(your_column) asc 
    

    Published by: JAC on November 19, 2012 16:35

  • Need help with dynamic where clause.

    Hello world.  I'm kind of a novice with PL/SQL, so please be patient with me.  I am building a web application using Weblogic Oracle 11 g and Oracle database.

    To make a long story short, I need to generate the complex dynamic WHERE clause.  I don't know what will be the name of the column or the operator of comparison or the value will be until the moment of execution.

    I'm not 100% certain, but I think I need to use dynamic SQL statements.  Unless there is a better way to do it.

    I'm sure that using dynamic SQL opens me up to SQL injection attacks if I use simple string concatenation.  I would like to use bind variable if possible.

    In any case, it seems like trying to build a dynamic where clause does not seem to work as I want it would be...

    bv1 := 'colA = 5 and colB >= 9';
    
    query_str := 'SELECT * FROM view WHERE :bv1';
    
    OPEN CUR FOR query_str USING bv1;
    

    The code above pours out when I try to run it.

    Is there a way to build dynamic where the provisions without the use of concatenation of simple string that leaves me open to attacks by SQL injection?

    Thank you

    Hello.  I have read briefly upward on things, you suggested, but it seems a bit abstract for me since I was a novice.

    Can you give us an explanation or an example of how to use it to accomplish what I need to do?

    Do ypu really plan create a query with a WHERE clause that contains a predicate for all possible columns?

    Variable bind offer performance when the same query is executed several times with different values for bind variables.

    Select * from emp where empno =: v_empno

    After the first run Oracle will always be this query in the library cache. The next running can use the version of the cache even if the bind value is different.

    Select * from emp where empno =: v_empno;

    Select * from emp where ename =: v_ename;

    Select * from emp where sal =: v_sal;

    Each one is a DIFFERENT query. Yes - each of them uses a variable binding, but queries are different.

    So, if your username select EMPNO, an '=', and a value from the first query can be executed. But the next time that the user can select the ENAME column so that 'stored' first request may not be used given that the query does not match.

    The third time your user selects SAL so none of the first two queries can be used in the library cache. The use of bind variables gives performance during the SAME QUERY is used multiple times with DIFFERENT values for the variable binding. Oracle is not to analyze the hard query everything simply because the VALUE is different.

    So bind variables do not help you if most of the queries were completely DIFFERENT sets of predicates. And SYS_CONTEXT will not help either since that simply provides a way to define binds the values of the variables.

    Just for the simple example above, there are at least SIX possible combinations of columns that could choose your user name: empno, ename, sal, empno ename, empno & sal, ename & sal

  • Cannot wrap a select with order by clause in a file.

    TOGETHER SET TERMOUT OFF FEEDBACK OFF PAGESIZE 0 400 LINESIZE ECHO OFF OFF POSITION

    coil & 1;

    Select "EMPID, EMP_NAME, REGION, FROM, TO, MONTH, ACTIVITY_TYPE, PROJECT_PIN, MILESTONE_NAME, PRACTICE_ID, RESOURCE_CATEGORY, HOURS, COMMENT, percent ALLOCATION, INVOICE_TO, the STATE of the double"

    Union of all the

    select empid,resource_name,region,week_of,(week_of+7),core_month,bill_rate,project_name,project_type,milestone_name,practice_id,resource_category,total_hours_submitted,project_type,"%ALLOCATION",invoice_to,status from master_emp_allocation order by week_of;

    spool off;

    "exit";

    /

    the above block gives result below

    select empid,resource_name,region,week_of,(week_of+7),core_month,bill_rate,project_name,project_type,milestone_name,practice_id,resource_category,total_hours_submitted,project_type,"%ALLOCATION",invoice_to,status from master_emp_allocation order by week_of

    *

    ERROR at line 3:

    ORA-00904: "WEEK_OF": invalid identifier

    ---------------------------------------------------------------------------

    Without the order by clause it wraps the file passed as an argument.

    check

    Combining the UNION AGENDA and BY

    Columns in the ORDER BY list must be a subset of the columns in the selection list on the left side of the union.

    All the columns in the ORDER BY list should be sorted in ascending order, and they must be a prefix in the order of the columns in the target of the left side of the UNION list.

  • [10g] need help with order by hierarchical query clause

    I have the following data samples:
    CREATE TABLE     bill_test1
    (     parent_part     CHAR(25)
    ,     child_part     CHAR(25)
    ,     line_nbr     NUMBER(5)
    ,     qty_per          NUMBER(9,5)
    );
    
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-10',100,1);
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-20',200,2);
    INSERT INTO bill_test1 VALUES ('ABC-1','ABC-30',300,3);
    INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-1',401,10);
    INSERT INTO bill_test1 VALUES ('ABC-1','HARDWARE-2',402,5);
    INSERT INTO bill_test1 VALUES ('ABC-10','ABC-155',100,2);
    INSERT INTO bill_test1 VALUES ('ABC-10','HARDWARE-1',200,1);
    INSERT INTO bill_test1 VALUES ('ABC-155','RAW-2',100,4.8);
    INSERT INTO bill_test1 VALUES ('ABC-155','HARDWARE-3',200,3);
    INSERT INTO bill_test1 VALUES ('ABC-20','RAW-1',100,10.2);
    INSERT INTO bill_test1 VALUES ('ABC-30','RAW-3',100,3);
    And the following query gives me exactly what I want, in the order I want. However, I wonder if there is a way to get this order without creating the column SEQ, given that I don't need in my results
    SELECT     part_nbr
    ,     parent_part
    ,     child_part
    FROM     (
         SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
         ,     b.parent_part
         ,     b.child_part
         ,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
         FROM     bill_test1 b
         ,     dual
         CONNECT BY     parent_part     = PRIOR child_part
         )
    WHERE          part_nbr     = 'ABC-1'
    ORDER BY     seq
    ;
    
    Results of above query, except with SEQ included in SELECT (just to show what I'm sorting off of):
    PART_NBR                     PARENT_PART                  CHILD_PART                   SEQ
    ---------------------------- ---------------------------- ---------------------------- -----------------
    ABC-1                        ABC-1                        ABC-10                        100
    ABC-1                        ABC-10                       ABC-155                       100 100
    ABC-1                        ABC-155                      RAW-2                         100 100 100
    ABC-1                        ABC-155                      HARDWARE-3                    100 100 200
    ABC-1                        ABC-10                       HARDWARE-1                    100 200
    ABC-1                        ABC-1                        ABC-20                        200
    ABC-1                        ABC-20                       RAW-1                         200 100
    ABC-1                        ABC-1                        ABC-30                        300
    ABC-1                        ABC-30                       RAW-3                         300 100
    ABC-1                        ABC-1                        HARDWARE-1                    401
    ABC-1                        ABC-1                        HARDWARE-2                    402

    Hello

    As long as there is that a single root, brothers and SŒURS of ORDER BY, you say, but you can not do in a subquery (well, you can, but usually there is no interest in a subquery). If the CONNECT BY in a subquery, there is no guarantee that the main request will preserve the hierarchical order which provides the subquery.

    The query you posted does not require a query of Tahina, so you can say:

    SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
    ,     b.parent_part
    ,     b.child_part
    --,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
    FROM     bill_test1 b
    WHERE          CONNECT_BY_ROOT b.parent_part     = 'ABC-1'
    CONNECT BY     parent_part     = PRIOR child_part
    ORDER SIBLINGS BY     b.line_nbr
    ;
    

    I said the query you posted does not require a subquery. It also does not require double, so I guess that what you posted is a simplification of what you are really doing, and that could have a subquery. In particular, if you want to GROUP BY part_nbr, you need the subquery. We can use CONNECT_BY_ROOT expression in the WHERE clause (or, come to think of it, use a START WITH clause instead WHERE), but, for some reason, we cannot use CONNECT_BY_ROOT in a clause GROUP BY; We need to calculate CONNECT_BY_ROOT in a subquery, give it a name (like part_nbr) and Super GROUP OF this column in a query.

    This requires that there is that one node root. ORDER OF brothers and SŒURS means just that: children of a common parent will appear in the order, but the root nodes, which have no parents, may not be in order.

    Here's what I meant by using START WITH place WHERE:

    SELECT     CONNECT_BY_ROOT b.parent_part                         AS part_nbr
    ,     b.parent_part
    ,     b.child_part
    --,     SYS_CONNECT_BY_PATH(b.line_nbr,' ')                    AS seq
    FROM     bill_test1 b
    START WITH     b.parent_part     = 'ABC-1'
    CONNECT BY     parent_part     = PRIOR child_part
    ORDER SIBLINGS BY     b.line_nbr
    ;
    

    This should be much more effective, because it reduces the results before waste you your time by getting their descendants.
    With the help of a clause START WITH here is analogous to me sending you an email, saying "come to a meeting one my office at 03:00."
    By using a WHERE clause here is similar by sending me an e-mail to all members of society, saying: "come to a meeting one my office at 3:00" and then, as people get here, tell everyone except you could go back.

    Brothers and SŒURS ORDER BY was introduced in Oracle 9.

    Published by: Frank Kulash, December 9, 2010 14:39
    Added version with the START WITH clause

  • Need help with ordering high voltage

    Hello

    NI PCIe-6341 card is already installed. And I want to order a power supply voltage (CZE1000R) to generate the high voltage (DC). The goal is to fully control the high voltage. For example, the voltage can chang from zero to 30 kV in 5 or 10 seconds and be stable to 30 kV to 30 minutes and then go down smoothly at 20 kV in 5 minutes and finally back to zero. Could someone help me with this task? Thank you.

    Hi, apok,

    I used the 'panels-test' on 'measurement and automation explorer. And I see signals on an oscilloscope.

    Thank your for your help.

    But when I try to test the "tension cntrl.vi" it has not worked.

    On the manual, he said:

    "

    Programming with external voltage:

    Disconnect between TB1-2 and TB1 - 3 riders. Connect signal 0 - 10V between TB1-3 and TB1-6 (common)".

    This means that I need to plug TB1 - 3 and TB1 - 6 and out of the acronym to TB1-3?

  • Help with MySQLI WHERE clause

    I am trying to retrieve records from a table of unique composition based on the following criteria:

    -members belong to 2 different associations (coded: Association = 1 or 2)

    -Some members have no postal addresses (coded: adresse_rue) and will not send mail.

    -Some members Association = 1 don't you mail (coded: D or V or W, X or Z)

    -No member of the Association 1 with cur_bal_2 = < gets 10 mail

    -No member of the Association 2 with cur_bal_2 = <-1 get mail

    -cur_bal_2 field is a numeric value in the table.

    I tested

    WHERE (Mbr_Scat = 'P' AND Association = 2 AND adresse_rue <>' ' AND cur_bal_2 > = - 1) by itself results accurate/w

    I tested

    WHERE (Mbr_Scat <>had ' AND Mbr_Scat <>'V' and 'W' AND Mbr_Scat <>'X' <>Mbr_Scat ' AND cur_bal_2 >-20 AND adresse_rue <>' ") by itself, results also w/accurate

    But-

    When I combine the above to:

    WHERE

    (Mbr_Scat = 'P' AND Association = 2 AND adresse_rue <>' ' AND cur_bal_2 > = - 1).

    OR

    (Mbr_Scat <>had ' AND Mbr_Scat <>'V' and 'W' AND Mbr_Scat <>'X' <>Mbr_Scat ' AND cur_bal_2 >-20 AND adresse_rue <>' ")

    the part of the WHERE the criteria cur_bal_2 > = - 1 is not running (ONLY this part of the statement fails - members whose balances is less than-1 selecting.)

    I get no error message.

    Suggestions?

    Best regards and thank you all,.

    Tom Smith

    Try this:

    WHERE adresse_rue <> "

    AND

    ((Association = 1 AND Mbr_Stat pas dans (serait ', 'V', 'W', 'X', 'Z') AND cur_bal_2 > = - 10) OR (Association = 2 AND cur_bal_2 > = - 1))

  • Need help with orders to clear a N2024 stacked switch port configuration

    The current config is:

    interface item in gi1/0/20

    Speed 1000

    Description "WifiLocation2".

    VLAN allowed switchport General add 154

    switchport general allowed vlan add 153 tag

    switchport vlan allowed General remove 1

    switchport access vlan 15

    LLDP transmit tlv ESCR-sys sys - cap

    LLDP transmit-mgmt

    notification of LLDP

    LLDP-med confignotification

    disable voice vlan auth

    I need to look like:

    interface item in gi1/0/20

    Description "WifiLocation2".

    switchport access vlan 15

    I tried a lot of things, but cannot get rid of the lines switchport

    any help would be appreciated

    Clayton

    Another way to remove the general lines switchport is to use the option "Delete" on all VLANs currently associated.  Just like what has been done for the vlan 1 in your example. Something like this:

    switchport vlan allowed General remove 153, 154

    Make sure you have the mode set correctly.  By default, the access mode is set.  If the default value of access is being used, the lines "switchport general" are ignored anyway.

    Hope this has been helpful.

    B

  • Help with the WHERE clause

    I have a Select statement where I want to select rows where weighs only 1 of the selected date 3 columns is null. Is this possible?

    Select rec_date, prior_rec_date2, prev_rec_date3
    of my_receipts
    where (not more than 1 or the date 3 fields is null)

    Any help would be greatly appreciated.

    Hello

    WHERE   NVL2 (rec_date,        1, 0) +
            NVL2 (prior_rec_date2, 1, 0) +
            NVL2 (prev_rec_date3,  1, 0) >= 2
    
  • using rownum with order by

    Hi all

    I want to use rownum with order of clause-

    When I use an order clause in the select query, I get so many lines that I don't want.
    I have average-i want only two first rows according to the order of.

    EG. - Select employee_id, salary of the order of salary employees;
    EMPLOYEE_ID, FIRST_NAME SALARY
    ----------- -------------------- --------
    132 2100 TJ
    Steven 128 2200
    2200 hazelnut 136
    James 127 2400
    135 Ki 2400

    now, I just want to see the first two lines of the output above.
    any oneone please help does
    SQL> SELECT *
    FROM   (SELECT employee_id,
                   first_name,
                   salary
            FROM   employees
            ORDER  BY salary)
    WHERE  ROWNUM < 3;   2    3    4    5    6    7  
    
    EMPLOYEE_ID FIRST_NAME               SALARY
    ----------- -------------------- ----------
            132 TJ                         2100
            128 Steven                     2200
    
  • Need help with configuration on cisco vpn client settings 1941

    Hey all,.

    I just bought a new router 1941 SRI and need help with the configuration of the parameters of the VPN client. Orders aspect a little different here, as I'm used to the configuration of ASA and PIX for vpn, routers not...

    If anyone can help with orders?

    I need the installation:

    user names, authentication group etc.

    Thank you!

    Take a peek inside has the below examples of config - everything you need: -.

    http://www.Cisco.com/en/us/products/ps5854/prod_configuration_examples_list.html

    HTH >

    Andrew.

  • DISTINCT with ORDER BY

    All,

    Facing a problem with the query below... "DISTINCT with Order By Clause.

    His work when we take the same distinct column and order at this time where the query works. But in my case... There are a couple of b/w of joining tables... and are distinct for a column and the order is for a different table with a different column.

    Please suggest me a solution for this below query column in the separate and column used for sorting are different.

    SELECT DISTINCT gl_cc.segment2

    OF gl_code_combinations gl_cc,.

    per_all_people_f req_emp,

    per_all_assignments_f req_emp_assign

    WHERE req_emp.person_id = req_emp_assign.person_id

    AND gl_cc.code_combination_id =

    req_emp_assign.default_code_comb_id

    AND req_emp.full_name = 'xyz '.

    ORDER BY req_emp_assign.last_update_date DESC

    Thank you

    Problem will takes us to Basic!

    Processing order for SELECT statements.

    SQL query(Non recursive SQL) are processed in the following order

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    SELECT clause

    ORDER BY clause

    So if you have something in the ORDER BY, but even not Fetch in SELECT it is bound to view the error.

    Given THAT order will work on column projected by SELECT!

    Single table query will fail also.

    Select distinct ename in order by empno emp;

    SQL error: ORA-01791: not a selected expression

    01791 00000 - "not a selected expression.

    * Cause:

    * Action:

    Inclusion of the req_emp_assign.last_update_date in the select column is necessary for order processing

  • 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

  • ORDER BY clause with an expression

    As the column of names and table name is valid, what happening internally when the query is executed?

    SQL > SELECT STU_ID, STU_NAME FROM to STUDENT BY 2 + 3, STU_ID;

    What I discovered, was that the lines get sorted by ascending order of STU_ID. It is obvious that he does not know the expression 2 + 3, so my doubts are:

    (a) is he adding a pseudo-column to the table with 2 + 3 get discounted at 5?

    Select (b) if there is a 5th column among students of the table and specify us it in the select statement of the list (5 column names) then why not consider as 5 and sort the data according to that?

    (c) it is true that, any expression that we write is getting evaluated to null? Then - what is ORDER BY NULL refers to any order and if the Analyzer search name column or next position (if specified)?

    (d) If neither of the two, so what is the reason of ignorance?

    Hello

    Welcome to the forum!

    987236 wrote:
    As the column of names and table name is valid, what happening internally when the query is executed?

    SQL > SELECT STU_ID, STU_NAME FROM TO STUDENT BY 2 + 3, STU_ID;

    What I discovered, was that the lines get sorted by ascending order of STU_ID. It is obvious that he does not know the expression 2 + 3, so my doubts are:

    b is a pseudo-column adding to the table with 2 + 3 get discounted at 5

    There is no column pseduo involved. (Pseudo-colonnes are something that Oracle provides to you, without requiring you to specify what you want. Include ROWID and LEVEL pseudo-colonnes. In this example, 2 + 3 is an Expression . Like the pseudo-colonnes, expressions can usually appear in the ORDER BY clause, even if they are not actually stored in the table.)
    It is the first sort by the NUMBER 5 (= 2 + 3), not the 5th column. Since the NUMBER 5 has the same value on every row, every row relates to the forefront. The result of sorting by any constant is the same; the results are the same that besides as exrpression in the ORDER BY clause. This is the clause ORDER BY, that you have published is equivalent to

    ORDER BY  2 + 3
    ,         'foo'
    ,         SYSDATE
    ,         NULL
    ,         stu_id
    

    and this is also equivalent to

    ORDER BY  stu_id
    

    None of the expressions except stu_id vary from one line to the other, then none of them affect sorting.

    Select (b) if there is a 5th column among students of the table and specify us it in the select statement of the list (5 column names) then why not consider as 5 and sort the data according to that?

    As Solomon replied only literal numbers are taken to refer to a column. 5 is a literal number, then

    ORDER BY  5
    

    means "Sort by the 5th column", but 2 + 3 is not a literal (that is an expression that happens to include a couple of literals), so

    ORDER BY  2 + 3
    

    does not refer to the 5th colunmn.

    (c) it is true that, any expression that we write is getting evaluated to null? Then - what is ORDER BY NULL refers to any order and if the Analyzer search name column or next position (if specified)?

    No, when you way "ORDER BY x", the rows with values of x which come first, followed by the lines with higher values of x. lines having the same value of x will be together, in no particular order with respect to the other (unless there is an expression of failure later in the clause ORDER BY.
    This is exactly what happens when you say "ORDER BY NULL". NULL has the same value (in fact, the same lack of any value) on all lines, so all rows have the same value of x, and they will appear in no particular order.

    (d) If neither of the two, so what is the reason of ignorance?

Maybe you are looking for