Restricting on a cursor result

Task:
1. I would like to make reports for a system.
2. I want to make the reports with an out sys_refcursor
3. I want to pass in some cursor with ids, to restrict report.
So here's the code I got so far:
procedure customer_status_distribution(c_universe sys_refcursor,
t_result out sys_refcursor) is
v_table_of_number table_of_number;
begin
fetch c_universe bulk collect
into v_table_of_number;
open t_result for with a as(
select column_value column_value
from table(cast(v_table_of_number as table_of_number)))
select t.alder, count(*)
from customer_aggregation t
where customer_id in(select column_value from a)
group by t.alder;
end;
c_universe is containing just numbers of course.
The problem with this is that it doesn't use the index on customer_aggregation.customer_id column.
I can add /*+RULE*/ and it uses the index, but I do not want that, since the actual reports are quite more complex, and will use different technuiqes for optimizing.
exists() clause does not use index.
/*+ index(customer_aggregation name_of_index)*/ doesn't do it.
Am I going about this the wrong way? Any ideas?

Following code:
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select t.alder, count(*)
from customer_aggregation t
where exists(select * from table(cast(v_table_of_number as table_of_number)) where column_value = t.customer_id)
group by t.alder;
gives:
SELECT STATEMENT      12176732          
SORT GROUP BY     12176732     1     9
NESTED LOOPS SEMI     12176729     1     9
TABLE ACCESS FULL -> CUSTOMER_AGGREGATION     1457     1521909     13697181
COLLECTION ITERATOR PICKLER FETCH          
Rewrite using in:
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select t.alder, count(*)
from customer_aggregation t
where t.customer_id in(select column_value from table(cast(v_table_of_number as table_of_number)))
group by t.alder;
gives:
SELECT STATEMENT      12176732          
SORT GROUP BY     12176732     1     9
NESTED LOOPS SEMI     12176729     1     9
TABLE ACCESS FULL -> CUSTOMER_AGGREGATION     1457     1521909     13697181
COLLECTION ITERATOR PICKLER FETCH               
Rewrite to use hints and "in":
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select /*+index(t PK_AGGR_CUSTOMER_ID)*/ t.alder, count(*)
from customer_aggregation t
where t.customer_id in(select column_value from table(cast(v_table_of_number as table_of_number)))
group by t.alder;
end;
gives:
SELECT STATEMENT      12211234          
SORT GROUP BY     12211234     1     9
NESTED LOOPS SEMI     12211231     1     9
TABLE ACCESS BY INDEX ROWID -> CUSTOMER_AGGREGATION     35959     1521909     13697181
INDEX FULL SCAN -> PK_AGGR_CUSTOMER_ID     11354     1521909     
COLLECTION ITERATOR PICKLER FETCH               
Rewrite using index hint and "exists":
fetch c_universe bulk collect
into v_table_of_number;
open t_result for
select /*+index(t PK_AGGR_CUSTOMER_ID)*/ t.alder, count(*)
from customer_aggregation t
where exists(select column_value from table(cast(v_table_of_number as table_of_number)) where column_value = t.customer_id)
group by t.alder;
gives:
SELECT STATEMENT      12211234          
SORT GROUP BY     12211234     1     9
NESTED LOOPS SEMI     12211231     1     9
TABLE ACCESS BY INDEX ROWID -> CUSTOMER_AGGREGATION     35959     1521909     13697181
INDEX FULL SCAN -> PK_AGGR_CUSTOMER_ID     11354     1521909     
COLLECTION ITERATOR PICKLER FETCH               
Finally, what I want is (explain plan wise):
the code posted using a tmp_numbers table:
which gives:
SELECT STATEMENT      10          
SORT GROUP BY     10     1     22
TABLE ACCESS BY INDEX ROWID -> CUSTOMER_AGGREGATION     3     1     9
NESTED LOOPS      8     1     22
SORT UNIQUE               
TABLE ACCESS FULL -> TMP_NUMBERS     2     1     13
INDEX RANGE SCAN -> PK_AGGR_CUSTOMER_ID (1)     2     1     
Suggestions?

