Collect inetnal table

Hi all,
I had a problem with collecting 2 internal tables in 1.
1 internal table itab:
matnr         belnr        qty.
200541   40076589   138.
and 2nd internal table itab2
matnr              belnr            qty
700042    40076589      4
700042    40076589     24
700042    40076589   110
I want ouput in single internal table like :
belnr              matnr        qty       matnr qty
40076589    200541    138   700042    4
40076589                              700042    24
40076589                             700042    110
please help me.

Hi,
create third internal table with same structure and do like this
loop at itab2.
itab3-matnr = itab-matnr.
itab3-belnr = itab-belnr.
itab3-qty = itab-qty.
append itab3.
endloop.
loop at itab.
itab3-matnr = itab-matnr.
itab3-belnr = itab-belnr.
itab3-qty = itab-qty.
modify itab3.
endloop.

Similar Messages

  • Collect internal table

    Hi    ....
    How can I collect internal table when a field adjacent is been . For example when corresponding matnr have I want to add other fields of other record .

    Hi,
    COLLECT add the numeric entries for the corresponding table keys..
    Example.
    DATA: BEGIN OF ITAB OCCURS 0,
                 MATNR TYPE MATNR,
                 COUNT TYPE I,
               END OF ITAB.
    ITAB-MATNR  = 'ABC'.
    ITAB-COUNT = 2.
    COLLECT ITAB.
    ITAB-MATNR  = 'ABC'.
    ITAB-COUNT = 1.
    COLLECT ITAB.
    ITAB-MATNR  = 'ABCD'.
    ITAB-COUNT = 2.
    COLLECT ITAB.
    ITAB-MATNR  = 'ABCD'.
    ITAB-COUNT = 3.
    COLLECT ITAB.
    LOOP AT ITAB.
      WRITE: / ITAB-MATNR, ITAB-COUNT.
    ENDLOOP.
    Thanks,
    Naren

  • COLLECT: Which table is better to use - STANDARD or SORTED?

    Hello Performance gurus,
    I read this curious fact about COLLECT statement:
    In standard tables that are filled using COLLECT only, the entry is determined by a temporary hash administrator. The workload is independent of the number of entries in the table. The hash administrator is temporary and is generally invalidated when the table is accessed to be changed. If COLLECT statements are specified after an invalidation, a linear search of all table rows is performed. The workload for this search increases in a linear fashion in relation to the number of entries.
    In sorted tables, the entry is determined using a binary search. The workload has a logarithmic relationship to the number of entries in the table.
    In hashed tables, the entry is determined using the hash administrator of the table and is always independent of the number of table entries.
    So does this mean if we're populating a table using COLLECT we should prefer STANDARD over SORTED(due to the HASH administration)? Is there any performance overload while setting up the temporary hash administrator for STANDARD tables?
    Please enlighten me.
    BR,
    Suhas

    Actually I have just noticed I already had created a test program for this somewhere in the past.
    Here are the results:
    STANDARD            1.091.295
    SORTED              3.159.771
    HASHED                994.101
    If for the STANDARD table you somehow destroy the hash administration (in this case it was done in the beginning by APPENDing one record):
    STANDARD            2.255.905
    SORTED                 14.013
    HASHED                  8.022
    (this 2nd execution was with less rows that the 1st execution, otherwise for the standard table it would take too long).
    So this does prove that standard tables can be faster than sorted tables in that special case, but again I would not rely on that.
    Rui Dantas

  • How to disable automatic statistics collections on tables

    Hi
    I am using Oracle 10g and we have few tables which are frequently truncated and news rows added to it. Oracle automatically analyzes the table by some means which collects statistics of the table but at the wrong time(when the table is empty). This makes my query to do a full table scan rather using indexes since the statistics was collected when the table was empty.Could any one please let me know how to disable the automatic statistics collection feature of Oracle?
    Cheers
    Anantha PV

    Hi
    I am using Oracle 10g and we have few tables which
    are frequently truncated and news rows added to it.
    Oracle automatically analyzes the table by some means
    which collects statistics of the table but at the
    wrong time(when the table is empty). This makes my
    query to do a full table scan rather using indexes
    since the statistics was collected when the table was
    empty.Could any one please let me know how to disable
    the automatic statistics collection feature of
    Oracle?
    First of all I think it's important that you understand why Oracle collects statistics on these tables: Because it considers the statistics of the object to be missing or stale. So if you just disable the statistics gathering on these tables then you won't have statistics at all or outdated statistics.
    So as said by the previous posts you should gather the statistics manually yourself anyway. If you do so right after loading the data into the truncated table, you don't need to disable the automatic statistics gathering as it only processes objects that are stale or don't have statistics at all.
    If you still think that you need to disable it there are several ways to accomplish it:
    As already mentioned, for particular objects you can lock the statistics using DBMS_STATS.LOCK_TABLE_STATS, or for a complete schema using DBMS_STATS.LOCK_SCHEMA_STATS. Then these statistics won't be touched by the automatic gathering job. You still can gather statistics using the FORCE=>true option of the GATHER__STATS procedures.
    If you want to change the automatic gathering job that it only gathers statistics on objects owned by Oracle (data dictionary, AWR etc.), then you can do so by calling DBMS_STATS.SET_PARAM('AUTOSTATS_TARGET', 'ORACLE'). This is the recommended method.
    If you disable the schedule job as mentioned in the documentation by calling DBMS_SCHEDULER.DISABLE('GATHER_STATS_JOB') then no statistics at all will be gathered automatically, causing your data dictionary statistics to be become stale over time, which could lead to suboptimal performance of queries on the data dictionary.
    All this applies to Oracle 10.2, some of the features mentioned might not be available in Oracle 10.1 (as you haven't mentioned your version of 10g).
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Returning Collection using table function

    Hi,
    I'm trying to return a collection with record type using table function but facing some issues.
    Could someone help me with it.
    SUNNY@11gR1> create or replace package test_pack as
      2  type rec_typ is record (
      3  empname varchar2(30),
      4  empage number(2),
      5  empsal number(10));
      6  type nest_typ is table of rec_typ;
      7  function list_emp return nest_typ;
      8  end;
      9  /
    Package created.
    Elapsed: 00:00:00.01
    SUNNY@11gR1> create or replace package body test_pack is
      2  function list_emp return nest_typ is
      3  nest_var nest_typ := nest_typ();
      4  begin
      5  nest_var.extend;
      6  nest_var(nest_var.last).empname := 'KING';
      7  nest_var(nest_var.last).empage := 25;
      8  nest_var(nest_var.last).empsal := 2500;
      9  nest_var.extend;
    10  nest_var(nest_var.last).empname := 'SCOTT';
    11  nest_var(nest_var.last).empage := 22;
    12  nest_var(nest_var.last).empsal := 3500;
    13  nest_var.extend;
    14  nest_var(nest_var.last).empname := 'BLAKE';
    15  nest_var(nest_var.last).empage := 1;
    16  return nest_var;
    17  end;
    18  end;
    19  /
    Package body created.
    Elapsed: 00:00:00.01
    SUNNY@11gR1> select * from table(test_pack.list_emp);
    select * from table(test_pack.list_emp)
    ERROR at line 1:
    ORA-00902: invalid datatype
    Elapsed: 00:00:00.01
    SUNNY@11gR1>Regards,
    Sunny

    But if I use pipelined function instead then I'm able to retrieve the records
    SUNNY@11gR1> create or replace package test_pack as
      2  type rec_typ is record (
      3  empname varchar2(30),
      4  empage number(2),
      5  empsal number(10));
      6  type nest_typ is table of rec_typ;
      7  function list_emp return nest_typ pipelined;
      8  end;
      9  /
    Package created.
    SUNNY@11gR1> ed
    Wrote file afiedt.buf
      1  create or replace package body test_pack as
      2  function list_emp return nest_typ pipelined is
      3  rec_var rec_typ;
      4  begin
      5  rec_var.empname := 'KING';
      6  rec_var.empage := 24;
      7  rec_var.empsal := 10000;
      8  pipe row(rec_var);
      9  rec_var.empname:='SCOTT';
    10  rec_var.empage:=22;
    11  rec_var.empsal:=2000;
    12  pipe row(rec_var);
    13  rec_var.empname:='BLAKE';
    14  rec_var.empage:='1';
    15  pipe row(rec_var);
    16  return;
    17  end;
    18* end;
    SUNNY@11gR1> /
    Package body created.
    Elapsed: 00:00:00.01
    SUNNY@11gR1> select * from table(test_pack.list_emp);
    EMPNAME                            EMPAGE     EMPSAL
    KING                                   24      10000
    SCOTT                                  22       2000
    BLAKE                                   1       2000
    Elapsed: 00:00:00.00Why is that?
    Regards,
    Sunny

  • Collections screen tables in R12

    Hi,
    I have a requirement to create a new Collector Call history in R12 as these report have been dicommissioned in R12. User is entering the data in Notes and Task tab in the Collection screen. When we select the Organization and select View -Customer- Then it will display all notes in notes tab. I am not able to find out the link between these two.How notes data is displaying customer wise.The table/view AST_NOTES_DETAILS_Vl is having source_object_id field which contains the Customer account ID but when when user enter the notes using Interaction screen then there is no cust_Accout_id. Then how it displays the data? I am really confused... What are the tables names of Interaction screen and what is the link???
    Please help..
    Thanks,
    Joohi

    1. choose a db
    3. learn sql
    3. learn jdbc
    4. build db and tables
    5. connect to db
    6. execute appropriate sql statements
    7. btw, consider db connection pooling and dao layer
    8. have a nice day

  • Joins between DATA COLLECTIONS and TABLES

    I would like to know if is there any way to create one data collection with a query result, but I must join this data collection with an exist table, I cant use the GLOBAL TEMPORARY TABLE because I cant create a table in the module. I would like to do just what the SQL Server do with the @.

    sql>create type tnumbercollection as table of number;
      2  /
    Type created.
    sql>declare
      2    c  tNumberCollection;
      3  begin 
      4    select employee_no bulk collect
      5      into c
      6      from mrt_user_master
      7     where rownum <= 5;  -- build collection of 5 employee numbers
      8 
      9    for r in (select um.last_name
    10                from user_master um, table(cast(c as tNumberCollection)) t
    11               where um.employee_no = t.column_value) loop  -- join the collection to the table
    12 
    13      dbms_output.put_line( r.last_name);          
    14 
    15    end loop; 
    16  end;
    17  /
    PL/SQL procedure successfully completed.

  • COLLECT into table of VARCHAR2 giving ORA-22814 error

    Hello,
    I am trying to collect a VARCHAR2(5 CHAR) column into a table type of VARCHAR2(5 CHAR) but it gives me the ORA-22814: attribute or element value is larger than specified in type.
    Even if I cast my string to this data type.
    SQL> CREATE OR REPLACE TYPE T_VARCHAR2_5_TAB AS TABLE OF VARCHAR2(5 CHAR);
      2  /
    Type created.
    SQL>
    SQL> DESC site_section_cours;
    Name                                      Null?    Type
    SEQ_SITE_COURS                            NOT NULL NUMBER
    CODE_SESSION                              NOT NULL VARCHAR2(6 CHAR)
    NUMERO_REFERENCE_SECTION_COURS            NOT NULL VARCHAR2(5 CHAR)
    CODE_STATUT_PUBLICATION_PDF               NOT NULL VARCHAR2(2 CHAR)
    CONTROLE_MODIFICATION                     NOT NULL NUMBER
    SEQ_BAREME_NOTES                                   NUMBER
    SQL>
    SQL> SELECT CAST(
      2              COLLECT(
      3              sisc.numero_reference_section_cours
      4              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      5              )
      6              AS t_varchar2_5_tab
      7           ) AS lov
      8  FROM   site_section_cours sisc;
              COLLECT(
    ERROR at line 2:
    ORA-22814: attribute or element value is larger than specified in type
    SQL>
    SQL> SELECT CAST(
      2              COLLECT(
      3              CAST(
      4                sisc.numero_reference_section_cours AS VARCHAR2 (5 CHAR)
      5              )
      6              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      7              )
      8              AS t_varchar2_5_tab
      9           ) AS lov
    10  FROM   site_section_cours sisc;
              COLLECT(
    ERROR at line 2:
    ORA-22814: attribute or element value is larger than specified in type What am I missing?
    Thanks
    Bruno

    A new test: try to collect into 10 and 20 char table type.
    Not working with 10 but working with 20.
    SQL> SELECT CAST(
      2              COLLECT(
      3              sisc.numero_reference_section_cours
      4              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      5              )
      6              AS t_varchar2_10_tab
      7           ) AS lov
      8  FROM   site_section_cours sisc;
              COLLECT(
    ERROR at line 2:
    ORA-22814: attribute or element value is larger than specified in type
    SQL>
    SQL> SELECT CAST(
      2              COLLECT(
      3              sisc.numero_reference_section_cours
      4              ORDER BY sisc.code_session, sisc.numero_reference_section_cours
      5              )
      6              AS t_varchar2_20_tab
      7           ) AS lov
      8  FROM   site_section_cours sisc;
    LOV                                                                            
    T_VARCHAR2_20_TAB('10001', '10003', '10004', '10016', '10018', '10019', '10020',
    '10022', '10025', '10028', '10029', '10030', '10031', '10032', '10039', '10040'
    , '10041', '10003', '21000', '21001', '21002', '21004', '21005', '21006', '21007
    ', '21008', '21009', '21010', '82001', '11972', '11986', '10018', '10019')      Bruno

  • PLSQL script not collecting temp table fields - variables problem?

    I've 'written' a script to extract data from a temp table and load it directly into the associated Oracle tables via HRMS's
    API packages.. but when I put the DBMS_OUTPUT.PUT_LINE's in I see that although it seems to read first API OK it doesn't collect the information from their relevant fields in the temp table.. Can anyone help please please..?
    ======================== code ==========================
    SET serveroutput ON SIZE 1000000
    SET verify OFF
    SET feedback OFF
    DECLARE
    -- Debugging/error handling
    v_err_seq NUMBER := 0;
    v_err_num VARCHAR2 (30);
    v_err_msg VARCHAR2 (250);
    v_err_line VARCHAR2 (350);
    -- Work variables
    p_hire_date DATE;
    p_business_group_id NUMBER := 0;
    p_person_id NUMBER := 0;
    p_address_line1 VARCHAR2 (240);
    p_date_of_birth VARCHAR2 (35);
    p_address_line2 VARCHAR2 (240);
    employee_number VARCHAR2 (14);
    p_employee_number VARCHAR2 (14);
    emp_number VARCHAR2 (14);
    p_email_address VARCHAR2 (240);
    p_address_line3 VARCHAR2 (240);
    p_first_name VARCHAR2 (150);
    p_address_line4 VARCHAR2 (240);
    p_middle_names VARCHAR2 (30);
    p_post_code VARCHAR2 (30);
    p_last_name VARCHAR2 (150);
    p_nationality VARCHAR2 (30);
    p_sex VARCHAR2 (30);
    p_national_identifier VARCHAR2 (30);
    p_title VARCHAR2 (30);
    v_rec_cnt NUMBER := 0;
    insert_flag VARCHAR2 (8);
    -- ip_p_address_id NUMBER;
    ip_p_address_id per_addresses.address_id%TYPE;
    ip_p_object_version_number NUMBER;
    ip_p_party_id per_addresses.party_id%TYPE;
    l_person_id per_all_people_f.person_id%TYPE;
    l_employee_number VARCHAR2 (35);
    l_validate BOOLEAN DEFAULT FALSE;
    l_assignment_id NUMBER;
    l_per_object_version_number NUMBER;
    l_asg_object_version_number NUMBER;
    l_per_effective_start_date DATE;
    l_per_effective_end_date DATE;
    l_full_name VARCHAR2 (240);
    l_per_comment_id NUMBER;
    l_assignment_sequence NUMBER;
    l_assignment_number VARCHAR2 (100);
    l_name_combination_warning BOOLEAN;
    l_assign_payroll_warning BOOLEAN;
    l_address_id NUMBER;
    l_object_version_number NUMBER;
    return_code NUMBER;
    return_message VARCHAR2 (2000);
    command_prin VARCHAR2 (4000);
    -- Get employee details info from work table
    CURSOR get_employee_details
    IS
    SELECT p_person_id, p_validate, p_hire_date, p_business_group_id,
    p_last_name, p_sex, p_date_of_birth, p_email_address,
    p_employee_number, p_first_name, p_marital_status,
    p_middle_names, p_nationality, p_title, p_national_identifier,
    p_address_line1, p_address_line2, p_address_line3,
    p_address_line4, p_post_code
    FROM SU_TEMPLOYEE_DETAILS;
    -- checks employee details info from PER_ALL_PEOPLE_F table
    -- v_err_seq := 1;
    CURSOR c_check_employee (emp_number VARCHAR2)
    IS
    SELECT per.person_id, per.business_group_id, per.last_name,
    per.start_date, per.date_of_birth, per.email_address,
    per.employee_number, per.first_name, per.marital_status,
    per.middle_names, per.nationality, per.national_identifier,
    per.sex, per.title, padd.address_id, padd.primary_flag,
    padd.address_line1, padd.address_line2, padd.address_line3,
    padd.town_or_city, padd.postal_code, padd.telephone_number_1,
    padd.object_version_number
    FROM per_all_people_f per, per_addresses padd
    WHERE per.employee_number = emp_number
    AND per.person_id = padd.person_id;
    emp_rec c_check_employee%ROWTYPE;
    BEGIN
    --v_err_seq := 2;
    command_prin := SQLERRM;
    LOOP
    -- Process each record in the work table
    FOR v_emp IN get_employee_details
    LOOP
    v_rec_cnt := v_rec_cnt + 1;
    -- determine whether customer already exists
    OPEN c_check_employee (v_emp.p_employee_number);
    FETCH c_check_employee
    INTO emp_rec;
    IF c_check_employee%NOTFOUND
    THEN
    insert_flag := 'I';
    ELSE
    insert_flag := 'X';
    END IF;
    IF insert_flag = 'I'
    THEN
    -- RETURN 'Employee does not exist, continue import..';
    DBMS_OUTPUT.PUT_LINE ('Employee does not exist, continue import..');
    ELSE
    DBMS_OUTPUT.PUT_LINE ('Employee found - record cannot be imported.');
    END IF;
    CLOSE c_check_employee;
    -- v_err_seq := 3;
    -- Create new PER_ALL_PEOPLE_F and PER_ADDRESSES record from
    -- info in table record
    IF insert_flag = 'I'
    THEN
    BEGIN -- Importing Employee Procedure --
    DBMS_OUTPUT.PUT_LINE ('          ');
    DBMS_OUTPUT.PUT_LINE ('Importing employees....Hold On.......!     ');
         DBMS_OUTPUT.PUT_LINE ('          ');
    BEGIN
    Hr_Employee_Api.create_gb_employee
    (p_validate => l_validate, --FALSE,
    p_hire_date => p_hire_date,
    p_business_group_id => p_business_group_id,
    p_date_of_birth => p_date_of_birth,
    p_email_address => p_email_address,
    p_first_name => p_first_name,
    p_middle_names => p_middle_names,
    p_last_name => p_last_name,
    p_sex => p_sex,
    p_ni_number => p_national_identifier,
    p_employee_number => l_employee_number,
    p_person_id => l_person_id,
    p_title => p_title,
    p_assignment_id => l_assignment_id,
    p_per_object_version_number => l_per_object_version_number,
    p_asg_object_version_number => l_asg_object_version_number,
    p_per_effective_start_date => l_per_effective_start_date,
    p_per_effective_end_date => l_per_effective_end_date,
    p_full_name => l_full_name,
    p_per_comment_id => l_per_comment_id,
    p_assignment_sequence => l_assignment_sequence,
    p_assignment_number => l_assignment_number,
    p_name_combination_warning => l_name_combination_warning,
    p_assign_payroll_warning => l_assign_payroll_warning
    DBMS_OUTPUT.PUT_LINE
    ('..employee record updated succesfully..');
    DBMS_OUTPUT.PUT_LINE ('          ');
    DBMS_OUTPUT.PUT_LINE ('          ');
    EXCEPTION
    WHEN OTHERS
    THEN
    DBMS_OUTPUT.PUT_LINE ('..SQLCodeErrors:- ' || SQLCODE);
         DBMS_OUTPUT.PUT_LINE (' ');
    DBMS_OUTPUT.PUT_LINE ('Person ID:-' || p_person_id || l_person_id);
    DBMS_OUTPUT.PUT_LINE ('Assignmnt Seq - '|| l_assignment_sequence);
    DBMS_OUTPUT.PUT_LINE ('l_ass_no - ' ||l_assignment_number);
    -- DBMS_OUTPUT.PUT_LINE ('Record failed to load.. ' || SQLERRM);
    DBMS_OUTPUT.PUT_LINE (SUBSTR (command_prin, 1, 250));
    END;
    BEGIN -- Importing Associated Address Procedure --
    DBMS_OUTPUT.PUT_LINE ('          ');
    -- ('..and the associated employee address....');
    Hr_Person_Address_Api.create_person_address
    (p_validate => l_validate,
    -- p_effective_date => p_hire_date,
    p_effective_date => SYSDATE,
    p_pradd_ovlapval_override => NULL,
    p_validate_county => NULL,
    p_person_id => l_person_id,
    p_primary_flag => 'Y',
    p_style => 'GB_GLB',
    -- p_date_from => p_hire_date,
    p_date_from => SYSDATE,
    p_date_to => NULL,
    p_address_type => NULL,
    p_comments => NULL,
    p_address_line1 => p_address_line1,
    p_address_line2 => p_address_line2,
    p_address_line3 => p_address_line3,
    p_town_or_city => p_address_line4,
    p_region_1 => NULL,
    p_region_2 => NULL,
    p_region_3 => NULL,
    p_postal_code => p_post_code,
    p_country => p_nationality,
    p_telephone_number_1 => NULL,
    p_telephone_number_2 => NULL,
    p_telephone_number_3 => NULL,
    p_addr_attribute_category => NULL,
    p_addr_attribute1 => NULL,
    p_addr_attribute2 => NULL,
    p_addr_attribute3 => NULL,
    p_addr_attribute4 => NULL,
    p_addr_attribute5 => NULL,
    p_addr_attribute6 => NULL,
    p_addr_attribute7 => NULL,
    p_addr_attribute8 => NULL,
    p_addr_attribute9 => NULL,
    p_addr_attribute10 => NULL,
    p_addr_attribute11 => NULL,
    p_addr_attribute12 => NULL,
    p_addr_attribute13 => NULL,
    p_addr_attribute14 => NULL,
    p_addr_attribute15 => NULL,
    p_addr_attribute16 => NULL,
    p_addr_attribute17 => NULL,
    p_addr_attribute18 => NULL,
    p_addr_attribute19 => NULL,
    p_addr_attribute20 => NULL,
    p_add_information13 => NULL,
    p_add_information14 => NULL,
    p_add_information15 => NULL,
    p_add_information16 => NULL,
    p_add_information17 => NULL,
    p_add_information18 => NULL,
    p_add_information19 => NULL,
    p_add_information20 => NULL,
    -- p_party_id => NULL,
    p_party_id => ip_p_party_id,
    p_address_id => ip_p_address_id,
    p_object_version_number => ip_p_object_version_number
    DBMS_OUTPUT.PUT_LINE ('Address Updation/Insertion has been successful!');
    EXIT WHEN command_prin IS NULL;
    command_prin := SUBSTR (command_prin, 251);
    END;
    END;
    -- v_err_seq := 4;
    -- End of customer related details
    END IF;
    END LOOP;
    -- DBMS_OUTPUT.PUT_LINE ('Records read : ' || v_rec_cnt);
    -- v_err_seq := 5;
    --EXCEPTION
    -- WHEN OTHERS THEN
    -- ROLLBACK;
    -- Output Error Message
    -- v_err_num := TO_CHAR(SQLCODE);
    -- v_err_msg := SUBSTR(SQLERRM,1,250);
    -- v_err_line := 'Oracle error (seqno=' || v_err_seq || ') ' ||
    -- v_err_num ||' occurred processing record '||
    -- TO_CHAR(v_rec_cnt + 1) ||' : '||v_err_msg;
    -- DBMS_OUTPUT.PUT_LINE(v_err_line);
    END LOOP;
    COMMIT;
    END;
    --END;
    EXIT;
    ======================================================
    many thanks to all...
    Steven

    Ive just sussed it - I had'nt put the 'v_emp' at the front of the fields from the temp table to pick then up! we continue..

  • What's the best way to collect internal table?

    Hi,
    I have an internal table, the fields are:
      Key1, key2, key3, qty1, qty2, qty3
    I want to collect the field "qty3" based on the key fields: "key1 + key2 + key3".
    What's the most efficient way to collect the internal table?
    Thanks.

    Hi Ren,
    You can code something like this with COLLECT statement.
    DATA: BEGIN OF ITAB OCCURS 0,
            KEY1 TYPE TABLE1-FIELD1,
            KEY2 TYPE TABLE1-FIELD2,
            KEY3 TYPE TABLE1-FIELD3,
            QTY1 TYPE TABLE2-QTY1,
            QTY2 TYPE TABLE2-QTY2,
            QTY3 TYPE TABLE2-QTY3.
    DATA: END OF ITAB.
    DATA: BEGIN OF ITAB2 OCCURS 0,
            KEY1 TYPE TABLE1-FIELD1,
            KEY2 TYPE TABLE1-FIELD2,
            KEY3 TYPE TABLE1-FIELD3,
            QTY3 TYPE TABLE2-QTY3.
    DATA: END OF ITAB2.
    SORT ITAB.
    LOOP AT ITAB.
      MOVE-CORRESPONDING ITAB TO ITAB2.
      COLLECT ITAB2.
    ENDLOOP.
    LOOP AT ITAB2.
      WRITE: /01 ITAB2-KEY1, ITAB2-KEY2, ITAB2-KEY3,
                 ITAB3-QTY3.
    ENDLOOP.
    Hope this will help and give an idea.
    Regards,
    Ferry Lianto
    Please reward points if helpful.

  • Collection -- Nested tables

    Hi,
    I am trying to use collections as nested tables from below mentioned procedure, but facing a problem of getting only last rows.
    Any help would be appreciated.
    +CREATE OR REPLACE PROCEDURE pr_collection
    AS
    TYPE type_num IS TABLE OF NUMBER;
    t_num type_num;
    TYPE type_char IS TABLE OF VARCHAR2 (20);
    t_char type_char;
    BEGIN
    FOR i IN (SELECT eid, nm
    FROM emp)
    LOOP
    t_num := type_num (i.eid);
    t_char := type_char (i.nm);
    DBMS_OUTPUT.put_line (i.eid || i.nm);
    END LOOP;
    DBMS_OUTPUT.put_line (t_num.COUNT);
    DBMS_OUTPUT.put_line (t_num.FIRST);
    DBMS_OUTPUT.put_line (t_num.LAST);
    FORALL J IN T_NUM.FIRST.. T_NUM.LAST
    INSERT INTO TEST
    VALUES (t_num (J), t_char (J));
    COMMIT;
    END;
    /+
    Output :
    1
    1
    1
    Thanks in Advance,
    Prashant

    Hi,
    It's normal, you get only the last element because of the following
    LOOP
        t_num := type_num (i.eid);
        t_char := type_char (i.nm);
    END LOOP;Each time you call the nested table constructor with the new element, so the previous elements are lost. The correct way of doing this is to call once the constructor before the LOOP and then call the EXTEND method inside the loop in order to make room available for each new element.
    Therefore, something like this:
    CREATE OR REPLACE PROCEDURE pr_collection AS
        TYPE type_num IS TABLE OF NUMBER;
        t_num type_num;
        t_num_idx PLS_INTEGER := 1;
        TYPE type_char IS TABLE OF VARCHAR2 (20);
        t_char type_char;
        t_char_idx PLS_INTEGER := 1;
    BEGIN
        t_char := type_char();
        t_num := type_num();
        FOR i IN (SELECT eid, nm FROM emp) LOOP
            t_num.EXTEND;
            t_num(t_num_idx) := i.eid;
            t_num_idx := t_num_idx + 1;
            t_char.EXTEND;
            t_char(t_char_idx) := i.nm;
            t_char_idx := t_char_idx + 1;
            DBMS_OUTPUT.put_line (i.eid || i.nm);
        END LOOP;
        DBMS_OUTPUT.put_line (t_num.COUNT);
        DBMS_OUTPUT.put_line (t_num.FIRST);
        DBMS_OUTPUT.put_line (t_num.LAST);
        FORALL J IN T_NUM.FIRST.. T_NUM.LAST
            INSERT INTO TEST VALUES (t_num (J), t_char (J));
        COMMIT;
    END;That being said, why do you add elements one by one, it is slow, why not using BULK COLLECT?
    Regards,
    Dariyoosh

  • Default collection Database Tables Changed!!!

    Hello,
    First of all I would like to thank Microsoft for an amazing product Team Foundation Server 2013. We recently migrated from TFS 2012 to TFS 2013 and My Team loved it !!! Especially the team collaboration features and "Features".
    My query is regarding Team Foundation Server Default Collection Database. I have a report in SSRS for Test Cases Statistics wherein we use tables viz. - "tbl_Plan" and "tbl_Suite". The mapping between these two tables has been done on
    basis of RootSuiteId of tbl_Plan and ParentSuiteId of tbl_Suite and PlanId of both tables.
    Till Team foundation server 2012 the table tbl_Plan had a column - "Name".
    In Team foundation server 2013, when I compile the procedure written for the Report, I get a compilation error for this column, since this no more exists in tbl_Plan. The column Name exists in tbl_PlanData now. I can't infer how to map the tables tbl_Plan
    and tbl_PlanData to keep my report working.
    Please help!!!
    Thanks in advance.
    Best Regards
    Yogesh kumar Hindoliya

    You should be using the TFS data warehouse (default db name: Tfs_Warehouse), preferably through the associated SSRS server.
    "You will find a fortune, though it will not be the one you seek." -
    Blind Seer, O Brother Where Art Thou
    Please Mark posts as answers or helpful so that others may find the fortune they seek.

  • Table function on a collection in Dynamic SQL

    Hello,
    I am trying to create a refcursor by selecting from a collection using table function.
    If I use the Select statement the query executes, but if I put the Select statement in a string
    the collection variable does not get resolved. The resaon I am putiing it in a string is because the
    WHERE clause will be passed a parameter. The code below is an anonymous block but will be changed to a
    procedure once I get it to work.
    I have tried many different ways but was unsuccessful.
    Please see if anybody cann assist or what I am trying to achive is not possible, so provide an alternative.
    The error I am getting is
    ORA-00904: "V_ALARM_REC_TABLE": invalid identifier
    ORA-06512: at line 50
    Thanks.
    Bimal
    DECLARE
    TYPE c_refcurtype IS REF CURSOR;
    x c_refcurtype;
    p_recordset c_refcurtype;
    v_rec mc2_dev2.mc2_alarm_rec_type := mc2_dev2.mc2_alarm_rec_type(null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null,null,
    null,null,null,null,null,null,null);
    v_alarm_rec_table mc2_dev2.mc2_alarm_rec_table := mc2_dev2.mc2_alarm_rec_table();
    v_select varchar2(200) := 'select a.* from ';
    v_table varchar2(200) := 'table(v_alarm_rec_table) a ';
    v_where varchar2(200) := 'where a.alarm_rule_def_uid = 9';
    v_query varchar2(32000);
    BEGIN
    MC2_ALARM.create_mc2_alarm(x, 1); --- ( X is a refcursor, which I will use to populate v_alarm_rec_table a (nested table collection)
    LOOP
    FETCH x INTO v_rec.record_cnt,
    v_rec.rn,
    v_rec.alarm_precision_order,
    v_rec.alarm_rule_def_uid,
    v_rec.alarm_type_def_uid,
    v_rec.alarm_rule_scope_uid,
    v_rec.trigger_tpl_master_uid,
    v_rec.alarm_scope_def_uid,
    v_rec.alarm_object_uid,
    v_rec.error_type,
    v_rec.all_error_codes,
    v_rec.enabled,
    v_rec.start_hour,
    v_rec.end_hour,
    v_rec.day_type,
    v_rec.alarm_severity_def_uid,
    v_rec.on_watch_duration,
    v_rec.update_on_status_change,
    v_rec.log_ind,
    v_rec.email_to,
    v_rec.email_from,
    v_rec.send_email,
    v_rec.stale_period;
    EXIT WHEN x%NOTFOUND;
    v_alarm_rec_table.extend;
    v_alarm_rec_table(v_alarm_rec_table.last) := v_rec;
    END LOOP;
    CLOSE x;
    v_query := v_select||v_table||v_where; -- ERROR OCCURS AT THIS LINE as it cannot resolve the TABLE name  v_alarm_rec_table)
    dbms_output.put_line('sql: '||v_query);
    OPEN p_recordset FOR v_query;
    LOOP
    FETCH p_recordset INTO v_rec.record_cnt,
    v_rec.rn,
    v_rec.alarm_precision_order,
    v_rec.alarm_rule_def_uid,
    v_rec.alarm_type_def_uid,
    v_rec.alarm_rule_scope_uid,
    v_rec.trigger_tpl_master_uid,
    v_rec.alarm_scope_def_uid,
    v_rec.alarm_object_uid,
    v_rec.error_type,
    v_rec.all_error_codes,
    v_rec.enabled,
    v_rec.start_hour,
    v_rec.end_hour,
    v_rec.day_type,
    v_rec.alarm_severity_def_uid,
    v_rec.on_watch_duration,
    v_rec.update_on_status_change,
    v_rec.log_ind,
    v_rec.email_to,
    v_rec.email_from,
    v_rec.send_email,
    v_rec.stale_period;
    EXIT WHEN p_recordset%NOTFOUND;
    some dbms_output statements...
    END LOOP;
    END;
    The error I am getting is
    ORA-00904: "V_ALARM_REC_TABLE": invalid identifier
    ORA-06512: at line 50

    Thanks Timur/Solomon,
    mc2_dev2 is the schema name.
    mc2_alarm_rec_table is a SQL type.
    Here are the scripts:
    CREATE OR REPLACE TYPE MC2_DEV2.mc2_alarm_rec_type IS OBJECT
    ( record_cnt NUMBER,
    rn number,
    alarm_precision_order NUMBER(6),
    alarm_rule_def_uid NUMBER(6),
    alarm_type_def_uid NUMBER(6),
    alarm_rule_scope_uid NUMBER(6),
    trigger_tpl_master_uid NUMBER(6),
    alarm_scope_def_uid NUMBER(6),
    alarm_object_uid NUMBER(6),
    error_type VARCHAR2(1),
    all_error_codes VARCHAR2(1),
    enabled VARCHAR2(1),
    start_hour NUMBER(2),
    end_hour NUMBER(2),
    day_type NUMBER(2),
    alarm_severity_def_uid NUMBER(6),
    on_watch_duration NUMBER(6),
    update_on_status_change VARCHAR2(1),
    log_ind VARCHAR2(1),
    email_to VARCHAR2(128),
    email_from VARCHAR2(128),
    send_email VARCHAR2(1),
    stale_period          NUMBER(6)
    CREATE OR REPLACE TYPE MC2_DEV2.MC2_ALARM_REC_TABLE IS TABLE OF MC2_DEV2.mc2_alarm_rec_type;
    If I popoulate the cursor with the following code:
    OPEN p_recordset FOR
    select a.* from table (v_alarm_rec_table) a where a.alarm_rule_def_uid = 9;
    there is no issue it works just fine.
    But when when I use
    OPEN p_recordset FOR v_query; ---- where v_query := v_select||v_table||v_where;
    the variable v_alarm_rec_table does not get resolved.
    Regards,
    Bimal

  • For loop or table cast to collection variable

    Hi ,
    I have a collection variable (Table type) which can have at-most 20 variables in it. I want to fetch one particular record.
    Which is more efficient; a For loop* or a table cast* ?
    Thanks,

    @Karthick, The requirement is like I have a query (with 2 joins in it) in a procedure which is executing about 50Lac times, and out of 50Lac execution it is fetching same data for say 25000 records.
    I mean query output is same for 25000 records (not fixed) and then it is same for next 25000 records. So I took a collection variable and did a BULK COLLECT to a variable and trying to process (fetch) data in memory instead of hitting the query again (and table ) again.
    Also query is taking 0.001 sec per execution but it is running for so many times thats why procedure is taking time. Oracle performs 2 type of I/O
    1. Physical I/O
    This happens when oracle picks up the data blocks from the data file and puts it in the Data buffer (SGA)
    2. Logical I/O
    This happens when oracle picks up data block from Data buffer (SGA)
    In Data Buffer the data is stored in FIFO basis. So when you hit a table for the first time oracle goes for a physical I/O the subsequent time it will go for Logical I/O.
    What you are trying to do oracle does it already. You don't have to use a collection. Collection uses expensive private memory (PGA).
    And again the basic question is why are you executing a procedure 50,00,000 times?

  • Can you input records to a COLLECTION TYPE object and use it as a table??

    My PL/SQL stored procedure creates a list of employee number and phone number records. I don't want to store them in a table. I will be passing this list from one procedure to another in my package.
    I created the object type (record) and collection type (table) using this statements.
    CREATE TYPE obj_emp_phone_rec AS OBJECT
         emp_number   NUMBER,
         emp_phone    VARCHAR2(100)
    CREATE TYPE obj_emp_phone_recs_table AS TABLE OF obj_emp_phone_rec
    /Thing is, can I use the obj_emp_phone_recs_table "table type" as a table?
    I.e. can I insert records to this in the package procedure and pass reference to it in called sub-procedures.
    i.e. something like this
    PACKAGE BODY abc IS
      PROCEDURE kdkddk IS
      BEGIN
        -- Insert records to the  obj_emp_phone_recs_table
        obj_emp_phone_recs_table(1).emp_number := '1';
        obj_emp_phone_recs_table(1).emp_phone   := '0774949494';
        obj_emp_phone_recs_table(2).emp_number := '234';
        obj_emp_phone_recs_table(2).emp_phone   := '285494';
        -- Pass the table to the sub procedure
        xyx(obj_emp_phone_recs_table);
      END kdkddk;
    END abc;If so how to insert to the obj_emp_phone_recs_table ???
    Nothing on the net. In the Net I found only where u define a normal table's column as an object type and then inserting records to it.
    Any help would be greatly appreciated.
    Edited by: user12240205 on Oct 6, 2011 2:08 AM

    mhouri > drop type obj_emp_phone_recs_table;
    Type dropped.
    mhouri > drop type obj_emp_phone_rec ;
    Type dropped.
    mhouri > CREATE TYPE obj_emp_phone_rec AS OBJECT
      2    (
      3       emp_number   NUMBER,
      4       emp_phone    VARCHAR2(100)
      5    )
      6  /
    Type created.
    mhouri > CREATE TYPE obj_emp_phone_recs_table AS TABLE OF obj_emp_phone_rec
      2  /
    Type created.
    mhouri > create or replace procedure p1(pin_tab IN obj_emp_phone_recs_table)
      2  is
      3   begin
      4     for j in 1..pin_tab.count
      5     loop
      6      dbms_output.put_line('record number '||j ||'-- emp number --'||pin_tab(j).emp_number);
      7     end loop;
      8 
      9  end p1;
    10  /
    Procedure created.
    mhouri > create or replace procedure p2
      2  is
      3  lin_tab  obj_emp_phone_recs_table := obj_emp_phone_recs_table();
      4  begin
      5  FOR i IN 1 .. 5
      6     LOOP
      7        lin_tab.extend;
      8        lin_tab(i) := obj_emp_phone_rec(i, 'i-i-i');
      9     END LOOP;
    10 
    11    p1(lin_tab);
    12 
    13  end p2;
    14  /
    Procedure created.
    mhouri > set serveroutput on
    mhouri > exec p2
    record number 1-- emp number -- 1                                                                                                                                                                                                                         
    record number 2-- emp number --2                                                                                                                                                                                                                         
    record number 3-- emp number --3                                                                                                                                                                                                                         
    record number 4-- emp number --4                                                                                                                                                                                                                         
    record number 5-- emp number --5                                                                                                                                                                                                                         
    PL/SQL procedure successfully completed.Best Regards
    Mohamed Houri

Maybe you are looking for