Sorting the results returned by a Ref cursor

Hi All,
I have a scenario where i am asked to sort results returned by a ref cursor.
I have to pass the column to be sorted as the Input parameter to a stored procedure. I tried using 'order by sorting_parameter' in the ref cursor's select query, but it is not sorting the results. It is not throwing any error even.
Please help.
Many Thanks...

Hi
i came across the below reply for a thread with the similar query as above.
<<
Justin Cave
Posts: 10,696
From: Michigan, USA
Registered: 10/11/99
Re: sort data in ref cursor
Posted: Feb 3, 2005 10:30 AM in response to: [email protected] Reply
No. You could sort the data in the SQL statement from which the REF CURSOR was created, but once you have a REF CURSOR, you cannot do anything but fetch from it.
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC
>>
So, the results from a ref cursor cant be sorted?? There is no way out?
Kindly advise.

Similar Messages

  • Can the return from xsql:ref-cursor-function be saved & looped through XSQL?

    If <xsql:ref-cursor-function> returns one field for a number of rows, is there a way to save those values and loop through the data retrieved for other query process within XSQL? Any example?
    Thanks.
    null

    You have a couple of options.
    You can process the XML returned by <Xsql:ref-cursor-function> as the normal part of XSLT processing, or you can write a custom action handler that aggregates the action handler for <xsql:ref-cursor-function> and then uses DOM to operate on the return value.
    Search the Online XSQL Pages Documentation for the term "MyIncludeXSQLHandler" for some sample code that illustrates building a customer action handler that aggregates one of the built-in handlers.

  • Number of total rows returned by a ref cursor without using FETCH

    Hi. How can we get the total number of rows returned by a ref cursor without doing the FETCH? I mean, if you use %ROWCOUNT, it only returns the current row number being returned in every fetch. This is not what I want. My purpose is to determine if my query using ref cursor returns greater than zero total rows without using fetch. Thanks.

    As John pointed out in the thread you linked to, the only way to know how many rows a query will return is to actually fetch all the rows. Oracle doesn't know how many rows a query is going to return until it actually fetches the last row.
    Plus, assuming the default transaction isolation level, if you run the same query multiple times in succession, there is no guarantee that the results will be the same.
    If you just want to know whether a query will return a nonzero number of rows, why not just write the code to assume that it returns at least 1 row and handle the zero row result as an exception.
    Justin

  • How can I show all the results returned by a sql query?

    Hi guys,
    I need your help.
    Let's say I have one table: TableA. Fields of TableA are aleg, anon, apes. The following sentence can return, in general, several rows: select anon from TableA where aleg = somevalue. I'd like to show the result of column anon but no luck. If I try to show the results in a TextArea and the origin is an sql query only shows the first row value. I tried Show as: show as text (based in PLSQL) and coding an anonymous plsql block as
    DECLARE
    v_anon TableA.anon%TYPE;
    CURSOR v_cur IS
         select anon from TableA where aleg = somevalue;
    BEGIN
    OPEN v_cur;
    LOOP
    FETCH v_cur INTO v_anon;
    EXIT WHEN v_cur%NOTFOUND;
    :FIELD_IN_FORM := v_anon;
    END LOOP;
    CLOSE v_cur;
    END;
    but in this case it's not shown any result.
    So the first question is what kind of field should I use to show the result. And the second one is what can I do to being able to show all the results returned by the query (provided that is more than one single row).
    regards

    Hi Denes,
    Just starting with apex. I think I know how to show the results in a report region. I've simplified the posted question.
    A more detailed question would be: Suppose you have a region where you have put several text areas to accommodate the result of a multi-column query (lets say for TableA) that only returns one row, each column value returned put in a different text area. Also you want to show the values of other fields in TableB that depends on some value just retrieved from TableA and that you want all values retrieved (from TableA and the linked TableB) to be show in the same region. Is that possible? If yes, how?
    Thank you in advance

  • Custom Search portlet : how to sort the result in sequence (Portal 10.1.4)

    With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
    Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
    Is there an action to add the "Sequence" Order By result Option?
    Great thanks for your kind help.
    Best regards

    No, I agree that it is functionality that should be added to the product, but it
    is not a bug because it was not written to do this.
    It is a short coming of the product.
    Cheers,
    Ersan

  • How to create a procedure function with a return value of ref cursor?

    Can anybody provide a sample about how to create a procedure function with a return value of REF CURSOR?
    I heard if I can create a function to return a ref cursor, I can use VB to read its recordset.
    Thanks a lot.

    http://osi.oracle.com/~tkyte/ResultSets/index.html

  • I've found no way to sort.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results.

    I've found no way to sort search results in itunes.  For example, if I type the group "Rush" into the search bar, I get a list of songs recorded by rush and literally thousands of other songs and artists with the word rush in them. There is; however, no way to sort the results. 

    In the Search box click on the black Arrow and UNTICK the Search Entire Library.
    Then the Search results in Songs view will be displayed in the main Grid and you can sort them by clicking on the column headers.
    You can also turn on the column browser which can help with filtering

  • Custom Search Portlet : How to Sort the Result By Sequence (Portal 10.1.4)

    Customer request: With a Custom Search portlet how to Sort the Result By Sequence. i.e. by respecting arrangements of the items in the page of contents?
    (Like it's possible in MyOracle)
    Actually the Results Options "Order By" are : Create Date, Author, Creator, Date Updated, Display Name, Last Update by, Publish Date, Score.
    Is there an action to add the "Sequence" Order By result Option?
    Great thanks for your kind help.
    Best regards

    No, I agree that it is functionality that should be added to the product, but it
    is not a bug because it was not written to do this.
    It is a short coming of the product.
    Cheers,
    Ersan

  • Sorting the result set return by EXTRACT for  XMLTYPE

    What is the best way to order the output return by extract?
        My SELECT statement:
         SELECT
                regexp_replace(regexp_replace(extract(xmltype(t.message_xml), '//Event'),'<Event>',''),'</Event>',',')
                FROM SUB_XML T
                Current output: EVT_B3_TRAN,EVT_B3_PROD,EVT_B3_FX,EVT_B3_ACC,EVT_B3_PRICE
                Required output: EVT_B3_ACC,EVT_B3_FX,EVT_B3_PROD,EVT_B3_PRICE, EVT_B3_TRAN

    Please post your example data so that people can help you.
    You would be better to extract the contents of the XML using the XMLTABLE functionality, rather than an extract with regexp_replace string functions.  Treat the XML as XML, not as strings.
    Example:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<XML>
      2    <Event>EVT_B3_TRAN</Event>
      3    <Event>EVT_B3_PROD</Event>
      4    <Event>EVT_B3_FX</Event>
      5    <Event>EVT_B3_ACC</Event>
      6    <Event>EVT_B3_PRICE</Event>
      7  </XML>') as xml from dual)
      8  --
      9  -- end of example XML
    10  --
    11  select listagg(event,',') within group (order by rn) as events
    12  from (
    13        select x.event
    14              ,row_number() over (order by x.event) as rn
    15        from   t
    16              ,xmltable('/XML/Event'
    17                        passing t.xml
    18                        columns event varchar2(20) path '.'
    19                       ) x
    20*      )
    SQL> /
    EVENTS
    EVT_B3_ACC,EVT_B3_FX,EVT_B3_PRICE,EVT_B3_PROD,EVT_B3_TRAN

  • What are the advantages to using a REF cursor

    When would I want to use a REF cursor?

    REF CURSORs are not cursors, they're references to cursors. This means they're dynamic. So you can completely change the query executed by the cursor.
    For example you can use a REF CURSOR to select from one of a number of tables (depending on an input parameter or other sort of flag). The results are fetched into the same resultset holder and hence you only need a single lot of code to process the results.
    Also you can also pass a REF CURSOR as a argument to other PL/SQL procedures and functions.
    rgds, APC

  • What is the better approach to populate Ref cursor into ADF business Component

    HI All,
    I have a requirement where I get the search results by joining more than 10 tables for my search criteria.
    What is the best approach to populate into ADF BCs.
    I have to go with Stored Procedure approach where I input the search Criteria and get the cursor back from the same.
    If I populate VO programmatically then the filtering at column level is a challenge.
    Anyone Please help me. Thanks in Advance.
    Thanks,
    Balaji Mucheli.

    The number of tables to be joined for a VO's query shouldn't matter - if the query is valid and fixed.
    Are you saying that you have logic to decide which tables to join to create the correct query?  I admit that would be a difficult thing to do, other than with a programmatic VO.  However, there are two possible solutions for doing this without a programmatic VO.
    Instead of your procedure returning a REF CURSOR, you can create an object type (CREATE TYPE) and a nested table of that type.  Then you have a function that returns an instance of the nested table.  The query in the VO is SELECT my_column... FROM TABLE(CAST my_table_function(:bind_variable) AS my_table_type).  You may have trouble getting the VO to accept this query as valid SQL, but it IS valid and it DOES work.
    Create a VO to be the master VO - it should have all the attributes that you intend to use, but the query can be anything, even a SELECT from DUAL.  Then create other VOs that subclass the master VO - one for each major variation of the query.  When you use the VO, use the data control for the master VO to create your pages, but change the pageDef to make the VO name a variable (with expression language).  Then you can set that variable to the correct child VO for the query that needs to execute.

  • Multiple SELECTS returned to a REF CURSOR

    Hi there
    I have a query regarding returning a REF Cursor from multiple selects and any input/hints would be greatly appreciated.
    Basically, I have a select(from multiple tables) that returns a set of rows(query 1) and another (from multiple tables) that returns a set of data that needs to be appended to the results from query 1. Initially my thoughts were to join the queries using an inline view. This returns the correct number of rows but as there is only 1 field I can use to join the queries it is very inefficient and takes forever to execute.
    So, I’ve there for had to rethink my design but have hit a brick wall – so to speak!
    Is it possible to use one cursor for each query and return the results in 1 ref cursor?
    I’m thinking I would need something like the following: -
    Cursor 1 is
    Select a.quote, b.name,c.price from table a,b,c
    Cursor 2 (cursor 1.quote IN)
    Is
    Select * from table d,e,f
    Where d.quote = cursor1.quote
    What I need to output in the ref cursor is as follows: -
    For each record returned from query 1, return the data from query 2.
    Many thanks in advance
    ps I'm using 9i

    Do UNION or UNION ALL work on your version of Oracle? <g>

  • Return XML from REF CURSOR

    It appears to be fairly straight-forward to get XML from a SQL query using the XML SQL Utility.
    Is it possible to use this utility (or another) to get XML from a cursor variable as well? I would like to generate overloaded get_xml functions in a PL/SQL package that will accept either SQL or a weak type REF CURSOR and return XML.

    Thanks for the help. Actually, I just bought your book and was getting ready to do some research. This should get me pointed in the right direction.
    Does the PL/SQL API lack this functionality? I wasn't sure whether to implement this in PL/SQL or Java, but the decision may be made for me...

  • How to clear the run time error in ref cursor

    good morning every one,
    the code as follows
    create or replace
    procedure Country_sel(key in varchar2)
    as
    cc Res_RelcountryLan.countrycode%type;
    len Res_Language.langname_en%type;
    lid Res_Language.langid%type;
    ab Res_Language.Abrivation%type;
    type refcursorr is ref cursor;
    cur refcursorr;
    d_stmt varchar2(100);
    begin
    d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',
    RL.Abrivation from  Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId';
    open cur for d_stmt;
    loop
    fetch cur into cc,lid,len,ab;
    if cur%found then
    dbms_output.put_line(cc||lid||len||ab);
    else
    exit;
    end if;
    end loop;
    close cur;
    commit;
    end  Country_sel;when i am running this code im getting
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    ORA-06512: at "RASOOL.COUNTRY_SEL", line 11
    ORA-06512: at line 6can you please help me in getting rid of this problem.
    thanking you,
    prakash

    d_stmt varchar2(100); Increase the size of d_stmt. Your a assigning a larger string
    d_stmt := 'select RCL.countrycode,RL.langid,RL.langname_'||key||',RL.Abrivation from  Res_RelCountryLan RCL inner join Res_Language RL ON RCL.LangId = RL.LangId'; The size of the above string is more than 100 characters.

  • Sorting the results of CONNECT BY query

    Hi,
    I have a table with following columns and values:
    DIS_PARENT_OID OID CREATION_TIME LEVEL
    0 26750 08/02/2001 14.52.14 1
    0 26751 08/02/2001 14.52.48 1
    26751 26752 08/02/2001 14.53.39 2
    0 26753 08/02/2001 14.53.54 1
    0 26722 08/02/2001 13.58.04 1
    26722 26723 08/02/2001 13.58.16 2
    26723 26724 08/02/2001 13.58.29 3
    26724 26725 08/02/2001 13.58.41 4
    26725 26726 08/02/2001 13.58.54 5
    26726 26727 08/02/2001 13.59.05 6
    26727 26728 08/02/2001 13.59.15 7
    26728 26729 08/02/2001 13.59.26 8
    26729 26730 08/02/2001 13.59.40 9
    26730 26731 08/02/2001 13.59.51 10
    26731 26732 08/02/2001 14.00.05 11
    26732 26733 08/02/2001 14.00.16 12
    26733 26734 08/02/2001 14.00.26 13
    26734 26735 08/02/2001 14.00.37 14
    26735 26736 08/02/2001 14.00.48 15
    26736 26737 08/02/2001 14.01.00 16
    26737 26738 08/02/2001 14.01.19 17
    And I used a query to fetch this tree structure like :
    SELECT PRIOR PARENTID,ID,CREATION_TIME,LEVEL
    FROM FORUM
    START WITH PARENTID=0
    CONNECT BY PRIOR OID=PARENTID;
    Result:
    DIS_PARENT_OID OID CREATION_TIME LEVEL
    0 26722 08/02/2001 13.58.04 1
    26722 26723 08/02/2001 13.58.16 2
    26723 26724 08/02/2001 13.58.29 3
    26724 26725 08/02/2001 13.58.41 4
    26725 26726 08/02/2001 13.58.54 5
    26726 26727 08/02/2001 13.59.05 6
    26727 26728 08/02/2001 13.59.15 7
    26728 26729 08/02/2001 13.59.26 8
    26729 26730 08/02/2001 13.59.40 9
    26730 26731 08/02/2001 13.59.51 10
    26731 26732 08/02/2001 14.00.05 11
    26732 26733 08/02/2001 14.00.16 12
    26733 26734 08/02/2001 14.00.26 13
    26734 26735 08/02/2001 14.00.37 14
    26735 26736 08/02/2001 14.00.48 15
    26736 26737 08/02/2001 14.01.00 16
    26737 26738 08/02/2001 14.01.19 17
    0 26750 08/02/2001 14.52.14 1
    0 26751 08/02/2001 14.52.48 1
    26751 26752 08/02/2001 14.53.39 2
    0 26753 08/02/2001 14.53.54 1
    It fetches the rows in tree structure, but i need them order by creation_time desc with group by the tree structure (the level structure need not be sorted - only the latest message should be on top ). But if I used the order by creation_time desc this qry fetches the rows in reverse tree structure.
    The query should fetch the rows
    ORDER BY creation_time DESC and GROUPED BY tree.
    Expected Result:
    DIS_PARENT_OID OID CREATION_TIME LEVEL
    0 26753 08/02/2001 14.53.54 1
    26751 26752 08/02/2001 14.53.39 2
    0 26751 08/02/2001 14.52.48 1
    0 26750 08/02/2001 14.52.14 1
    0 26722 08/02/2001 13.58.04 1
    26722 26723 08/02/2001 13.58.16 2
    26723 26724 08/02/2001 13.58.29 3
    26724 26725 08/02/2001 13.58.41 4
    26725 26726 08/02/2001 13.58.54 5
    26726 26727 08/02/2001 13.59.05 6
    26727 26728 08/02/2001 13.59.15 7
    26728 26729 08/02/2001 13.59.26 8
    26729 26730 08/02/2001 13.59.40 9
    26730 26731 08/02/2001 13.59.51 10
    26731 26732 08/02/2001 14.00.05 11
    26732 26733 08/02/2001 14.00.16 12
    26733 26734 08/02/2001 14.00.26 13
    26734 26735 08/02/2001 14.00.37 14
    26735 26736 08/02/2001 14.00.48 15
    26736 26737 08/02/2001 14.01.00 16
    26737 26738 08/02/2001 14.01.19 17
    please suggest a solution
    thanks,
    Satheesh
    null

    The sorting variable is always the first item in the cluster.  When you sort an array of clusters, it sorts by the first item in the cluster.  If there are two identical values in the first item, it sorts by the second item, and so on.
    When you build your cluster, you want to put the items into the cluster in the sequence that you want to sort them by.  For example, if I was sorting names, I would put the last name as the first item in the cluster, then the first name, then any other information I want to keep with the name when I sort it, such as phone number, address, etc.
    Bruce
    Bruce Ammons
    Ammons Engineering

Maybe you are looking for