Performanace Issue using cursors

Hi All,
I am using Cursors in my db using these cursors i am fetching data from 8 DB's. When it was fresh Database It was working fine. But now it is taking lot of time. I have a Stats on all the tables. How we can increase the performance of that program so that we can get the data in my db at high speed. we are using simple cursors. Can i use ref cursors for incresing the performance.
Thanks in advance

Hi,
I am from india, Working for a Telecom Company. we have 12 databases and now we have created some pl/sql programs on my host database. I have shcedule these programs at 3 o'clock night now. we are facing some performance problem. we want these programs should complete within 2 hours. but they are taking huge time.near about 4hours. the coding of this proc is below.
CURSOR C1 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu1 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C2 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu2 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C3 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu3 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C4 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu4 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C5 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu5 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C6 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu6 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C7 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu7 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR c_active_brio_demo is
select /*+ INDEXED */ mtdd.first_order_cr_date,
mtdd.USER_ID,
mtdd.account_no,
mtdd.BILL_FIRST_NAME,
mtdd.BILL_MIDDLE_NAME,
mtdd.BILL_LAST_NAME,
mtdd.BILL_ADDRESS_1,
mtdd.BILL_ADDRESS_2,
mtdd.bill_address_3,
mtdd.BILL_CITY,
mtdd.bill_state,
mtdd.bill_zip,
mtdd.bill_period,
mtdd.CONTACT1_PHONE,
mtdd.contact2_phone,
mtdd.cust_phone1,
mtdd.cust_phone2,
mtdd.ACCOUNT_ACTIVATION_DATE,
mtdd.ACCOUNT_CREATION_DATE,
mtdd.ACCOUNT_STATUS,
mtdd.DEALER_NAME,
MTDD.ALLOC_AGENT_CODE,
mtdd.ACCOUNT_CATEGORY,
mtdd.parent_id,
mtdd.bill_county,
mtdd.EQUIP_STATUS,
mtdd.MARKET_CODE,
mtdd.subscriber_no,
mtdd.subscriber_no_reset,
mtdd.report_id,
mtdd.report_date,
mtdd.rec_type,
mtdd.addon_name,
mtpd.PACKAGE_NAME,
mtpd.ACTIVE_DATE P_ACTIVE_DATE,
mtpd.INACTIVE_DATE P_INACTIVE_DATE,
MTPD.PACKAGE_ORDER_ID,
nvl(osv.display_value,'UNDEFINED') PACKAGE_ORDER_STATUS,
mtpd.package_status,
mtpd.package_instance_id,
mtpd.package_instance_id_serv,
mtcd.COMPONENT_NAME,
mtcd.ACTIVE_DATE,
mtcd.INACTIVE_DATE,
mtcd.COMPONENT_STATUS,
mtdd.subdealer_code,
mtdd.DISCONNECT_REASON,
mtdd.XFER_REASON,
mtdd.CONNECT_RESON,
MONTHS_BETWEEN(mtdd.SERVICE_END,mtdd.SUBSCR_ACTIVATION_DATE) AON
from misr_tra_demo_det mtdd,misr_tra_pack_det mtpd, misr_tra_comp_det mtcd,order_status_values osv
where mtdd.report_id = p_rep_id
and mtpd.subscriber_no = mtdd.subscriber_no
and mtpd.subscriber_no_resets = mtdd.subscriber_no_reset
and mtpd.report_id = mtdd.report_id
and mtpd.record_type = mtdd.rec_type
and mtcd.subscriber_no = mtdd.subscriber_no
and mtcd.subscriber_no_resets = mtdd.subscriber_no_reset
and mtcd.report_id = mtdd.report_id
and mtcd.record_type = mtdd.rec_type
and mtcd.package_instance_id = mtpd.package_instance_id
and mtcd.package_instance_id_serv = mtpd.package_instance_id_serv
and mtpd.PACKAGE_ORDER_STATUS = osv.ORDER_STATUS(+);
CURSOR CUR_VAS IS
SELECT distinct mmvc.COMPONENT_NAME
FROM misr_mas_vas_comp mmvc, misr_tra_comp_det mtcd
WHERE mtcd.subscriber_no = d_subscriber_no
AND mtcd.subscriber_no_resets = d_subscriber_no_reset
AND mtcd.inactive_date = E_END_DATE
AND mtcd.component_id = mmvc.component_id;
CURSOR c_active_brio_equip is
select /*+ INDEXED */ mted.MOBILE_ORDER_ID,
MTED.MOBILE_ORDER_STATUS,
mted.EXTERNAL_ID,
mted.START_DATE,
mted.END_DATE,
mted.external_id_type,
MONTHS_BETWEEN(mted.END_DATE,mted.ORIG_SERVICE_START) AON
from misr_tra_equip_det mted
where subscriber_no = d_subscriber_no
and subscriber_no_resets = d_subscriber_no_reset
and report_id = p_rep_id
and rec_type = d_rec_type;CURSOR C1 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu1 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C2 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu2 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C3 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@bpcu3 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C4 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@bpcu4 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C5 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@bpcu5 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C6 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu6 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR C7 IS
select bill_ref_no , (NEW_CHARGES/100)
from cmf_balance@cu7 a
where ACCOUNT_NO = D_ACCOUNT_NO
ORDER BY BILL_REF_NO DESC;
CURSOR c_active_brio_demo is
select /*+ INDEXED */ mtdd.first_order_cr_date,
mtdd.USER_ID,
mtdd.account_no,
mtdd.BILL_FIRST_NAME,
mtdd.BILL_MIDDLE_NAME,
mtdd.BILL_LAST_NAME,
mtdd.BILL_ADDRESS_1,
mtdd.BILL_ADDRESS_2,
mtdd.bill_address_3,
mtdd.BILL_CITY,
mtdd.bill_state,
mtdd.bill_zip,
mtdd.bill_period,
mtdd.CONTACT1_PHONE,
mtdd.contact2_phone,
mtdd.cust_phone1,
mtdd.cust_phone2,
mtdd.ACCOUNT_ACTIVATION_DATE,
mtdd.ACCOUNT_CREATION_DATE,
mtdd.ACCOUNT_STATUS,
mtdd.DEALER_NAME,
MTDD.ALLOC_AGENT_CODE,
mtdd.ACCOUNT_CATEGORY,
mtdd.parent_id,
mtdd.bill_county,
mtdd.EQUIP_STATUS,
mtdd.MARKET_CODE,
mtdd.subscriber_no,
mtdd.subscriber_no_reset,
mtdd.report_id,
mtdd.report_date,
mtdd.rec_type,
mtdd.addon_name,
mtpd.PACKAGE_NAME,
mtpd.ACTIVE_DATE P_ACTIVE_DATE,
mtpd.INACTIVE_DATE P_INACTIVE_DATE,
MTPD.PACKAGE_ORDER_ID,
nvl(osv.display_value,'UNDEFINED') PACKAGE_ORDER_STATUS,
mtpd.package_status,
mtpd.package_instance_id,
mtpd.package_instance_id_serv,
mtcd.COMPONENT_NAME,
mtcd.ACTIVE_DATE,
mtcd.INACTIVE_DATE,
mtcd.COMPONENT_STATUS,
mtdd.subdealer_code,
mtdd.DISCONNECT_REASON,
mtdd.XFER_REASON,
mtdd.CONNECT_RESON,
MONTHS_BETWEEN(mtdd.SERVICE_END,mtdd.SUBSCR_ACTIVATION_DATE) AON
from misr_tra_demo_det mtdd,misr_tra_pack_det mtpd, misr_tra_comp_det mtcd,order_status_values osv
where mtdd.report_id = p_rep_id
and mtpd.subscriber_no = mtdd.subscriber_no
and mtpd.subscriber_no_resets = mtdd.subscriber_no_reset
and mtpd.report_id = mtdd.report_id
and mtpd.record_type = mtdd.rec_type
and mtcd.subscriber_no = mtdd.subscriber_no
and mtcd.subscriber_no_resets = mtdd.subscriber_no_reset
and mtcd.report_id = mtdd.report_id
and mtcd.record_type = mtdd.rec_type
and mtcd.package_instance_id = mtpd.package_instance_id
and mtcd.package_instance_id_serv = mtpd.package_instance_id_serv
and mtpd.PACKAGE_ORDER_STATUS = osv.ORDER_STATUS(+);
CURSOR CUR_VAS IS
SELECT distinct mmvc.COMPONENT_NAME
FROM misr_mas_vas_comp mmvc, misr_tra_comp_det mtcd
WHERE mtcd.subscriber_no = d_subscriber_no
AND mtcd.subscriber_no_resets = d_subscriber_no_reset
AND mtcd.inactive_date = E_END_DATE
AND mtcd.component_id = mmvc.component_id;
CURSOR c_active_brio_equip is
select /*+ INDEXED */ mted.MOBILE_ORDER_ID,
MTED.MOBILE_ORDER_STATUS,
mted.EXTERNAL_ID,
mted.START_DATE,
mted.END_DATE,
mted.external_id_type,
MONTHS_BETWEEN(mted.END_DATE,mted.ORIG_SERVICE_START) AON
from misr_tra_equip_det mted
where subscriber_no = d_subscriber_no
and subscriber_no_resets = d_subscriber_no_reset
and report_id = p_rep_id
and rec_type = d_rec_type;
Please suggest me how we can improve the performance can we use pl/sql records over here.

