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?

Tags: Database

Similar Questions

  • ORDER BY clause or HAVING clause... ERROR

    Hi, I request what error throws please find the solution for the application to go without danger...


    Select C.src_cd,
    D.src_nm,
    Count (*) supp_clm_count,
    (CASE WHEN A.clm_ttladjamt > 0 then A.clm_ttladjamt to another A.clm_ttlreqamt END) as the amount
    Of IWOWNER. WC_clm, a.
    IWOWNER. WC_clm_srvc B,.
    LOVELY. WC_SRC C.
    LOVELY. WC_SRC_lang D
    where A.clm_id = B.clm_id
    and A.rcv_loc_id = C.src_id
    and C.src_id = D.src_id
    and TRANSLATE (A.clm_rqst_type_cd) = "SUPPLIERCLAIM".
    and TRANSLATE (A.clm_typ_cd) in ('GUARANTEE', 'PRE-DELIVERY')
    and DATE (A.clm_create_dt) between January 1, 2000 "and on January 1, 2010"
    C.src_cd group, D.src_nm



    ERROR:
    -------

    SQLSTATE: 42803, SQLERRMC: CLM_TTLADJAMT
    Message: An expression starting with "CLM_TTLADJAMT" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or a SELECT clause, a HAVING clause ORDER BY clause with a column function and no GROUP BY clause is specified

    Hello

    With oracle, you can try this query.

    Salim cordially.

    /* Formatted on 2009/07/22 10:10 (Formatter Plus v4.8.8) */
    SELECT DISTINCT c.src_cd, d.src_nm,
                    COUNT (1) OVER (PARTITION BY c.src_cd, d.src_nm)
                                                                   supp_clm_count,
                    (CASE
                        WHEN a.clm_ttladjamt > 0
                           THEN a.clm_ttladjamt
                        ELSE a.clm_ttlreqamt
                     END
                    ) AS amount
               FROM iwowner.wc_clm a,
                    iwowner.wc_clm_srvc b,
                    showner.wc_src c,
                    showner.wc_src_lang d
              WHERE a.clm_id = b.clm_id
                AND a.rcv_loc_id = c.src_id
                AND c.src_id = d.src_id
                AND a.clm_rqst_type_cd = 'SUPPLIERCLAIM'
                AND a.clm_typ_cd IN ('WARRANTY', 'PRE-DELIVERY')
                AND a.clm_create_dt BETWEEN TO_DATE ('01/01/2000', 'dd/mm/yyyy')
                                        AND TO_DATE ('01/01/2010', 'dd/mm/yyyy')
    
  • Order by clause

    Hello

    I want to know what it means when I use the "order by" clause with more than one column in both cases (sort order, it's the same, and when the sort order is different), for example

    What should happen when I do this

    1 Select * from table

    order by 1, 2; -both are a CSA

    2 - Select * from table

    order by 1 asc, desc 2;

    in both cases if it sorts the column with the first column without worrying, it is asc or desc, order another column order, because he should get

    related data in the first column, then another sort column does nothing?

    Am I wrong?

    Thank you

    SQL > select * from t by col1, col2 CSA CSA;

    COL1 COL2

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

    1                    1

    1                    2

    1                    3

    2                    1

    2                    2

    SQL > select * from t by CSA col1, col2 desc;

    COL1 COL2

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

    1                    3

    1                    2

    1                    1

    2                    2

    2                    1

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

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

  • 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

  • sys_context and order by clause

    Hi all

    IM using Oracle 11 g R2.

    Is it somehow possible to use the context variable (to store the column name) in the ORDER BY clause? My ultimate goal is to build by Order at run time, without using the concatenation.

    for example, I created context as my_ctx for some pkg and its variable as v_ctx with a value defined as 'TABLE_NAME '.
    So it is possible to use it as

    Select * from all_tables
    sys_context order ('my_ctx', 'v_ctx');

    If not, does perform a work around?

    Thank you
    Vivek

    Hi, Vivek,

    Vivek says:
    Hi all

    IM using Oracle 11 g R2.

    Is it somehow possible to use the context variable (to store the column name) in the ORDER BY clause? My ultimate goal is to build by Order at run time, without using the concatenation.

    Of course, you can use SYS_CONTEXT in an ORDER BY clause, but it is unclear what you are trying to do, so I don't know if SYS_CONTEXT will help you.

    for example, I created context as my_ctx for some pkg and its variable as v_ctx with a value defined as 'TABLE_NAME '.
    So it is possible to use it as

    Select * from all_tables
    sys_context order ('my_ctx', 'v_ctx');

    If not, does perform a work around?

    Post a full test script Hat people can run to recreate the problem and test their ideas. Show the output you want from the parameters a data you give.

    Consider using a CASE expression in the ORDER BY clause. You can use SYS_CONTEXT in the expression BOX, if you wish.

  • 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

  • Can I connect a link more MXI for PXI-1033 card in order to work with it

    Ladies and gentlemen,

    Tell me please that I can plug a card of MXI link more in the PXI-1033 chassis in order to work with it.

    In other words, I don't use the built-in controller for MXI and want to work with the NI PXI-8366 MXI-Express and PXI-1033.

    Thank you.

    The answer to your question is no. The question that must be taken into consideration is the type of housing, we have access to on the PXI-1033. To use a PXI MXI card for control purposes in a PXI system, we need to use the card in a slot of system controller (denoted by a triangle around the number of slots on the chassis). With the 1033 however, we have no access to slots control. Because of the connection of controller MXI incorporated, we only have access to a calendar/trigger and devices slots.

    Is there a particular reason you don't want to use on the 1033 MXI connection, or you just want to avoid having to change the connection to another computer?  Single MXI cards which would depend on the space available on the PXI-1033 would be something along the lines of the 8367 and 8367, who are used to the Garland of a separate chassis.

  • Order By clause does not

    I have a very basic SQL statement that I am running on a simple table of three columns. I just want to choose two of the three columns basing selection on a column, then rank each other. I use version 9.2.0.1.0 and I tried to use sqlplus and toad 10.6 and the results are the same in both. My problem is that even if I use an Order By clause the results not be sorted. I have countless statements written and never had a problem with the Order By clause before. I'm puzzled.

    Executed SQL statement:

    Select COL3 From Table1 where COL2 = 1 Order By COL3;

    Result:

    DXXXXX
    NXXX Mxxx/Cxxxx CXXV
    Nzzzz Ezzzz
    Oxxxxxxxxxx Exxxx
    Rxxxxxxxxx Exxxx
    Sxxxxxxx Exxxx
    Sxxxxxx Hxxx
    gxxxxxxx

    You should know that I replaced everything except the first letter of each letters to alter woth Word. There's nothing remarkable about the table:

    Executed SQL statement:

    DESC Table1;

    Result:

    Table1 TABLE:
    Name                                      Null?    Type
    ----------------------------------------- -------- ----------------------------
    COL1                                                   NUMBER
    COL2                                                   NUMBER
    COL3 VARCHAR2 (255)

    Hello

    Use this...

    Select COL3 From Table1 where COL2 = 1 Order By LOWER (COL3);

    It should work once you order by the case-based.

    When you view, its up to you, if you want to use all the conversions of case or not

  • How to order by working with rownum

    Oracle worm: 11g

    Hi all
    I have 2 cases here, with external control by one and another without external by command.
    I see no difference in the results for the moment.
    Case 1:
    /* Formatted on 4/30/2013 2:12:28 PM (QP5 v5.240.12305.39446) */
    SELECT *
      FROM (  SELECT ROWNUM rn, id
                FROM (SELECT 9 AS id FROM DUAL
                      UNION ALL
                      SELECT 1 FROM DUAL
                      UNION ALL
                      SELECT 14 FROM DUAL
                      UNION ALL
                      SELECT 7 FROM DUAL
                      UNION ALL
                      SELECT 5 FROM DUAL
                      UNION ALL
                      SELECT 6 FROM DUAL
                      UNION ALL
                      SELECT 13 FROM DUAL
                      UNION ALL
                      SELECT 8 FROM DUAL
                      UNION ALL
                      SELECT 2 FROM DUAL
                      UNION ALL
                      SELECT 4 FROM DUAL
                      UNION ALL
                      SELECT 19 FROM DUAL
                      UNION ALL
                      SELECT 3 FROM DUAL)
            ORDER BY id)
     WHERE rn BETWEEN 1 AND 6;
     
    Case 2:
    I added the command by external clause in this case
    But I want to make sure if I really need to have the order of outer query by here.
    /* Formatted on 4/30/2013 2:12:28 PM (QP5 v5.240.12305.39446) */
    SELECT *
      FROM (  SELECT ROWNUM rn, id
                FROM (SELECT 9 AS id FROM DUAL
                      UNION ALL
                      SELECT 1 FROM DUAL
                      UNION ALL
                      SELECT 14 FROM DUAL
                      UNION ALL
                      SELECT 7 FROM DUAL
                      UNION ALL
                      SELECT 5 FROM DUAL
                      UNION ALL
                      SELECT 6 FROM DUAL
                      UNION ALL
                      SELECT 13 FROM DUAL
                      UNION ALL
                      SELECT 8 FROM DUAL
                      UNION ALL
                      SELECT 2 FROM DUAL
                      UNION ALL
                      SELECT 4 FROM DUAL
                      UNION ALL
                      SELECT 19 FROM DUAL
                      UNION ALL
                      SELECT 3 FROM DUAL)
            ORDER BY id)
     WHERE rn BETWEEN 1 AND 6;
     ORDER BY id;
    Thank you
    Rod.

    Hey, Rod,

    SamFisher wrote:
    ... I see no difference in the results for the moment.

    You can not, but you are not sure that you will never see a difference. There may be a difference if you change versions, or if you add more data, or for no apparent reason.

    If there is an ORDER BY clause in the main query (as in query 2) then the output is guaranteed to be in that order.
    Is there no ORDER BY clause in the main query (as in the query 1), then there is no guarantee that the lines will be in a particular order. If Oracle finds it convenient to display rows in order by one of the columns (for example, rn) then she will do. You can't count on it always does the same thing, unless there is an ORDER BY clause.

    You should check the ROW_NUMBER analytic function. It is much more useful and easier to understand, as ROWNUM. (In this example, it maybe not simple, however.)

  • order by clause union in date column

    Hi gems... good evening...

    Oracle version: 11.2.0.2 EL6 Linux server

    I have a query as below:

    Select col1, col2, col3 col4
    tab1, tab2, tab3
    where the conditions
    Union
    Select col1, col2, col3 col4
    tab1, tab2, tab3
    where the conditions
    Union
    Select col1, col2, col3 col4
    tab1, tab2, tab3
    where the conditions;

    Now the col4 is a date column, and I need to order by on that entire result sets. I know that I can do (order of col4) (order by 4) or at the end of all of the query.

    But the problem is that the output is coming to Mon-dd-yyyy (i.e. 31-Dec-2012).

    I want each output in the format dd/mm/yyyy, so I need to use the function to_char.

    But in this case, I can't use the order by clause, because in this case it's get organized by character IE by 1,2,3,4,5 like that.

    How can I solve my problem... Please help... Thanks in advance.

    Published by: gogol on 3 November 2012 08:05

    Maybe - when you order by date column, she did it with a date internal representation so on exit you can use any date format you think appropriate

    select distinct
           col1,col2,col3,col4
      from (select col1,col2,col3,col4
              from tab1,tab2,tab3
             where conditions_1
                or conditions_2
                or conditions_3
           )
    

    Concerning

    Etbin

  • Need help with regular expressions

    Hi all

    I need your help, because I have no ideas more...

    I have the following problem: in the column of the database table, I have the string with the names of files already uploaded to the database. For example: + File1_V01.txt +, + File1_v02.txt +, + File1_01_v01.txt +, etc. The string _vxx * + or _Vxx * + (non-case sensitive) represents the version of the file.

    Now the problem: I'll upload the file with the name + File1_v02.txt + (already exists in the table).
    If the file name already exists in the table the pl/sql function should get the name of the file with the following version number. In my case it takes + File1_v03.txt +.

    Is it possible to do this using SELECT with regular expressions?

    Best regards and thanks!
    with t as (
      select 'File_V05.txt' fn from dual union all
      select 'File_V04.txt' fn from dual union all
      select 'File2_v03.doc' fn from dual union all
      select 'File2_v115.doc' fn from dual union all
      select 'File2_v15.doc' fn from dual union all
      select 'File1_v03.doc' fn from dual union all
      select 'File1_v115.doc' fn from dual union all
      select 'File1_v999.doc' fn from dual union all
      select 'File2.doc' fn from dual union all
      select 'File2_v05.doc' fn from dual union all
      select 'File1_v01.txt' fn from dual union all
      select 'File1_v02.txt' fn from dual union all
      select 'File1_v1.txt' fn from dual union all
      select 'File1_v1.doc' fn from dual union all
      select 'File1_v2.txt' fn from dual union all
      select 'File2_v01.doc' fn from dual union all
      select 'File2_v02.doc' fn from dual union all
      select 'File1_ABC_v01_DEF.docx' fn from dual union all
      select 'File1_ABC_V02_ABC.docx' fn from dual union all
      select 'File1_ABC_v01_12_04_17.docx' fn from dual union all
      select 'ABC_V1_QWERT.pdf' fn from dual
    )
    
    select fn,
    case when fn!=fn_new then
     last_value(fn_new)
     over(partition by regexp_replace(upper(fn),'V[[:digit:]]+','') --(.*?V0*)([1-9]+)(\..*?)$
     order by nv
     rows between unbounded preceding and unbounded following
     )
    else fn
    end fn_new
    from (
        select
        case when v-1 <= 0 then fn
        else
               regexp_replace (fn,
                        '(_v|_V)(\d*)',
                        case
                        when length(substr(fn,v+1,p-v-1)+1) > (p-v-1)
                        then '\1'||to_char(substr(fn,v+1,p-v-1)+1)
                        else '\1'||lpad(substr(fn,v+1,p-v-1)+1,p- v-1,0)
                        end
               )
        end fn_new
        ,fn
        ,case when v-1 <= 0 then -1
         else
            substr(fn,v+1,p- v-1)+1
         end nv
        from (
            select fn, regexp_instr(upper(fn),'_V[[:digit:]]+',1,1,1) p, instr(upper(fn),'_V')+1 v from t
        )
    )
    order by fn
    
    FN     FN_NEW
    ABC_V1_QWERT.pdf     ABC_V2_QWERT.pdf
    File_V04.txt     File_V06.txt
    File_V05.txt     File_V06.txt
    File1_ABC_v01_DEF.docx     File1_ABC_v02_DEF.docx
    File1_ABC_v01_12_04_17.docx     File1_ABC_v02_12_04_17.docx
    File1_ABC_V02_ABC.docx     File1_ABC_V03_ABC.docx
    File1_v01.txt     File1_v3.txt
    File1_v02.txt     File1_v3.txt
    File1_v03.doc     File1_v1000.doc
    File1_v1.doc     File1_v1000.doc
    File1_v1.txt     File1_v3.txt
    File1_v115.doc     File1_v1000.doc
    File1_v2.txt     File1_v3.txt
    File1_v999.doc     File1_v1000.doc
    File2.doc     File2.doc
    File2_v01.doc     File2_v116.doc
    File2_v02.doc     File2_v116.doc
    File2_v03.doc     File2_v116.doc
    File2_v05.doc     File2_v116.doc
    File2_v115.doc     File2_v116.doc
    File2_v15.doc     File2_v116.doc
    
  • ORA-00907: lack the right parenthesis when using Group by clause with xmlagg

    I have the following query and I am getting ORA-00907 error when I use the clause with the xmlagg function group.
    select xmlelement("Mitigation",
                    xmlelement("m_szMethodName",tm.DisplayName),
                    xmlelement("SubstanceInterferenceProtocolList",
                                (select xmlagg(xmlelement("MitigationProtocol",
                                        xmlelement("m_szMethodName",tm.DisplayName),
                                        xmlelement("m_szInterferenceProtocolName",tmp.protocol_name),
                                        xmlelement("m_szInterferenceSubstance",tmp.intf_mtrl_prod_code),
                                        xmlelement("m_ProtocolParameters",
                                            xmlelement("m_szProtocolName",tmp.protocol_name),
                                                xmlelement("m_Consumables",
                                                    xmlelement("Consumable",
                                                        xmlelement("m_szConsumId", xrl.rgnt_pack_name),
                                                        xmlelement("m_szProductCode",xrl.pack_prod_code),
                                                        xmlelement("m_nVolume",tmp.fluid_vol),
                                                        xmlelement("m_szProtocolStep",xps.protocol_step_name))),
                                                    xmlelement("m_ProtParamList",
                                                        xmlagg(
                                                        xmlelement("ParameterValues",
                                                            xmlelement("m_szProtocolName",tmp.protocol_name),
                                                            xmlelement("m_Time",xpsd.parameter_ntime_value))
                                                        group by tmp.ccd_test_id,tmp.intf_mtrl_prod_code)
                    )))
                    order by tmp.ccd_test_id, tmp.intf_mtrl_prod_code, xps.protocol_step_intprotocolstep )
                    from XPR_tdef_mitigation_protocol tmp, xp_reagentlist xrl,
                    xpr_protocol_settings xps, xpr_protocol_settings_default xpsd
                    where tmp.ccd_test_id = tm.ccd_test_id
                    and tmp.ccd_test_id = xrl.ccd_test_id
                    and tmp.pack_prod_code = xrl.pack_prod_code
                    and tmp.intf_type = 1
                    and xps.protocol_name = xpsd.protocol_name
                    and xps.protocol_step_name = xpsd.protocol_step_name
                    and xps.ps_action_parameterlist = xpsd.ps_action_parameterlist
                    and xps.protocol_name =  tmp.PROTOCOL_NAME
                    )))
    from XPtoXPRTdef_defn_mapping tm
    where tm.DisplayName = 'SYPH'
    If I remove the clause xmlagg and the group by clause, the query works well and not give me the result.
    But in this code XML, the output format is incorrect for my application.

    Could someone help out here?

    Now my problem is that this unique coating is more than 32767 characters and utl_file can write 32767 bytes per line.
    Someone deal with this?

    Serialize the output as CLOB and DBMS_XSLPROCESSOR.clob2file procedure used to write to a file:

    DECLARE
      xml_output CLOB;
    BEGIN
      SELECT XMLElement("Department",
               XMLAgg(
                 XMLElement("Employee",e.job_id||' '||e.last_name)
                 ORDER BY e.last_name
               )
             ).getClobVal() AS "Dept_list"
      INTO xml_output
      FROM hr.employees e
      WHERE e.department_id = 30 OR e.department_id = 40;
    
      DBMS_XSLPROCESSOR.clob2file(xml_output, 'XML_DIR', 'test.xml');
    END;
    /
    

Maybe you are looking for