Error due to ORDER BY clause

Hi gurus
I have this formula for a Formula Column
function CF_PREVIOUS_QUANTITY return Number is
quantity number;
begin
SELECT QUANTITY_REMAINING INTO quantity
FROM
SELECT
QUANTITY_REMAINING
FROM ...
WHERE ....
----ORDER BY trx_date DESC
WHERE rownum=1;
return quantity;
end;
This code compiles only if ORDER BY line is commented, otherwise I get this:
Encountered the symbol ORDER when expecting....
The code compiles ok in SQLDeveloper. I just want to get the first record in a recordset.
What's wrong here?
I'm using Reports 6
Thanks in advance
Oscar

You encounter a M-to-1 issue.
try either:
... (-- preferred)
for c in ( SELECT
QUANTITY_REMAINING
FROM ...
WHERE ....
ORDER BY trx_date DESC) loop
return c.QUANTITY_REMAINING ;
end loop;
... (--awkwardly)
SELECT QUANTITY_REMAINING INTO quantity
FROM
( SELECT QUANTITY_REMAINING
SELECT
QUANTITY_REMAINING
FROM ...
WHERE ....
ORDER BY trx_date DESC
WHERE rownum=1
);

Similar Messages

  • Error : The ORDER BY clause is invalid in views, inline functions, derived

    Hi All,
    I am on 11g 6.2, Windows Server 2008, my db SQL server 2008, I am facing the error for the reports in which I am trying to edit one the column formula and do something like 'abc/sum(abc)*100'.
    10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 16001] ODBC error state: 37000 code: 8180 message: [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.. [nQSError: 16001] ODBC error state: 37000 code: 1033 message: [Microsoft][ODBC SQL Server Driver][SQL Server]The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.. [nQSError: 16002] Cannot obtain number of columns for the query result. (HY000)
    One of the solutions to this which I have found is to edit the EXPRESSION_IN_ORDERBY_SUPPORTED feature in the db properties.
    I want to know what does EXPRESSION_IN_ORDERBY_SUPPORTED means?
    When I create a calculations in 11g like abc/sum(abc) in the column formula for a column then i get this error.
    What does this error mean? Does OBIEE 11g doesn't support using these expressions in the report and the fact that it applies the order by clause to the reports, the report fail?
    Could anybody please explain the issue. There is very limited information on this over the web.
    Thanks in advance.
    Ronny

    Thanks svee for the quick response, actually i had resolved the issue by unchecking the EXPRESSION_IN_ORDERBY_SUPPORTED option in the database. I want to understand how does that makes the difference?
    What does EXPRESSION_IN_ORDERBY_SUPPORTED mean? Does it mean that if I give any expression in my answers report and since obiee uses a order by for all the queries, the expression won't be supported?
    Please explain.

  • ORDER BY Clause in XMLAGG is throwing errors.

    Hi,
    I'm getting errors when generating the XML using the ORDER BY clause in the XMLAgg function. Although, running the SQL directly in SQL Plus doesn't have any problem.
    Here is the PL/SQL sample.
    DECLARE
    vX_XML SYS.XMLTYPE;
    vCL_XML CLOB;
    BEGIN
    SELECT XMLElement("GROUP",
    XMLAttributes(Group_Id AS "ID", Group_Name AS "NAME", Group_Description AS "DESC"),
    XMLAgg(XMLElement("FIELD",
    XMLAttributes(Field_Id AS "ID", Field_Description AS "DESC",
    Table_Name AS "TAB_NM", Rule_Name AS "RULE_NM",
    Field_Hierarchy_Depth AS "DOL_VAR_CALC")) ORDER BY Field_Description))
    INTO vX_XML
    FROM (SELECT g.Group_Id, g.Group_Name, g.Group_Description, f.Field_Id, f.Field_Description,
    DECODE(f.Table_Name, 'ESTIMATES', 'E', 'LINE_ITEMS', 'L', NULL) Table_Name,
    rt.Rule_Name,
    CASE NVL(f.Field_Hierarchy_Depth, 0) WHEN 0 THEN 'N' ELSE 'Y' END Field_Hierarchy_Depth
    FROM GROUPS g,
    Rules r,
    Rule_Types rt,
    Fields f
    WHERE g.Group_Id = 3087
    AND r.Group_Id_Fk = g.Group_Id
    AND rt.Rule_Type_Id = r.Rule_Type_Id_Fk
    AND f.Field_Id = r.Field_Id_Fk) tab
    GROUP BY Group_Id, Group_Name, Group_Description;
    vCL_XML := vX_XML.GetCLOBVal();
    END;
    And, here are the errors.
    ERROR at line 8:
    ORA-06550: line 8, column 23:
    PLS-00306: wrong number or types of arguments in call to 'XMLAGG'
    ORA-06550: line 8, column 23:
    PL/SQL: ORA-00904: "XMLAGG": invalid identifier
    ORA-06550: line 6, column 5:
    PL/SQL: SQL Statement ignored
    Thanks in Advance.
    BTW, we are using Oracle 9.2.0.4.

    This is bug 2785463 with no ETA for a fix
    regards
    Coby D. Adams Jr.

  • HAVING clause, or ORDER BY clause ....ERROR

    hi i have following query which throws error plz find the solution for the query to go safe..
    Select C.src_cd,
    D.src_nm,
    count(*) 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 TRANSLATE(A.clm_rqst_type_cd) = 'SUPPLIERCLAIM'
    and TRANSLATE(A.clm_typ_cd) in ('WARRANTY','PRE-DELIVERY')
    and DATE(A.clm_create_dt) between '01/01/2000' and '01/01/2010'
    Group by C.src_cd, 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 it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified

    Hi,
    With analytic function
    /* Formatted on 2009/07/22 10:47 (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,
                    SUM (CASE
                            WHEN a.clm_ttladjamt > 0
                               THEN a.clm_ttladjamt
                            ELSE a.clm_ttlreqamt
                         END
                        ) OVER (PARTITION BY c.src_cd, d.src_nm) 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')

  • Unable for Apple Store to upload IPhoto album due to "error occured unloading order"

    Trying to order IPhot album.  When Apple store tries to upload picture I get message "error occured uploading order".

    What version of iPhoto? Of the OS?
    Are you speaking of a photo book? (an album is an iPhoto organizational element) If so will it preview correctly? 
    Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it.
    If it does and you still can not purchase it boot into safe mode and try
    LN

  • Why I cannot use RowID in where clause but can use it in order by clause

    I am on SQL Server 2008.
    1. If I use
    SELECT (ROW_NUMBER()  over
    (order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
      FROM [JnJ_Version1].[dbo].[td_Production_Week]
      order by RowID
    Statement works
    But
    2. If I use
    SELECT (ROW_NUMBER()  over
    (order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
      FROM [JnJ_Version1].[dbo].[td_Production_Week]
      where  RowID > 10000
    I get error, RowID is an invalid column Name why? How to correct query 2.

    This is due to the logical evaluation order of a SELECT statement. Logically, a SELECT statement is computed in the order:
    FROM (which includes JOIN)
    WHERE
    GROUP BY
    HAVING
    SELECT
    ORDER BY
    OFFSET
    Thus, you can use what is defined in the SELECT list in the ORDER BY clause, but not in the WHERE clause.
    In the case of row_number(), this has immediate repurcussions. row_number() is computed from the rows as they arrive the SELECT clause, and if you then you would filter on the value in the WHERE clause you would be going round in circles.
    To do what you are looking for, you use a nested table, for instance with a CTE:
    WITH numbering AS (
       SELECT (ROW_NUMBER()  over
    (order by ImportId, ScenarioId, SiteID, AssetID, LocalSKUID, WEEKID, MonthID)) RowID, * 
      FROM [JnJ_Version1].[dbo].[td_Production_Week]
    SELECT *
    FROM   numbering
    WHERE  RowID > 10000
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Dump Error during Sales Order Craetion

    Dear Mates
    While creating Sales Order in VA01 iam getting dump error.
    Error Message is
    RUN TIME ERROR : SAPSQL_INVALID_TABLENAME
    EXCEPT : CX_SY_DYNAMIC_OSQL_SEMANTICS
    The raeson for exception is "Invalid table name KOTD801was specified in the open SQL Command
    Due to one of the following reasons, the error occurs only at runtime:
    - the table name was specified dynamically, or                        
    - the SELECT clause, WHERE clause, GROUP-BY clause, HAVING clause, or 
      ORDER-BY clause was specified dynamically.   
    I have created condition table and put up in Package Z001 and iam not sure where i have mistake,Can anybody throw somelight on this issue.
    Thanx in Advance
    Karthik

    SAPSQL_INVALID_TABLENAME
    "Invalid table name KOTD801was specified in
           the open SQL Command
    In normal circumstances, system will throw the above error where no table exists with the specified name.   This means, the second one is self explanatory.  Could you let me know as to whether you are creating sale order with standard order type.
    Nevertheless, you can take the help of ABAPer and before keying in VA01, maintain "/h" on top menu bar and then start creating sale order in debug mode so that your ABAPer can help you out.
    thanks
    G. Lakshmipathi

  • Order by clause in cursor problem

    Hello,
    I'm unable to compile package body when i'm using order by clause in cursor subquery in stored procedure.
    Sample code:
    CREATE PACKAGE Announces AS
    TYPE tRefCur IS REF CURSOR;
    PROCEDURE TopAnnounces(
    iiCount IN NUMBER,
    osAnnounces OUT tRefCur,
    oiRetVal OUT NUMBER
    END Announces;
    CREATE PACKAGE BODY Announces AS
    PROCEDURE TopAnnounces(
    iiCount IN NUMBER,
    osAnnounces OUT NUMBER,
    oiRetVal OUT NUMBER
    AS
    BEGIN
    OPEN osAnnounces FOR
    SELECT Id, Name, AnnCount FROM
    SELECT Id, Name, COUNT(CategoryId) AS AnnCount FROM tblAnnounces
    GROUP BY Id, Name
    -- bellow is the line, where the code crash
    ORDER BY AnnCount DESC
    WHERE ROWNUM < iiCount + 1;
    oiRetVal := 0;
    EXCEPTION
    WHEN OTHERS THEN
    oiRetVal := -255;
    END TopAnnounces;
    END Announces;
    If I compile the code above I will get this error:
    PLS-00103: Encoutered the symbol "ORDER" when expecting on of the following:
    After I remark the problematic line, the compilation is successful (but not the result :).
    Is there something I'm doing wrong?
    Thanks for advice
    Vojtech Novacek
    null

    Sorry you can not use order by clause into one temporal table created by subquery.
    Put the order by clause offside of subquery.
    Atte.
    CC.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Vojtech Novacek:
    Hello,
    I'm unable to compile package body when i'm using order by clause in cursor subquery in stored procedure.
    Sample code:
    CREATE PACKAGE Announces AS
    TYPE tRefCur IS REF CURSOR;
    PROCEDURE TopAnnounces(
    iiCount IN NUMBER,
    osAnnounces OUT tRefCur,
    oiRetVal OUT NUMBER
    END Announces;
    CREATE PACKAGE BODY Announces AS
    PROCEDURE TopAnnounces(
    iiCount IN NUMBER,
    osAnnounces OUT NUMBER,
    oiRetVal OUT NUMBER
    AS
    BEGIN
    OPEN osAnnounces FOR
    SELECT Id, Name, AnnCount FROM
    SELECT Id, Name, COUNT(CategoryId) AS AnnCount FROM tblAnnounces
    GROUP BY Id, Name
    -- bellow is the line, where the code crash
    ORDER BY AnnCount DESC
    WHERE ROWNUM < iiCount + 1;
    oiRetVal := 0;
    EXCEPTION
    WHEN OTHERS THEN
    oiRetVal := -255;
    END TopAnnounces;
    END Announces;
    If I compile the code above I will get this error:
    PLS-00103: Encoutered the symbol "ORDER" when expecting on of the following:
    After I remark the problematic line, the compilation is successful (but not the result :).
    Is there something I'm doing wrong?
    Thanks for advice
    Vojtech Novacek<HR></BLOCKQUOTE>
    null

  • Order by clause in PL/SQL cursors

    I am trying to execute a procedure with some input parameters. I open a cursor
    with a select statement. However, the order by clause in the query does not
    recognize parameter sent through the procedure input parameters.
    For example:
    open <<cursor name>> for
    select id from member order by <<dynamic parameter>>" does not work (Compiles fine but does not return the right result).
    But if I try and give a static order by <<column name>> it works. Is the
    order by clause in the PL/SQL a compile time phenomenon?
    I have also tried it through dynamic sql. All the other parameters work except the order by <<parameter>> asc|desc
    Also "asc" and "desc" does not work if given dynamically.
    What alternatives do I have?
    null

    I don't think order by can be dynamic in a cursor, but it sure can be using dynamic sql. The only issue is that you must do a replace in the sql string with the dynamic variable. For example:
    create or replace procedure test_dyn(p_col in varchar2, p_order in varchar2) as
    q varchar2(500);
    u_exec_cur number;
    u_columnnumber NUMBER;
    u_columndate DATE;
    u_columnvarchar varchar2(50);
    u_cur_count number;
    u_ename varchar2(20);
    u_sal number;
    begin
    q := 'select ename, sal from scott.emp order by p_col p_order';
    -- got to do these two replaces
    q:= replace(q,'p_col',p_col);
    q:= replace(q,'p_order',p_order);
    u_exec_cur := dbms_sql.open_cursor;
    dbms_sql.parse(u_exec_cur,q,dbms_sql.v7);
    dbms_sql.define_column(u_exec_cur, 1, u_columnvarchar, 20);
    dbms_sql.define_column(u_exec_cur, 2, u_columnnumber);
    u_cur_count := dbms_sql.execute(u_exec_cur);
    loop
    exit when (dbms_sql.fetch_rows(u_exec_cur) <= 0);
    dbms_sql.column_value(u_exec_cur, 1, u_ename);
    dbms_sql.column_value(u_exec_cur, 2, u_sal);
    dbms_output.put_line(u_ename);
    dbms_output.put_line(u_sail);
    --htp.p(u_ename);
    --htp.p(u_sal);
    end loop;
    end;
    show errors;
    Now when when I execute my procedure I can change the order by clause all I want, for example:
    SQL> set serveroutput on;
    SQL> exec gmika.test_dyn('sal','asc');
    SMITH
    800
    ADAMS
    1100
    WARD
    1250
    MARTIN
    1250
    MILLER
    1300
    TURNER
    1500
    ALLEN
    1600
    JLO
    2222
    BLAKE
    2850
    JONES
    2975
    SCOTT
    3000
    FORD
    3000
    LOKITZ
    4500
    KING
    5000
    JAMES
    5151
    JAMES
    5555
    PL/SQL procedure successfully completed.
    SQL>
    null

  • Order by clause in Sub query

    Hi,
    Can we use order by clause in Sub query?
    While using the order by clause, I am getting the "missing expression error" . If I remove order by clause query executing fine.
    Here is my query:
    select *
    from emp_mstr
    where emp_no in(select
    emp_no
    from emp_mstr
    order by branch_no);
    Thanks & Regards,
    Mahi

    May be you miss some required spaces also, other than wrong use of ORDER BY
    select *
    from emp_mstr
    where emp_no in
         ( select e2.emp_no
           from emp_mstr e2
    --       order by e2.branch_no
         );Why do you want to ORDER BY in the subquery, which you use with IN clause? That will not make any difference in the result..Means the result you get with ORDER BY will be same as without that.. And in this case, ORDER by is a unncessary overhead.. And Ordering is very costly..
    And why do you want to have the IN clause at all in your query? You are referring the same tables in the main query and sub query..
    The below will give the same result
    select *
    from emp_mstr
    where emp_no is not nullIf you want to use another table in the subquery, always use aliasess...
    select *
    from emp_mstr
    where emp_no in
         ( select e2.emp_no
           from emp_mstr2 e2
    --       order by e2.branch_no
         );

  • Order by clause in discoverer custom folder

    hi,
    i m working on discoverer 3.1.38.I've been trying to sort the period according to calendar sequence and for this i tried 2-3 different queries which are working fine on sql plus but in discoverer custome folder,one error is coming saying ..can't use ORDER BY clause in custom folder.
    I've tried formatting option also but it doesn't work here with me as i preferably want to sort in MON-RR format.
    thanks in anticipation
    null

    thanks for replying back. but i didn't get what exactly u meant by creting query in user edition and about alternative sort,i should have list of value item and item_to_sort in same folder but i don't have that..i am creating one cross tab report and using to_char(gl_date,'MON-RR') format on my top axis its' appearing alphabetically over there,i wrote one qurey which worked prefecly fine on sql plus,but in discoverer its' giving me error.i can't create alternative sort on this,so please give me some different solution
    thanks in advance

  • ORDER BY clause in runtime

    Hi All,
    I want to order my SELECT using "dynamic ORDER BY". I have a CURSOR (in my PL/SQL procedure) contains a select with ORDER BY clause. I have implemented two combobox in my form (the first contains the column name, the second contains ASC and DESC).I tried with the next:
    1) Dynamic ORDER BY in CURSOR with combobox results. IT DOESN'T WORK.
    2) Using a block property named "ORDER BY CLAUSE". Here I put, for example, :myBlock.comboColumnOrder. IT DOESN'T WORK.
    3) Using a function: set_block_property(myBlock,order_by,:myBlock.comboColumnOrder) or set_block_property(myBlock,default_where,:myBlock.comboColumnOrder). IT DOESN'T WORK.
    4) Using dynamic CURSOR: ORACLE FORMS give me an error that said: "...it can't to the CLIENT-SIDE".
    I have thought my last solution, but it maybe cumbersome. I do a TEMPORARY TABLE, and my CURSOR insert in this TABLE, and then I'll fetch to my BLOCK.
    Thanks a lot.
    PS: My ORACLE Version is 10g.

    PROCEDURE CHEQUEAR_V0 IS
         V_ORDEN VARCHAR2(50) := '' || :BLOCK_CHECK.ORDER_BY_NAME || ' ' || :BLOCK_CHECK.ORDER_BY_ASC_DES ;
    CURSOR FILA_RESULTADO_TABLA IS
         SELECT Last_name,First_name,App_user, App_role, UserDB
         FROM adm_users
         WHERE
         ((Last_name IS NULL OR Last_name LIKE '%'||:BLOCK_CHECK.Last_name||'%') AND
         (First_name IS NULL OR First_name LIKE '%'||:BLOCK_CHECK.First_name||'%') AND
         (App_user IS NULL OR App_user LIKE '%'||:BLOCK_CHECK.App_user||'%') AND
         (App_role IS NULL OR App_role LIKE '%'||:BLOCK_CHECK.App_role||'%') AND
         (UserDB IS NULL OR UserDB LIKE '%'||:BLOCK_CHECK.User_DB||'%'))
    ORDER BY V_ORDEN;
         V_Last_name VARCHAR2(50);
         V_First_name VARCHAR2(50);
         V_App_user VARCHAR2(50);
         V_App_role VARCHAR2(50) ;
         V_User_DB VARCHAR2(50);
         CONT NUMBER ;
    BEGIN
         CONT := 1 ;
              GO_BLOCK('BLOCK_APPS_GRANTS');     
              CLEAR_BLOCK;
         SYNCHRONIZE;     
              OPEN FILA_RESULTADO_TABLA;
              LOOP
                   FETCH FILA_RESULTADO_TABLA INTO V_Last_name,V_First_name,V_App_user,V_App_role,V_User_DB ;
              EXIT WHEN FILA_RESULTADO_TABLA%NOTFOUND;
                        :BLOCK_APPS_GRANTS.Last_name := V_Last_name ;           
                        :BLOCK_APPS_GRANTS.First_name := V_First_name ;                               
                        :BLOCK_APPS_GRANTS.App_user := V_App_user ;
                        :BLOCK_APPS_GRANTS.App_role := V_App_role ;
                        :BLOCK_APPS_GRANTS.User_DB := V_User_DB ;                                         
                   NEXT_RECORD;
                   CONT := CONT+1;          
              END LOOP;
              IF FILA_RESULTADO_TABLA%ISOPEN THEN
                   CLOSE FILA_RESULTADO_TABLA;
              END IF;
              SET_BLOCK_PROPERTY('BLOCK_APPS_GRANTS', ORDER_BY, :BLOCK_CHECK.ORDER_BY_NAME || ' ' || :BLOCK_CHECK.ORDER_BY_ASC_DES);
              GO_BLOCK('BLOCK_APPS_GRANTS');
              EXECUTE_QUERY;
    synchronize;
              exception when others then
                   raise;
    END;
    Thanks a lot.
    Edited by: user11285646 on 22-jul-2009 2:30

  • Exception caused by bind variables in ORDER BY clause and VO RANGE_PAGING

    Hi,
    I'm using a ViewObject in RANGE_PAGING mode and discovered a problem when using bind variables in the ORDER BY clause of my statement:
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3 When a bind variable is used in the ORDER BY CLAUSE and the method VO.getEstimatedRowCount() is call then the DB issued an SQL error:
    java.sql.SQLException: Ungültiger Spaltenindex (eng.: invalid column index)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:137)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:174)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:239)
         at oracle.jdbc.driver.OraclePreparedStatement.setStringInternal(OraclePreparedStatement.java:4612)The numbering of the bind variables indicates that the last two bind variables have the wrong numbering (??)
    When I rewrite the SQL into the following statement, the SQL error does not occur but I have not verified yet that the VO delivers the correct range of data because the numbering of the bind variables is not correct.
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT *, decode (attr2, :1, 1, null, 0, -1) as ATTR_FOR_SORTING FROM T_TABLE WHERE (attr1 = :2) ORDER BY ATTR_FOR_SORTING  desc, attr3 ) IQ 
      WHERE ROWNUM < :2) WHERE Z_R_N > :3I'm working with JDev 10.1.2 and Oracle DB 9203.
    Any comments are welcome!
    Thanks,
    Markus

    You are using the bind variable :2 twice. Did you try
    SELECT * FROM (SELECT /*+ FIRST_ROWS */ IQ.*, ROWNUM AS Z_R_N FROM (
      SELECT * FROM T_TABLE WHERE (attr1 = :1) ORDER BY decode (attr2, :2, 1, null, 0, -1) desc, attr3 ) IQ 
      WHERE ROWNUM < :4) WHERE Z_R_N > :3
    setWhereClauseParm(0, "a"); // :1
    setWhereClauseParm(1, "b"); // :2
    setWhereClauseParm(2, "c"); // :3
    setWhereClauseParm(3, "b"); // :2setting the fourth parameter the same as the second one?
    I remeber reading something about using bind variables twice causing problems, but I#m not sure about it.

  • Sorting character column ( used in order by clause dynamically)

    Hi,
    I need help on sorting character-based numbers. Like say, I want to sort customers based on street numbers(which is a character string being used in the
    order by clause) they live in.
    The criteria are :
    i. Numbers must take precedence.
    This being a character string, 1000001 comes before 2. This shouldn't happen. And you cannot use to_number
    since using it with a string having characters in it would raise an error.
    ii. If only a single alphabet occurs as the last character, then treat the whole string as a number except the last character and then sort it
    as if sorting a number. Something like : if you have 1000A, 200D, 200B, 1000X, the result would be 200B,200D,1000A,1000X.
    iii. if a character occurs elsewhere in the string, then perform the search normally as if performing a character search.
    The output of the following data :
    100
    A101
    B100A
    110C
    C120B
    120
    100020
    120C
    C1100
    100D
    would be like :
    100
    100D
    110C
    120
    120C
    100020
    A101
    B100A
    C120B
    C1100
    Please note that the sort is being done dynamically, so I could have access to the values of the street numbers only during run time.
    Any help is really appreciated.
    Thanks in advance.
    Regards,
    Anil.

    Create a function to test whether the column is numeric :
    create FUNCTION is_numeric(v_number VARCHAR2)
    RETURN INTEGER
    IS
    l_number NUMBER;
    BEGIN
    IF INSTR(UPPER(v_number),'E') > 0 THEN
    RETURN 0;
    END IF;
    l_number := TO_NUMBER(v_number);
    RETURN 1;
    EXCEPTION
    WHEN OTHERS THEN
    RETURN 0;
    END;
    And try this query
    Assume the table name is TEST with column STREET
    select * from TEST
    order by case is_numeric(STREET) when 1 then LPAD(STREET,20, ' ') else STREET end
    Please make sure that 20 mentioned above is the column size for STREET.
    Hope this helps.
    -Nags

  • JPQL - No UPPER() in ORDER BY clause??

    I have created a NamedQuery and am attempting to order my returned collection using the ORDER BY clause, however, the specification asks for string ordering to be case insensitive. It seems that I cannot do that with the Java Persistence Query Language - or at least the implementation that we are using. I am using Glassfish v2ur2 with uses Oracle TopLink Essentials - 2.0.1, Build b04-fcs (found in my Exception message).
    I suspect that the only way to do what I want is to create a Comparator for the ResultList and run a sort after I get the result list from my EntityManager. Is that correct or is my syntax wrong in my JPQL?
    Here is my named query (cut from a larger list of named queries), pretty simple:
    @NamedQuery(name = "MyObject.findAll", query = "SELECT a FROM MyObject a ORDER BY UPPER(a.myString), a.Id")Here is a summary exception report that I receive:
    ===========================================================================
       Exception: javax.ejb.EJBException
       Description: nested exception is: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
            java.rmi.RemoteException: null; nested exception is:
            Exception [TOPLINK-8024] (Oracle TopLink Essentials - 2.0.1 (Build b04-fcs (04/11/2008))): oracle.toplink.essentials.excepti
    ons.EJBQLException
    Exception Description: Syntax error parsing the query [MyObject.findAll: SELECT a FROM MyObject a WHERE ORDER BY UPPER(a.myString), a.Id], line 1, column 81: syntax error at [UPPER].
    Internal Exception: line 1:81: expecting IDENT, found 'UPPER'
    (Stack-Trace Included)
    ===========================================================================

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