Similar Messages

  • Issue using cursors in extractors

    Hello,
    I am using two cursors in an extractor. My requirement is to delete data obtained from one cursor from another set of data obtained from the second cursor.
    What happens is when the two cursors run for the first time, assuming they read 100 records each, if the data i require to delete from the second cursor is not in the first set of records obtained from the first cursor, then on the second run, the data would be replaced by new data in both the tables and this time, even though the data is available in the second cursor, the data in the first has been replaced already. So the requirement doesnt get fulfilled.
    If anyone could make sense of what i just wrote , pls help me out.
    Regards,
    Suraj

    Hi Suraj,
    The thing is you cannot raise the exception when there is not data fetch in the first cursor select statement.
    As you dont know at run time is there any data left in the second select statement you have written .
    what you can do if declare a variable which will be set to X when the sy-subrc<> 0 for the first select statment.
    like
    This is your 1st select statement with the cursor .....
        FETCH NEXT CURSOR S_CURSOR
                   APPENDING CORRESPONDING FIELDS
                   OF TABLE E_T_DATA
                   PACKAGE SIZE S_S_IF-MAXSIZE.
        IF SY-SUBRC <> 0.
    lv_var = 'X' .
    Dont raise the ecception here.
        ENDIF.
    No the 2nd select statment with cursor
        FETCH NEXT CURSOR S_CURSOR
                   APPENDING CORRESPONDING FIELDS
                   OF TABLE E_T_DATA
                   PACKAGE SIZE S_S_IF-MAXSIZE.
        IF SY-SUBRC <> 0.
    if lv_var = 'X' .
    raise the ecception here this is because in the 1st select it has already fetch all the data .
    endif.  
    ENDIF.
    where you lv_var is type c .
    I hope it is clear now.
    Regards,
    Pawan
    Message was edited by:
            PS

  • How to use cursor function for nested xml

    Hi,
    i have a query for XMLQuery like
    select * from bills where bill_id=????
    it results in something like
    <bills>
    <bill>
    <city>london</city>
    <amount>44</amount>
    </bill>
    <bill>
    <city>london</city>
    <amount>988</amount>
    </bill>
    <bill>
    <city>new york</city> <amount>59</amount> </bill>
    </bills>
    but i want xml output to be sorted for city names adding one more level location like
    <bills>
    <location city="london">
    <bill>
    <amount>44</amount>
    </bill>
    <bill>
    <amount>988</amount> </bill>
    </location>
    <location city="new york">
    <bill>
    <amount>59</amount> </bill>
    </location>
    </bills>
    it should be possible to iterate through the same table to gather informaton with the help of cursor function, but never used CURSOR before.
    any idea?

    sreese wrote:
    p_desig works as a comma delimited string without the NVL function, that's not the issue.
    It IS the issue .. you need to provide  a SAMPLE so we can see what you're doing ..
    How are you "passing it in" ?
    option A:
    procedure ( in_var  in  VARCHAR2 )
    AS
    and nvl(sn.c_attribute1,'x@#$%') in nvl(in_var,'x@#$%')
    option B:
    and nvl(sn.c_attribute1,'x@#$%') in nvl(&1,'x@#$%')
    .. or some other method?

  • Need using cursor for query

    Hi all,
    can anybody tell me how to get the result of the following query by using cursor?
    SELECT (SUBSTR('        ', 1,LEVEL*2)
      || t1.label) AS t1_label,
      amount
    FROM
      (SELECT t1.label,
        t1.ID,
        t1.parent_id,
        SUM(t2.turnover) AS amount
      FROM t1,
        t2
      WHERE t2.t1_id = t1.id
      AND t2.t1_id  IN
        (SELECT id
        FROM t1
          START WITH t1.ID       = 2
          CONNECT BY PRIOR t1.ID = t1.parent_id
      GROUP BY t1.label, t1.ID, t1.parent_id
      ) t1
      START WITH t1.ID       = 2
      CONNECT BY PRIOR t1.ID = t1.parent_id;...and the result:
    t1_label             amount
         B11     11778.54
          B121     19980.28
            B1211     18842.77
            B1212     25480.56
          B122     18339.07
        B12            23455.9
        B13            20876.52Thanks,
    Alex
    Edited by: 860003 on Jun 9, 2011 1:30 AM
    Edited by: 860003 on Jun 9, 2011 1:31 AM
    Edited by: 860003 on Jun 9, 2011 1:31 AM

    860003 wrote:
    Is not that i don't want to use hierarchy queries, but find others ways, tricks to reach the result needed. I just want to explore different ways that Oracle provides to resolve issues.Not a problem with that in principle.
    Maybe using "loop, if-else, for" will provide us with an elegant way to get the result. However, a problem in principle with this. SQL and PL/SQL are not the same thing. Two separate and very different languages.
    In PL/SQL, you can code both PL and SQL - so you can write source code of 2 different language and mix these. The PL/SQL parser is clever enough to figure out what is what and glues the code seamlessly and transparently together.
    SQL is used to crunch SQL data. PL/SQL sucks at this in comparison (and Java/.Net sucks a heck of a lot worse at this). Cursor fetch loops? Bulk processing. Neat. But will always be slower than running that data crunching in SQL only.
    That is why there is a simple maxim for performance in Oracle: Maximise SQL. Minimise PL/SQL.
    Do not use PL/SQL to do what the SQL is perfectly able and capable of doing. The exception is when the processing is too complex for SQL to handle and you need the programming logic part of the PL/SQL language.
    My question is how to use this cursor to get the value, fetch it and then get another value(ofc only for the children) and fetch it again so i can output it? I thing this can be achieve but don't know how.All SQLs (and anonymous PL/SQL) are parsed and cursors are created. A cursor is a basically a set of instructions (as seen via execution plans) of how to get the job done. Think of cursors as programs that are executed and output data.
    So do you want t create a bunch of cursors (programs) and then call these from PL/SQL, consume their output, create/call new cursor programs and repeat?
    Or do you want to create a single cursor program that does the job and outputs the required results?
    Maximise SQL. Minimise PL/SQL.

  • Insert multiple rows using Cursors.

    I am trying to insert rows into a table based on information from another table.
    For example:
    When Table 1: Num_Rows = 100 my proc will insert 100 rows into Table 2 with relevent data.
    Do I need to use a Cursor and iterate through Num_Rows doing an INSERT each time? Is there a better way to do it other than using Cursors?
    Rob.

    It is not about using cursors or not using cursors. All SQLs wind up as cursors in the Oracle Shared Pool. So there is no such concept as not using cursors. Oracle needs to parse and compile and execute SQLs as cursors.
    The issue is WHERE* you do the work?
    Do you use the cursor (SQL) to do it for you? Or do you pull the data into another language, like PL or Java and process it there?
    And the performance mantra in this case is a very fundemantal Maximize SQL and minimize PL/Java/etc+.
    So do not do in PL/SQL what you can do in SQL only. It is a lot slower to pull data from the SQL engine into the PL engine. And then push that very same data from the PL engine back to the SQL engine. Like the following for example:
    -- poor design, poor performance
    for employee in (select e.* from emp e where e.deptid = 123 )
    loop
      insert into tab2 values( employee.empid, employee.name );
    end loop;You do not need to use PL (or Java) in this case. The SQL language is more than able to do this better and faster than any other language... as it is closer to the data.
    So the following is far more optimal code. Instead of the above PL/SQL code, we can simply do it as:
    -- optimal design: maximizing SQL and letting it to as much of the work as possible
    insert into tab2 select e.empid, e.name from emp e where e.deptid = 123;

  • Generate report using CURSORS? - Simple question

    Folks,
    I'm a real newbie still with PL/SQL so please excuse my ignorance I have a simple report I need to generate. The following SQL statement gets me all my "header" records:
    SELECT OHA.ORDER_NUMBER, HEADER_ID, ATT11, ATT12, ATT16
    FROM XXXWD.WD_DUPS DUPS, OE_ORDER_HEADERS_ALL OHA
    WHERE OHA.ATTRIBUTE11 = DUPS.ATT11
    AND OHA.ATTRIBUTE12 = DUPS.ATT12
    AND OHA.ATTRIBUTE16 = DUPS.ATT16
    AND (OHA.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED'))
    AND (ATT11 <> 'WESTERN SERVICE')
    ORDER BY ATT11, ATT12, ATT16
    What I want to do now is have a second script that will display all my detail records. Something like:
    SELECT OLA.LINE_NUMBER, OLA.ORDERED_ITEM, OLA.FLOW_STATUS_CODE
    FROM OE.ORDER_LINES_ALL OLA
    WHERE OLA.HEADER_ID = OHA.HEADER_ID
    I expect I'd do this with two cursors, passing the value of my HEADER_ID to my second cursor. But when I've used cursors before, they primarily have been to import data, and manipulate data. But what if I just want to create a report using these?
    I essentially want to display my header information, and then any lines below that data (if there is any, there may be a header with no lines).
    Can I create a simple report like this with cursors? Any help with this would be IMMENSELY appreciated. I'm really under the gun... :)
    Thanks so much!
    Steve

    Here's one query that will give you everything:
    SELECT OHA.ORDER_NUMBER
          ,OHA.HEADER_ID
          ,DUPS.ATT11
          ,DUPS.ATT12
          ,DUPS.ATT16
          ,OLA.LINE_NUMBER
          ,OLA.ORDERED_ITEM
          ,OLA.FLOW_STATUS_CODE     
    FROM   XXXWD.WD_DUPS        DUPS
          ,OE_ORDER_HEADERS_ALL OHA
          ,OE.ORDER_LINES_ALL   OLA
    WHERE  OLA.HEADER_ID   = OHA.HEADER_ID
    AND    OHA.ATTRIBUTE11 = DUPS.ATT11
    AND    OHA.ATTRIBUTE12 = DUPS.ATT12
    AND    OHA.ATTRIBUTE16 = DUPS.ATT16
    AND    OHA.FLOW_STATUS_CODE NOT IN ('CLOSED', 'CANCELLED')
    AND    DUPS.ATT11 <> 'WESTERN SERVICE'
    ORDER  BY OHA.ORDER_NUMBER
             ,OLA.LINE_NUMBER
             ,DUPS.ATT11
             ,DUPS.ATT12
             ,DUPS.ATT16
    ;(correction in order by clause)
    Message was edited by:
    Eric H

  • To Use  Cursor or  TYPE table Index by PLS_integer

    Hi All,
    Let's see if I have table with no. of records 19,26,20,000.
    If I want to loop through all the records which will be a optimized way To Use Cursor or TYPE table Index by PLS_integer.
    Please guide.
    Thanks.

    What is it you want to do to/with the rows you're looping through?
    Ideally you want to avoid looping, as that's row by row (aka slow by slow) processing and it's expensive time-wise.
    If you're doing DML (insert/update/delete) then you're best off doing it in one sql statement, rather than looping.

  • How to pick max value from a column of a table using cursor and iteration

    Hello Everybody
    I have a table loan_detail
    and a column in it loan_amount
    now i want to pick values from this table using cursor and then by using iteration i want to pick max value from it using that cursor
    here is my table
    LOAN_AMOUNT
    100
    200
    300
    400
    500
    5600
    700i was able to do it using simple loop concepts but when i was trying to do this by using cursor i was not able to do it .
    Regards
    Peeyush

    SQL> SELECT MAX(sal) Highest_Sal,MIN(sal) Lowest_Sal FROM emp;
    HIGHEST_SAL LOWEST_SAL
           5000        800
    SQL> set serverout on
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := counter;
    10      counter := counter + 1;
    11    END LOOP;
    12    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    13    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    14  END;
    15  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Even smaller
    SQL> DECLARE
      2    TYPE tmp_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
      3    sal_tbl tmp_tbl;
      4    CURSOR emp_sal IS
      5      SELECT sal FROM emp;
      6    counter INTEGER := 1;
      7  BEGIN
      8    FOR i IN emp_sal LOOP
      9      sal_tbl(i.sal) := 1;
    10    END LOOP;
    11    DBMS_OUTPUT.put_line('Lowest SAL:' || sal_tbl.FIRST);
    12    DBMS_OUTPUT.put_line('Highest SAL:' || sal_tbl.LAST);
    13  END;
    14  /
    Lowest SAL:800
    Highest SAL:5000
    PL/SQL procedure successfully completed.
    SQL> Edited by: Saubhik on Jan 5, 2011 4:41 PM

  • Any way to use cursor values inside other cursor by bulk collect?

    hi,
    Is there any way to use cursor get_tables value insdide loop get column if i am using bulk collect in both cursors?
    I tried a lot but i am nt able to do it.kindly help...
    create or replace procedure MULTIPLE_CURSORS_PROC is
    v_owner varchar2(40);
    v_table_name varchar2(40);
    v_column_name varchar2(100);
    cursor get_tables is
    select distinct tbl.owner, tbl.table_name
    from all_tables tbl
    where tbl.owner = 'SYSTEM';
    cursor get_columns is
    select distinct col.column_name
    from all_tab_columns col
    where col.owner = v_owner
    and col.table_name = v_table_name;
    begin
    open get_tables;
    loop
    fetch get_tables into v_owner, v_table_name;
    open get_columns;
    loop
    fetch get_columns into v_column_name;
    end loop;
    close get_columns;
    end loop;
    close get_tables;
    end ;

    hi there
    Refer this
    CREATE OR REPLACE PROCEDURE MULTIPLE_CURSORS_PROC
    IS
       TYPE scol IS VARRAY (10000) OF VARCHAR2 (32767);
       v_table_name    scol;
       v_column_name   scol;
       TYPE curtyp IS REF CURSOR;
       get_columns     curtyp;
       CURSOR get_tables
       IS
          SELECT   DISTINCT tbl.table_name
            FROM   all_tables tbl
           WHERE   tbl.owner = 'SYSTEM';
    BEGIN
       OPEN get_tables;
       LOOP
          FETCH get_tables BULK COLLECT INTO   v_table_name;
          FOR indx IN v_table_name.FIRST .. v_table_name.LAST
          LOOP
             SELECT   DISTINCT col.column_name
               BULK   COLLECT
               INTO   v_column_name
               FROM   all_tab_columns col
              WHERE   col.table_name = v_table_name (indx);
             FOR ind IN v_column_name.FIRST .. v_column_name.LAST
             LOOP
                DBMS_OUTPUT.put_line (v_column_name (ind));
             END LOOP;
          END LOOP;
          EXIT WHEN get_tables%NOTFOUND;
       END LOOP;
       CLOSE get_tables;
    END MULTIPLE_CURSORS_PROC;regards
    Hitesh

  • Report using cursors and loop

    Hi,
    can anybody suggest what kind of report and in what way I have to use if I want to write query using cursors within loops?
    Thanks!
    Karina.

    Hi,
    I found the solution. I just rewrite all cursors within one SQL statement and it works.
    Karina.

  • Using Cursor in Select statements? How to do this?

    I am getting an error whilt passing a cursor to a select clause:
    SELECT dbms_xmlquery.getXML('select deptno, dname, '||
    'cursor(select empno, ename, sal from emp e where e.deptno = d.deptno) employees '||
    'from dept d where d.deptno in (10, 20)')
    FROM dual;
    DBMS_XMLQUERY.GETXML('SELECTDEPTNO'||'CURSORIS(SELECTEMPNOFROMEMPEWHEREE.DEPT=D.
    <?xml version = '1.0'?>
    <ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00923
    : FROM keyword not found where expected
    </ERROR
    THIS IS DUE TO THE CURSOR AND ITS FROM STATEMENT?
    CAN ANY ONE PLEASE GUIDE AS TO HOW TO USE CURSORS IN A SELECT STATEMENT PLEASE?

    Another duplicate thread. See my response Select CLAUSE error using CURSORS & XSU.Please SEE..
    Cheers, APC

  • Loading data from one table to another using cursor

    Hi,
    I have given the below command to load the data from 1 table to another using cursor.
    declare
    cursor mycursor IS
    SELECT extract_name,from_date,to_date,BETA from temp_table where EXTRACT_NAME='GIFTCARD_DETAILS';
    Begin
    for mycursor_1 IN mycursor loop
    insert into tmp_tab columns(col1,col2,col3,col5) values(mycursor_1.EXTRACT_NAME,mycursor_1.from_date,mycursor_1.to_date,mycursor_1.BETA);
    End loop;
    commit;
    end;
    It is working fine.
    But I want to hard code some of the columns ( like flags ) which are not there in 1st table and load them into 2nd table.
    In db2 we will give commands like
    varSqlStatus=`db2 "declare mycurs cursor for select extract_name,from_date,to_date,BETA,'N','Y' from temp_table"`
    varSqlStatus=`db2 "load from mycurs of cursor modified by identityignore insert into tmp_tab(col1,col2,col3,col5,col6,col7) nonrecoverable"`
    But I want it in oracle 10g, Can any one help me in this.

    Have you tried either of the two options :
    1. Modify the CURSOR itself :
    cursor mycursor IS
    SELECT extract_name,from_date,to_date,BETA,'N','Y' from temp_table where EXTRACT_NAME='GIFTCARD_DETAILS';2. Modify the INSERT statement itself :
    insert into tmp_tab columns(col1,col2,col3,col5,col6,col7) values(mycursor_1.EXTRACT_NAME,mycursor_1.from_date,mycursor_1.to_date,mycursor_1.BETA,'N','Y');

  • Is there an issue using file vault 2 on a Mac fusion drive

    is there an issue using file vault 2 on a Mac fusion drive

    I'm using that configuration and it works for me. There have been some reports of kernel panics with FileVault and SSD's. The cause is unknown. Chances are you'll be fine, but make good backups.

  • Goods Issue using BAPI_GOODSMVT_CREATE movement type 541

    Hi
        According to my requirement I need to do Post goods issue using BAPI_GOODSMVT_CREATE. But I am unable to do PGI . how to consume BOM details if batches are changed. please let me know what values I need to pass to BAPI . give with an example.
    Its an urgent requirement.

    are you passing batch number to the BAPI?
    if not try pass the batch number the rest of the things bapi will take care of.
    bi

  • Post Goods issue using bapi_goodsmvt_create

    hi,
    Iam trying to do post goods issue using bapi_goodsmvt_create. please let me know what are the mandatory fields to be passed?

    hi,
    *& Report  ZRPT_SUB_KO01GOODSMOVEMENT
    REPORT  ZRPT_SUB_KO01GOODSMOVEMENT.
    PARAMETERS : P_BAG(17)  TYPE C,
                 P_ZZORG LIKE zaUFK-ZZORG,
                 P_MATNR LIKE MARA-MATNR,
                 P_WERKS LIKE AUFK-WERKS,
                 P_WERK LIKE AFPO-PWERK,
                 P_DATE LIKE MKPF-BUDAT,
                 P_LGORT LIKE GOITEM-LGOBE.
    DATA : BDC_DATA TYPE STANDARD TABLE OF BDCDATA. "internla table for bdc data
      DATA : WA_BDC_DATA TYPE BDCDATA .                "work area for bdc data
      DATA : T_XMSEG TYPE   MSEG.
      DATA : T_XMKPF TYPE MKPF.
      DATA : V_BAGS1(17) TYPE C.
    DATA : BEGIN OF WA_MB1B,
           ZZGCODE TYPE ZMIGO-ZZGCODE,
           ZZGBAGS TYPE ZMIGO-ZZGBAGS,
           WERKS TYPE AUFK-WERKS,
           LGORT TYPE VBRP-LGORT,
           ZZORG TYPE zAUFK-ZZORG,
           END OF WA_MB1B.
    DATA : V_MATERIAL TYPE BAPI2017_GM_HEAD_RET-MAT_DOC.
    data : v_date(10) type c.
    DATA : T_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
           T_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
           T_GOODSMVT_ITEM TYPE STANDARD TABLE OF BAPI2017_GM_ITEM_CREATE,
           T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
    DATA : WA_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE.
    DATA : BEGIN OF S_MARA,
           MEINS LIKE MARA-MEINS,
           END OF S_MARA.
    DATA : MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC.
    *FORM GOODSMOVEMENT TABLES T_RETURN
                             USING WA_MB1B LIKE WA_MB1B.
    SELECT SINGLE  MEINS
                   FROM MARA
                   INTO S_MARA
                   WHERE MATNR = P_MATNR.
       CONCATENATE p_date6(2) p_date4(2) p_date+0(4) INTO V_DATE SEPARATED BY '.'.
        T_GOODSMVT_HEADER-PSTNG_DATE = P_DATE.
        T_GOODSMVT_HEADER-DOC_DATE = P_DATE.
        T_GOODSMVT_CODE-GM_CODE = '04'.
        WA_GOODSMVT_ITEM-MATERIAL =      P_MATNR.                    "'000000000000001556'.
        WA_GOODSMVT_ITEM-PLANT  =        P_WERK.                     " '1000'.
        WA_GOODSMVT_ITEM-STGE_LOC =      P_LGORT.                    " '0001'.
        WA_GOODSMVT_ITEM-MOVE_TYPE =     'Z42'.
        WA_GOODSMVT_ITEM-VENDOR =         P_ZZORG.                   "'0000100224'.
        WA_GOODSMVT_ITEM-ENTRY_QNT =      P_BAG.                   " '1'.
        WA_GOODSMVT_ITEM-ENTRY_UOM =     S_MARA-MEINS.
        WA_GOODSMVT_ITEM-ENTRY_UOM_ISO = S_MARA-MEINS.
        WA_GOODSMVT_ITEM-MOVE_PLANT = P_WERKS.
        APPEND WA_GOODSMVT_ITEM TO T_GOODSMVT_ITEM.
    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
          GOODSMVT_HEADER          = T_GOODSMVT_HEADER
          GOODSMVT_CODE            = T_GOODSMVT_CODE
    IMPORTING
        MATERIALDOCUMENT           = V_MATERIAL
    TABLES
          GOODSMVT_ITEM            = T_GOODSMVT_ITEM
    RETURN                        = T_RETURN.
    BREAK shailajaa.
               EXPORT t_return  to MEMORY ID '123'.
               EXPORT V_MATERIAL TO MEMORY ID 'MAT'.
                CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
         EXPORTING
           WAIT          = ' '.
    *ENDFORM.

Maybe you are looking for

  • JSP form values lost upon servlet request (RequestDispatcher)

    Hello, I have a query screen (jsp) that calls a servlet and gets results. However, although the results or errors display just fine (I do a setAttribute for them), I lose the initial values in the query form (values that the user input - which are st

  • Word Doc to PDF

    Hi friends Can any one tell me how i can convert a word doc to pdf using java. My actual problem is I need to convert doc to pdf without the user interaction. Here iam creating doc from xml and xsl and the i need to make the copy of word doc in pdf.

  • Midi in using Alesis IO Doc for Garage Band

    I have audio in GB on iPad2 and the Alesis IO dock and would like to use the midi in to at least start and stop my song.  Will GB understand a midi clock in?  If so how can it be told to recognize it.  I'm told it supports core midi but it wont do mi

  • Duplicate material check on contract

    Hello GURUS, How to restrict creation of duplicate material items on one contract (outline agreement)? i.e. if the material already exists on contract, the system should prevent adding the same mateiral to the same contract. Any clue? Are there any u

  • Screen Refresh frequency on my Portege M300 stuck on 60Hz.

    Hi, I can only set my Refresh frequency to 60Hz on my laptop screen. Watching the screen for a long time at below 75hz can give me a headache. I all ways set my screen refresh rate to above 75Hz keeping the resolution around 1024x768, prefer 85Hz-100