Similar Messages

  • Stored procedure that returns a cursor (result set)

    Hi,
    We have a stored procedure that returns a cursor (result set) but when I compliled it and catalouged (introspected) it in the OBPM I got all the primitive type parameters (either IN or OUT) in the proc call except the cursor type (the result set) which is the out param of the stored proc.
    Any pointers please?
    Thanks

    Result set is of RowType and is not supported as a Stored Procedure as far as I know.
    HTH
    Sharma

  • EA2 : Cursor result support?

    I have been eagerly anticipating the release of 1.5 in the hope that cursor results would have support. I have been scouring the forums and have found mention of them but nowhere is there a definitive explanation of how to view the cursor results. Please bear in mind that we have strict controls over packages and schemas and the creating and compiling of "helper" procedures just to output cursor results is heavily frowned upon. Other than that I am a current PL/SQL Develper and am trying desperately to get off windows and onto Linux completely and your product has given me a glimpse of light at the end of the tunnel. Keep up the awesome work

    Okay guys, looks like we're getting our lines crossed. I am currently using PL/SQL developer and it has a very nice testing interface for procedures which return cursors as their results. You simply execute the procedure and then click on the cursor parameter and it opens up, as a table ( similar to the standard query results view ) and you can scroll through it as you would a normal query result.
    I am using 1.5 Early Adopter 2 (1.5.0.52.03).
    All I wanted to know is if there is/will be similar support for cursors in SQL Developer as there is in PL/SQL Developer, and if there already is ( and I mean built in support, not some workaround ) how to I get it/use it/see it??
    thanks
    Mark
    P.S. Still in awe of this free software...

  • Cursor result count

    Hi,
    I've a staging table with one column
    result_id :100,101,102 etc
    I need to query another table say stage2 which consists of many columns including result_id
    so If I found result id in stage 2 then I want to update that table flag enable_flag=y and give a count in a log file say : no of records updated
    If I won't find id in table2 , I've to move on with other ids by putting a message in a log file says :'This id has no value in stage2'
    and provide count :no of ids don't have any value:
    Any simple and efficent way of doing this ?
    Thanks,
    Kiran

    >
    say in stage1 If I've an id 191 which is not there in stage 2 Then I need to put that in logifile
    >
    Are you saying that if IDs 191, 192 and 193 are not in the stage 2 table you need to log a separate count for each ID?
    If so then you should add a query to Solomon's code that executes before the UPDATE statement.
    The query would get IDs from STAGE1 and a count of the number of those IDs that are in STAGE2. You would use these results to do the logging that you want to do. Then you would do the update shown in Solomon's code.
    SELECT S1.RESULT_ID, COUNT(S1.RESULT_ID) ID_COUNT
    FROM STAGE1 S1, STAGE2 S2
    WHERE S1.RESULT_ID (+) = S2.RESULT_ID
    GROUP BY S1.RESULT_IDThe result set records with a count of zero are the IDs that are not in the STAGE2 table. The other records have the count of how many records will get updated.
    You can use the above query as a cursor to do logging.

  • Running queries against cursor results?

    I'm running a cursor in a stored procedure, and the query itself is dependent on one of the parameters passed to the SP. So, for example:
    create procedure annoying as
    SQLString varchar2(50);
    myCursor Types.cursorType; -- defined elsewhere in pkg.
    begin
    if parameter = 1 then SQLString = "select x,y from table1";
    if parameter = 2 then SQLString = "select x,z from table2";
    open myCursor for SQLString;
    At this point, I need to run a further query against the result set from the cursor. I have no clue how to proceed with this. Am I barking up the wrong tree? Should I be looking for a different solution?

    Instead of looping through a cursor and comparing the values of x, use the entire select statement that you would have used for the cursor as an inline view (select statement in the from clause) in your subsequent cursor and join via x. Please see the example below. You can continue this nesting for as many levels as required. For example, instead of opening the ref cursor for sqlstring2, you could use that as an inline view in another sqlstring3 and open the ref cursor for sqlstring3.
    scott@ORA92> create or replace package types
      2  as
      3    type cursortype is ref cursor;
      4  end types;
      5  /
    Package created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> create or replace procedure annoying
      2    (parameter in  number,
      3       myCursor  out Types.cursortype)
      4  as
      5    SQLString  varchar2(50);
      6    sqlString2 varchar2(4000);
      7  begin
      8    if parameter = 1 then SQLString := 'select deptno x, dname y from dept';
      9    elsif parameter = 2 then SQLString := 'select deptno x,loc z from dept';
    10    end if;
    11    sqlstring2 := 'select e.empno, d.*
    12                  from   emp e,
    13                      (' || sqlstring || ') d -- inline view
    14                  where e.deptno = d.x';
    15    open myCursor for SQLString2;
    16  end annoying;
    17  /
    Procedure created.
    scott@ORA92> show errors
    No errors.
    scott@ORA92> variable g_ref refcursor
    scott@ORA92> execute annoying (1, :g_ref)
    PL/SQL procedure successfully completed.
    scott@ORA92> print g_ref
         EMPNO          X Y
          7934         10 ACCOUNTING
          7839         10 ACCOUNTING
          7782         10 ACCOUNTING
          7902         20 RESEARCH
          7876         20 RESEARCH
          7788         20 RESEARCH
          7566         20 RESEARCH
          7369         20 RESEARCH
          7900         30 SALES
          7844         30 SALES
          7698         30 SALES
          7654         30 SALES
          7521         30 SALES
          7499         30 SALES
    14 rows selected.
    scott@ORA92> execute annoying (2, :g_ref)
    PL/SQL procedure successfully completed.
    scott@ORA92> print g_ref
         EMPNO          X Z
          7934         10 NEW YORK
          7839         10 NEW YORK
          7782         10 NEW YORK
          7902         20 DALLAS
          7876         20 DALLAS
          7788         20 DALLAS
          7566         20 DALLAS
          7369         20 DALLAS
          7900         30 CHICAGO
          7844         30 CHICAGO
          7698         30 CHICAGO
          7654         30 CHICAGO
          7521         30 CHICAGO
          7499         30 CHICAGO
    14 rows selected.

  • Restricting views of search results in E-recruiting

    Hello Experts,
    I have a requirement in my project to restrict the visibility of search results when users run search queries to look for applications. The system should be masking the applications of the user's reporting managers, directors or VPs when they apply for internal job postings or anyone above the hierarchy level in the Org structure. There is no structural authorization provided in TREX search by SAP. I understand that the talent pool is a global talent pool with all internal and external applications, but I need to cater to this requirement somehow.
    Any inputs would be of great help!!!
    Thanks
    Srini.

    Hi srini,
    i am not really getting the concept of your requirement.
    Candidates cannot see other candidates applications. Managers only see the applications forwarded to them so it is no issue to restrict anything as it would be HR task to controll forwarding candidates but still how often does it happen that a hiring managers superior is applying to a job below the manager as managers usually hire subordinates.
    So only recruiters are effected. On centralized recruiting organizations recruiters would not be allowed to see applications of hr manager hierarchy - ok might be an issue, while all other departments are no problem. From my experience this is usually handled outside the system exactly because of the problems implicated by that.
    In decentralized hr organizations we have a similar situation like in the managers case. the decentalized recruiter is working for an department so he only handles applications for this department. Employees in higher hierachy levels will probably not apply for the job the recruiter is responsible.
    Could you please give some more background information on what you exactly try to achieve, this will probably help to answer your question.
    Known points in the e-recruiting application I met in my projects were the listed applications in data overviews for the same candidate. Managers should not see that an internal applicant has applied for several other positions over the time so he treats all applicants equally and managers won't start chatting "hey bro, I saw mr. xy already applied in your department last month, you did not hire him, what's wrong with that guy? is he stealing copy paper?". but this can be easily handled by propper data overview design.
    Another difficult issue is the candidate overview were a recruiter can see all applications of a candidate. Here the reason is also equal opportunities for all internal candidates. Trouble here is the difficulty that hiding results in the loss of information which prevents internal overbidding (a candidate who has two offers on two applications in the same company using this to push salary offers). This one is tricky and has to be decided very carefully.
    But as you see both cases are dealing with applications of the same candidate not a candidate in general.
    So please check if you can give some more details on the requrements.
    Best regards
    Roman

  • Is it possible to ref cursor(result set) as in parameter to procedure/funct

    Hi,
    I am getting a resultset/ref cursor from the Java side to the procedure/function as in parameter. Is this possible in oracle 10g.
    If yes can body send the links/suggestions describing some examples.
    Thanks,

    I am getting a resultset/ref cursor from the Java
    side to the procedure/function as in parameter. Is
    this possible in oracle 10g. It is possible, but it sounds like you have your application design entirely backwards.
    A ref cursor is designed to be used to pass a result set from a stored procedure to a client or calling application.
    So while you could use a screwdriver to hammer in a nail, you probably would not want to.

  • HT201304 Turning restrictions on then off resulting in duplicate TV shows

    I search the forums, but didn't see a solution to this issue, though there were other posts along this line:
    On my iPad, 3rd generation, with iOS 7.1 installed (and even before, with 7.0.6)...
    When I have videos downloaded to the Videos app (such as TV shows), and then I turn on restrictions to not allow TV shows, then I turn the restrictions off again.. the TV show episode all show duplicates.  This is when I view them with iTunes match enabled.  In addition, the episodes that I had already downloaded show up as not downloaded/available on the iPad.  And, if I select to download an episode from the cloud, all duplicates show as downloading.
    This wouldn't really be a big deal, but apparently, the episodes seem to take up more space, as if I am actually downloading duplicate copies.  In addition, the episodes that were downloaded prior to turning on restrictions still seem to take up memory space, as indicated by my overall memory usage (but the videos app itself does not show up as using much memory).
    How do I report this as an issue, in hopes that it is fixed someday?  The restrictions are useful for when, for example, I want to temporarily restrict access to TV shows for my children while allowing them to use other apps on the iPad.

    Thanks, Winston C, I've actually tried everything you suggested. I'm thinking now that the Home Sharing problem likely is related to Bonjour--I've seen several people mention this with similar (but not identical) problems. The solution that seems to work for some people is to uninstall and reinstall Bonjour. Frankly, I don't want to go through the trouble given that the iOS 7 release is imminent.
    One thing that I haven't tried is resetting the ATV to factory settings. I'll give that whirl.
    Thanks for your advice!

  • Procedure output cursor result insert to new table

    Hi all,
    Is there has any method to complete following task,
    CREATE OR REPLACE
    PROCEDURE sp1(
    cv_1 OUT sys_refcursor)
    AS
    BEGIN
    OPEN cv_1 FOR SELECT OBJECT_NAME FROM USER_OBJECTS;
    END;
    CREATE TABLE TEST1(OBJECT_NAME VARCHAR2(100));
    var cv_1 refcursor;
    INSERT INTO TEST1(OBJECT_NAME)
    EXEC sp1(:cv_1);
    Note: need solution apart from insert records to above table with-inside the procedure.
    Thanks
    Tharindu Dhaneenja

    Your code will not work anyway. You need to go through the SQL and PL/SQL basics again. It's always better to use pure SQL (if possible) instead of PL/SQL. You can try to insert using something like
    INSERT INTO TEST1 SELECT OBJECT_NAME FROM USER_OBJECTS;

  • Who's Who - Restrict Result List

    Dear,
    My problem today is that my Who's Who displays all the positions from the backend in the result list.
    For example, if Mr X was in entity A til end of Dec07 and then he changed position and was in entity B. Then Who's who displayed all the results.
    That is to say, i have two records for Mr X in SAP so both records are displayed in my who's who.
    > My question is then the following: how to restrict who's who result? So that i can have only the current record in my result list and NOT ALL the records???
    Thanks a lot
    Regards,
    Cyrielle

    Tim is correct with one rider. If you add a group to the list it will unpack the group membership EXCEPT where the users are members by virtue of it being their primary group.
    Therefore, you can give read and/or write permission to a large group of individuals without including them in the mailing list.
    Note, Apple defaults to putting everyone into GUID 20. So you have to make changes to the users if you want any selectivity, but it works.

  • How to hold result of query with too many characters into a cursor?

    Hi, guys:
    Could anyone help me on this issue? I encounter such a error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small. The reason is because the returning result is too big to hold in a cursor. I know I should use clob, how can I return result of a query into a clob?
    Here is my code of procedure
    function Find_Near_Offenders(P_f_Resident_Latitude in float, P_f_Resident_Longitude in float, P_n_Radius in number, P_s_User_Group in varchar2, P_b_Found out boolean) return rcur_Offender AS
        rcur_Offender_address rcur_Offender;
      begin
        if P_s_User_Group='Public' then
            open rcur_Offender_address for
              select distinct  so.offender_id as "Offender_ID",  so.first_name||' '|| so.middle_name||' '||so.last_name as "Offender_Name",
              replace(replace(nvl2(sl.address1, sl.address1||' '||sl.address2 ||' '||sl.city ||' '||sl.county||' '||(select sc3.description from sor_code sc3 where sc3.code_id=sl.state)||' '||sl.zip, 'No Known Address'),'#') ,',') as "Address",
              replace(replace(nvl2(sl.physical_address1,sl.physical_address1||' '||sl.physical_city ||' '||sl.physical_county||' '||(select sc4.description from sor_code sc4 where sc4.code_id=sl.physical_state)||' '||sl.physical_zip, 'No Known Address'),'#') ,',')  as "Physical_Address",
              nvl2(sl.ADDRESS_LATITUDE, to_char(sl.ADDRESS_LATITUDE)||','||to_char(sl.address_longitude),'') as "Address_Geocoding",
              nvl2(sl.physical_address_latitude,to_char(sl.physical_address_latitude) ||','||to_char(sl.physical_address_Longitude),'') as "Physical_Geocoding"
              from sor_location sl, sor_offender so, sor_offense sof, registration_offender_xref rox, sor_last_locn_v sllv
              where rox.offender_id=so.offender_id
              and sllv.offender_id(+)=so.offender_id
              and sl.location_id(+)=sllv.location_id
              and sof.offender_id=so.offender_id
              and rox.status not in ('Merged')
              and rox.reg_type_id=1
              and upper(rox.status)='ACTIVE'
              and nvl(rox.admin_validated, to_date(1,'J'))>=nvl(rox.entry_date, to_date(1,'J'))
              --and sl.physical_address_latitude is null
              and sl.ADDRESS_LATITUDE <=to_number(P_f_Resident_Latitude)+0.02*to_number(P_n_Radius) and sl.ADDRESS_LATITUDE>= to_number(P_f_Resident_Latitude)-0.02*to_number(P_n_Radius)
              and sl.address_longitude >=to_number(P_f_Resident_Longitude)-0.02*to_number(P_n_Radius) and  sl.address_longitude<=to_number(P_f_Resident_Longitude)+0.02*to_number(P_n_Radius)
              and sor_google_map_service.Calculate_Distance(P_f_Resident_Latitude, P_f_Resident_Longitude, sl.ADDRESS_LATITUDE, sl.address_longitude)<=P_n_Radius
              union
              select distinct  so.offender_id as "Offender_ID",  so.first_name||' '|| so.middle_name||' '||so.last_name as "Offender_Name",
              replace(replace(nvl2(sl.address1, sl.address1||' '||sl.address2 ||' '||sl.city ||' '||sl.county||' '||(select sc3.description from sor_code sc3 where sc3.code_id=sl.state)||' '||sl.zip, 'No Known Address'),'#') ,',') as "Address",
              replace(replace(nvl2(sl.physical_address1,sl.physical_address1||' '||sl.physical_city ||' '||sl.physical_county||' '||(select sc4.description from sor_code sc4 where sc4.code_id=sl.physical_state)||' '||sl.physical_zip, 'No Known Address'),'#') ,',')  as "Physical_Address",
              nvl2(sl.ADDRESS_LATITUDE, to_char(sl.ADDRESS_LATITUDE)||','||to_char(sl.address_longitude),'') as "Address_Geocoding",
              nvl2(sl.physical_address_latitude,to_char(sl.physical_address_latitude) ||','||to_char(sl.physical_address_Longitude),'') as "Physical_Geocoding"
              from sor_location sl, sor_offender so, sor_offense sof, registration_offender_xref rox, sor_last_locn_v sllv
              where rox.offender_id=so.offender_id
              and sllv.offender_id(+)=so.offender_id
              and sl.location_id(+)=sllv.location_id
              and sof.offender_id=so.offender_id
              and rox.status not in ('Merged')
              and rox.reg_type_id=1
              and upper(rox.status)='ACTIVE'
              and nvl(rox.admin_validated, to_date(1,'J'))>=nvl(rox.entry_date, to_date(1,'J'))
              and sl.physical_address_latitude <=to_number(P_f_Resident_Latitude)+0.02*to_number(P_n_Radius) and sl.physical_address_latitude>= to_number(P_f_Resident_Latitude)-0.02*to_number(P_n_Radius)
              and sl.physical_address_Longitude >=to_number(P_f_Resident_Longitude)-0.02*to_number(P_n_Radius) and  sl.physical_address_Longitude<=to_number(P_f_Resident_Longitude)+0.02*to_number(P_n_Radius)
              and sor_google_map_service.Calculate_Distance(P_f_Resident_Latitude, P_f_Resident_Longitude, sl.physical_address_latitude, sl.physical_address_Longitude)<=P_n_Radius;
            return rcur_Offender_address;
          end if;
      end;and my anonymous block is:
    declare
      query_result json_list;
      --list_string varchar2(32000);
      list_string clob;
      l_cursor sor_google_map_service.rcur_Offender;
      b_found boolean;
    begin
        l_cursor:=sor_google_map_service.find_near_offenders(35.5113030,-97.5543081, 3, 'Public', b_found);
        query_result:=json_util_pkg.ref_cursor_to_json(l_cursor);
        list_string:='{"Offenders": '||json_printer.pretty_print_list(query_result)||'}';
        dbms_output.put_line(list_string);
    end;

    lxiscas wrote:
    I checked the PL_JSON, and I found it uses sys_refcursor, which is limited to 32K around. That doesn't make sense. A SYS_REFCURSOR has no 32k limit-- the limits are related to the data types that the SQL statement that the SYS_REFCURSOR points to uses. If that SQL statement has a CLOB column, there is effectively no limit. If that SQL statement has a VARCHAR2 column, you've got the 4000 byte limit.
    and I was using varchar2 variable in anonymous block. However, my cursor result is too big to hold in a 32K space. Again, this doesn't seem to make sense. There is no such thing as a result that is too big for a cursor
    Do you think I need to change PL_JSON API myself to ensure it uses CLOB? or there is anyway that I can avoid update PL_JSON package internally?If the PL_JSON package is trying to write more than 32k of data into a VARCHAR2, your options are
    - Modify the package to use a CLOB
    - Find some other package that implements whatever functionality you need
    - Limit the data to 32k
    Justin

  • Maximum open cursors exceeded problem

    hi,
    I am connecting to Oracle 8i (8.1.6 ) using JDBC2.0. I have a
    block of code which does the following:
    Open connection to database, create a Statement object say stat
    and a Prepared Statement object say pStat
    pStat.execute()
    while(condition)
    stat.executeUpdate(string);
    pStat.close();
    stat.close()
    Close connection
    Multiple execution of the block gives ORA-01000 error. I use
    select user_name, count(*) num from sys.v_$open_cursor group by
    user_name;
    to check for open cursors and find that no open cursors result
    from block. The maximum # of open cursors is set to 100.
    Please help!
    Regards,
    Pratibha

    If that were true, then connection pooling would never work. I
    think the problem is:
    while(condition){
    stat.executeUpdate(string);
    Oracle is creating a new process (cursor) for each call to
    executeUpdate, which is never being released throught the whole
    looping process. What would be better is:
    while(condition){
    stat = conn.createStatement();
    int result = stat.executeUpdate(string);
    stat.close();
    conn.commit();
    You have to destroy the connection, not just close it.
    rgds, APC

  • Cursor in select query in row to column format

    Hi
    I have the query like below
    SELECT d.department_id,
                 CURSOR(SELECT e.first_name,
                         e.last_name
                  FROM   employees e
                  WHERE  e.department_id = d.department_id
           ) emps
    FROM   depatments dI want the result set in a format of Row To columns like
    10                             20
    <cursor result>   <cursor result>pls give ur suggestions how to achieve this in a efficient way?I tried the method of "max(decode(.." but dont think so its possible with this

    vishnu prakash wrote:
    Hi
    I have the query like below
    SELECT d.department_id,
    CURSOR(SELECT e.first_name,
    e.last_name
    FROM   employees e
    WHERE  e.department_id = d.department_id
    ) emps
    FROM   depatments dI want the result set in a format of Row To columns like
    10                             20
    <cursor result>   <cursor result>pls give ur suggestions how to achieve this in a efficient way?I tried the method of "max(decode(.." but dont think so its possible with thisNumber of column of a select query is static. Must be known at the parsing time itself. But in your case i dont think the number of columns will be limited to 2 (10 and 20) there could be many more.
    You can search this forum to see how to PIVOT your data. There are lot of example. You can also try dynamic pivot. Its all in here, just search.

  • Cursor bind variable syntax err

    Any one help me in correcting the syntax, for cursor return.
    Oracle version 10g
    I am trying to execute the sproc and print the cursor results using bind variable, I am getting he below error
    Variable V_REFCUR REFCURSOR
    Variable V_REFCUR2 REFCURSOR
    variable swp_ret_value NUMBER
    exec  DELETE_POSITION(0,0,2,'U',:swp_ret_value,:V_REFCUR,:V_REFCUR2)
      print swp_ret_value
      Print v_refcur
      Print v_refcur2
    -- output
    Error starting at line 5 in command:
    exec  DELETE_POSITION(0,0,2,'U',:swp_ret_value,:V_REFCUR,:V_REFCUR2)
    Error report:
    Cursor is closed.
    SWP_RET_VALUE
    V_REFCUR
    V_REFCUR2
    ------Edited by: NeilCSE on Jan 18, 2011 4:08 AM

    it is calling another proc
    PROCEDURE Assign_outRefcur2 (CurrentCursor IN OUT SYS_REFCURSOR
                                                          , v_ref_cur IN OUT SYS_REFCURSOR
                                                          , v_ref_cur2 IN OUT SYS_REFCURSOR
    AS
       InitCursor SYS_REFCURSOR;
    BEGIN
    IF NOT v_ref_cur%IsOpen THEN v_ref_cur := CurrentCursor;
       ELSIF NOT v_ref_cur2%IsOpen THEN v_ref_cur2 := CurrentCursor;
    END IF;
    CurrentCursor:= InitCursor;
    END;

  • Using ref cursor in "in clause" in select statement

    Hi,
    Is there any way can we use the ref cursor in the in condition of a select statement.
    Regards,
    Venkat.
    Edited by: ramanamadhav on Aug 23, 2011 11:14 AM

    ramanamadhav wrote:
    I'm sorry if I post in confusing way. I will give an example. Just see the psudo code here.
    declare
    rf_cur sys_refcursor;
    begin
    pr_test(empno,rf_cur);
    -- rf_cur returning emp names.
    select * from emp
    where empname in (ref_cusor results);-- here i want to consume my ref cursor result in the in conditions.
    end;
    Thanks &Regards,
    Venkat.No you can't do that. A ref cursor is not a set of results as you believe.
    Take a read of this article...
    {thread:id=886365}

Maybe you are looking for