Maybe you are looking for

  • SQL query using Group by and Aggregate function

    Hi All, I need your help in writing an SQL query to achieve the following. Scenario: I have table with 3 Columns. There are 3 possible values for col3 - Success, Failure & Error. Now I need a query which can give me the summary counts for distinct va

  • Comment replies lost in Acrobat X on Windows 7

    Last month I upgraded from Windows Vista to Windows 7 and upgraded from Acrobat 9 to Acrobat X. I'm trying to do a very typical task (replying to reviewer comments on a PDF that I created last week). I imported comments from multiple PDFs into a sing

  • Need help with a email plugin I trying to create

    I modifed some sample code here problem I am having is figuring out how to get the image filename so I can create a loop code to create a comma delimited string of images to be sent to the external program. local LrDate = import 'LrDate' local LrFile

  • Use of Form Service ES2

    Hi, Is Form Service ES2 module best if i) need to generate pdf  (pdf that has Save button that user can click) from xml data and xdp template. ii) and also have to generate non interactive pdf from xml data and xdp template. ( or may be pdf in the fo

  • Problems : Payment conditions replication

    Hi, I have problem in business agreement and account contract replication between SAP CRM and SAP ISU. When I replicate a business agreement from CRM to ISU, it's (almost) OK, but terms of payment is not the same between CRM and ISU. When replicate a