Creating variable of type of a PLSQL table type

I have an object defined as
create or replace type emp_rec as object (col1 date, col2 date);
then I defined
create or replace type data_emp_rec is table of emp_rec;
Now I need to define a variable temp_rec which will host data returned of emp_rec structure.
please advise how to define a variable to have data structure similar to that of emp_rec
declare
temp_rec emp_rec(null, null);
or
temp_rec data_emp_rec;
Thx

Hello
It's all about casting data types and supplying the right data type to the bulk collect clause:
SQL> SELECT
  2     usr.nm,
  3     perm.id,
  4     perm.descr
  5  FROM
  6     dt_test_user usr,
  7     dt_test_permission perm,
  8     dt_test_user_permission usr_perm
  9  WHERE
10     usr.id = usr_perm.user_id
11  AND
12     perm.id = usr_perm.permission_id
13  ORDER BY
14     usr.nm
15  /
NM                                     ID DESCR
Barry Bethel                            4 Be very enthusiastic about everything
Barry Bethel                            2 Advertise slimming products
Dr. Evil                                1 Take over the world
Rolf Harris                             4 Be very enthusiastic about everything
Rolf Harris                             3 Sing very strange songs
SQL> select
  2     usr.id,
  3     usr.nm,
  4     CURSOR(select
  5                             p.user_id
  6                     from
  7                             dt_test_user_permission p
  8                     where
  9                             p.user_id = usr.id
10                     ) pos_cursor
11  from
12     dt_test_user usr
13  /
        ID NM                             POS_CURSOR
         1 Rolf Harris                    CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
   USER_ID
         1
         1
         2 Barry Bethel                   CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
   USER_ID
         2
         2
         3 Dr. Evil                       CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
   USER_ID
         3
SQL> select
  2     usr.id,
  3     usr.nm,
  4     CAST(MULTISET(  select
  5                                                             p.user_id
  6                                                     from
  7                                                             dt_test_user_permission p
  8                                                     where
  9                                                             p.user_id = usr.id
10                                             ) AS permissionList
11                             ) pos_ntt
12  from
13     dt_test_user usr
14  /
        ID NM                             POS_NTT(ID)
         1 Rolf Harris                    PERMISSIONLIST(PERMISSION_TYPE(1), PERMISSION_TYPE
                                          (1))
         2 Barry Bethel                   PERMISSIONLIST(PERMISSION_TYPE(2), PERMISSION_TYPE
                                          (2))
         3 Dr. Evil                       PERMISSIONLIST(PERMISSION_TYPE(3))
SQL> declare
  2     ul userList;
  3  begin
  4     select
  5             usr.id,
  6             usr.nm,
  7             CAST(MULTISET(  select
  8                                                     p.user_id
  9                                             from
10                                                     dt_test_user_permission p
11                                             where
12                                                     p.user_id = usr.id
13                                     ) AS permissionList
14                     ) pos_ntt
15     bulk collect into
16             ul
17     from dt_test_user
18             usr;
19  end;
20  /
        from dt_test_user
ERROR at line 17:
ORA-06550: line 17, column 2:
PL/SQL: ORA-00947: not enough values
ORA-06550: line 4, column 2:
PL/SQL: SQL Statement ignored
SQL> declare
  2     ul userList;
  3  begin
  4     select
  5             user_type(      usr.id,
  6                                     usr.nm,
  7                                     CAST(MULTISET(  select
  8                                                                             p.user_id
  9                                                                     from
10                                                                             dt_test_user_permission p
11                                                                     where
12                                                                             p.user_id = usr.id
13                                                             ) AS permissionList
14                                             )
15                             )
16     bulk collect into
17             ul
18     from dt_test_user
19             usr;
20
21  end;
22  /
PL/SQL procedure successfully completed.
SQL> declare
  2     ul userList;
  3  begin
  4     select
  5             user_type(      usr.id,
  6                                     usr.nm,
  7                                     CAST(MULTISET(  select
  8                                                                             p.user_id
  9                                                                     from
10                                                                             dt_test_user_permission p
11                                                                     where
12                                                                             p.user_id = usr.id
13                                                             ) AS permissionList
14                                             )
15                             )
16     bulk collect into
17             ul
18     from dt_test_user
19             usr;
20
21     FOR li_Idx IN ul.FIRST..ul.LAST LOOP
22
23             dbms_output.put_line(ul(li_Idx).name);
24
25             FOR li_NttIdx IN ul(li_Idx).permissions.FIRST..ul(li_Idx).permissions.LAST LOOP
26
27                     dbms_output.put_line(ul(li_Idx).permissions(li_NttIdx).id);
28
29             END LOOP;
30
31     END LOOP;
32
33  end;
34  /
Rolf Harris
1
1
Barry Bethel
2
2
Dr. Evil
3
PL/SQL procedure successfully completed.HTH
David

Similar Messages

  • How to create APEX report from data in PLSQL table

    Hi, I have a procedure that is creating/inserting records into multidimensional pslql table. I want to create a report and graph based on the data stored in plsql table. Can someone please advice how to can I select this data in apex OR point me to any sample code?
    Thanks
    Aali

    Hi,
    try to google something about ORACLE TABLE CAST
    SELECT ot.yourcolumn
    FROM
       TABLE(CAST(yourplsqltablevariable AS userdefinedoracletype)) otE.g.
    http://it.toolbox.com/blogs/oracle-guide/using-a-plsql-table-in-sql-11013
    Regards,
    R.

  • Report based on plsql table type

    Is it possible crete a report (updatable) based on plsql table type?
    thank in advance
    Franco Galante

    Sorry for my cryptic question, i wanted to mean create a report based on a stored procedure
    function which return a plsql table type variable.
    This idea could give me the chance to work with variable (plsql table) instead of db table.
    hope i'm enough clear
    thank you again
    Franco Galante

  • Mapping of PLSQL  table type  Date to java

    i am having problem in mapping plsql table type DATE in java,
    able to execute procedures which return plsql table type NUMBER,VARCHAR.
    i am using oracle 9 , jdk1.4, oci driver, windows 2000.
    sample code:
    registering:
    st.registerIndexTableOutParameter(15,100,OracleTypes.DATE,1000);
    st.registerIndexTableOutParameter(16,100,OracleTypes.DATE,1000);
    st.execute();
    getting out params in arrays:
    java.sql.Date[] O_lSubFolder_CrOn=(java.sql.Date[])java.sql.Date[] st.getPlsqlIndexTable(15);
    O_lSubFolder_MdOn=(java.sql.Date[])st.getPlsqlIndexTable(16);
    error while executing the code:
    java.sql.SQLException: Invalid PL/SQL Index Table element type
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:180)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:222)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:285)
    at oracle.jdbc.driver.OraclePreparedStatement.checkPlsqlIndexTableBindTypes(OraclePreparedSt
    atement.java:2705)
    at oracle.jdbc.driver.OracleCallableStatement.registerIndexTableOutParameter(OracleCallableS
    tatement.java:834)
    can anyone help me to solve this problem.

    i am having problem in mapping plsql table type
    DATE in java,
    able to execute procedures which return plsql table
    type NUMBER,VARCHAR.
    i am using oracle 9 , jdk1.4, oci driver, windows
    2000.
    sample code:
    registering:
    st.registerIndexTableOutParameter(15,100,OracleTypes.D
    TE,1000);
    st.registerIndexTableOutParameter(16,100,OracleTypes.D
    TE,1000);
    st.execute();
    getting out params in arrays:
    java.sql.Date[]
    O_lSubFolder_CrOn=(java.sql.Date[])java.sql.Date[]
    st.getPlsqlIndexTable(15);
    O_lSubFolder_MdOn=(java.sql.Date[])st.getPlsqlIndexTab
    e(16);
    can anyone help me to solve this problem.1. Write a wrapper procedure that converts the table of dates to either number or date and then re-convert the table back into date.
    2. Since it's an out param you could create a temp table, insert the contents of the index by array into it and return a cursor.
    3. Create a oracle type using CREATE TYPE and then use an array of the type.
    David Rolfe
    Orinda Software

  • How create a record type and a pl/sql table of that record type in database

    Hi
    I want to create a record type and then I want to create a PL/SQL table in the oracle 9i database.
    I have done it in PL/SQL block.
    But when I am trying to do it in database it is throwing me some error.
    Could you please tell me how can I do that?
    Regards

    user576726 wrote:
    Hi
    I want to create a record type and then I want to create a PL/SQL table in the oracle 9i database.
    I have done it in PL/SQL block.
    But when I am trying to do it in database it is throwing me some error.
    Could you please tell me how can I do that?
    RegardsRECORD type is supported only in PL/SQL for SQL you need to use OBJECT type.

  • Japanese characters alone are not passing correctly (passing like ??? or some unreadable characters) to Adobe application when we create input variable as XML data type. The same solution works fine if we change input variable data type to document type a

    Dear Team,
    Japanese characters alone are not passing correctly (passing like ??? or some unreadable characters) to Adobe application when we create input variable as XML data type. The same solution works fine if we change input variable data type to document type. Could you please do needful. Thank you

    Hello,
    most recent patches for IGS and kernel installed. Now it works.

  • Best to use in terms of tuning Global Temporary table or PLSQL Table type

    Hi All,
    which one is best to use in terms of tuning Global Temporary table or PLSQL table type?
    Thanks in Advance.
    Regards
    Deepika

    user8828028 wrote:
    which one is best to use in terms of tuning Global Temporary table or PLSQL table type?The answer to which one is better depends on the requirements - and an informed decision as to which one to use to address those requirements.
    Thus it is important to understand how these work. They are nothing alike.
    PL/SQL collections reside in the PGA. Can only be used in SQL via binding. Cannot be indexed. Temp tables on the other hand does not use expensive PGA. Does not need to be bind in SQL. Can be indexed. Etc.
    Sure, a (surgical) saw and scalpel are both used on the operating table - but for very different purposes.

  • How to improve performance using bulk collects with plsql tables or arrays

    Hi All,
    my procedure is like this
    declare
    cursor c1 is select ----------------------
    begin
    assigning to variables
    validations on that variables
    --50 validations are here --
    insert into a table
    end;
    we have created indexes on primary keys,
    i want to use
    DECLARE
    CURSOR a_cur IS
    SELECT program_id
    FROM airplanes;
    TYPE myarray IS TABLE OF a_cur%ROWTYPE;
    cur_array myarray;
    BEGIN
    OPEN a_cur;
    LOOP
    FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
    ***---------can i assign cursor data to the plsql table variables or array***
    ***validate on the pl sql variable as---***
    i
    nsert into a table
    EXIT WHEN a_cur%NOTFOUND;
    END LOOP;
    CLOSE a_cur;
    END;
    Edited by: Veekay on Oct 21, 2011 4:28 AM

    Fastest way often is this:
    insert /*+append */
    into aTable
    select * from airplanes;
    commit;The select and insert part can even be done in parallel if needed.
    However if the oparation is complex or the dataset is very very very very very large or the programmer is decent but not excellent then the bulk approach should be considered. It is often a pretty stable and linear scaling approach.
    The solution depends a little on the database version.
    LOOP
      FETCH a_cur BULK COLLECT INTO cur_array LIMIT 100;
      EXIT WHEN a_cur.count = 0;
      forall i in a_cur.first.. a_cur.last
      insert into aTable (id)
      values (a_cur(i));
    END LOOP;
    ...If you have more then one column then you might need a single collection for each column. Other possibilities depend on the db version.
    Also: do not exit using a_cur%NOTFOUND. This is wrong! You might loose records from the end of the data set.

  • How to get the plsql table data into output cursor

    Hi,
    Could anybody please help me.
    Below is an example of the scenario..
    CREATE OR REPLACE PACKAGE chck IS
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR);
    TYPE get_rec is record (ename varchar2(20),
    eno number(12));
    TYPE t_recs IS TABLE OF get_rec INDEX BY BINARY_INTEGER;
    emp_tab t_recs;
    END chck;
    CREATE OR REPLACE PACKAGE BODY chck AS
    PROCEDURE getdata(dept_no IN VARCHAR2,oc_result_cursor OUT sys_REFCURSOR)
    is
    BEGIN
    select ename, eno
    bulk collect into emp_tab
    from emp;
    open oc_result_cursor for select * from table(emp_tab); -- I believe something is wrong here ....
    END;
    END chck;
    the above package is giving me an error:
    LINE/COL ERROR
    10/29 PL/SQL: SQL Statement ignored
    10/43 PL/SQL: ORA-22905: cannot access rows from a non-nested table
    item
    let me know what needs to be changed
    Thanks
    Manju

    manjukn wrote:
    once i get the data into a plsql table, how to get this plsql table data into the cursor?There is no such thing as a PL/SQL table - it is an array.
    It is nothing at all like a table. It cannot be indexed, partitioned, cluster, etc. It does not exist in the SQL engine as an object that can be referenced. It resides in expensive PGA memory and needs to be copied (lock, stock and barrel) to the SQL engine as a bind variable.
    It is an extremely primitive structure - and should never be confused as being just like a table.
    Its use in SQL statements is also an exception to the rule. Sound and valid technical reasons need to justify why one want to push a PL/SQL array to the SQL engine to run SELECT 's against it.

  • Internal PLSQL Tables Access via SQL. But how ?

    Hello,
    I want to write the result of a database query in an internal PLSQL Table. After that i would like work with this internal PLSQL Table
    in a Package/Procedure/Function.
    Important for me is to access the internal Table via SQL because i have to refactor a package wich is working with 46 Database Tables an plain SQL. I
    would like to change these DB Tables into internal PLSQL Tables.
    I have written a short example wich will explain my approach to solving this problem.
    The syntax will be accepted by the Database but my 'dbms_output.put_line' statement at the end is empty or blank.
    What do i wrong ? Would be nice if anyone can help me out.
    With best regards
    Jens
    pre work :
    create table PERSON_DB_TABLE
    (SURNAME  VARCHAR2(50),
    LASTNAME VARCHAR2(50));
    insert into PERSON_DB_TABLE values
    ('JENS','FOERSTER');
    insert into PERSON_DB_TABLE values
    ('MAX','MEIER');
    insert into PERSON_DB_TABLE values
    ('MARTHA','MUSTERMANN');
    create type PERSON_OBJECT as object (
        SURNAME  VARCHAR2(50),
        LASTNAME VARCHAR2(50));
    create type PERSON_NESTED_TABLE as table of PERSON_OBJECT;
    now my anonymous block
    declare
       v_PERSON_OBJECT        PERSON_OBJECT;
       v_PERSON_NESTED_TABLE  PERSON_NESTED_TABLE;
       v_PERSON_OBJECT_2      PERSON_OBJECT;
    begin
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT.SURNAME,
                                                                                            v_PERSON_OBJECT.LASTNAME
                                  from PERSON_DB_TABLE)
         loop
            v_PERSON_NESTED_TABLE := PERSON_NESTED_TABLE(v_PERSON_OBJECT);
         end loop;
       for v_counter in (select SURNAME, LASTNAME into v_PERSON_OBJECT_2.SURNAME,
                                                                                            v_PERSON_OBJECT_2.LASTNAME
                                  from TABLE (v_PERSON_NESTED_TABLE))
         loop
            dbms_output.put_line(v_PERSON_OBJECT_2.LASTNAME);
         end loop; 
    end;

    1386a7b8-e834-43bf-a0d4-922b548bb70b wrote:
    I need this, because my customer didn't like the idea to use Database Tables instead of Variables in the RAM. So he wants this procedure redesigned.
    As Mike says, keep this person away from your database.
    Customers should not be dictating how to implement technical solutions, they should be providing business and logical requirements.
    PL/SQL arrays/collections use expensive PGA memory, taking up valuable server resources.
    Copying data from the database to PGA memory to try and process it using PL/SQL is bad design.  SQL is designed specifically for data manipulation using database tables, so it's the ideal way to do process data... directly on database tables.

  • Help with PLSQL table population.....

    Hi all,
    I am populating a PLSQL table from a cursor and then inserting into a target table using FORALL.
    While populating, I need two two records differing only by the process_name.
    Say my populated PLSQL table should look like this.
    vt_proc_status_tbl:
    1     76     Pname_A     20     Sysdate     1     U     1
    1     76     Pname_B     20     Sysdate     1     U     1
    How can I create duplicate records like this inside the PLSQL table varying only by process_name????
    OPEN cur_fcst_sites_ppo;
    FETCH cur_fcst_sites_ppo
    BULK COLLECT INTO vt_fcst_sites_tbl;
    CLOSE cur_fcst_sites_ppo;
    FOR v_idx_fcst_sites IN 1 .. vt_fcst_sites_tbl.COUNT
    LOOP
    BEGIN
    SELECT seq_ods_site_process_status.NEXTVAL
    INTO v_odssiteprocessid
    FROM DUAL;
    END;
    v_pst_idx := v_pst_idx + 1;
    vt_proc_status_tbl (v_pst_idx).odssiteprocessid :=
    v_odssiteprocessid;
    vt_proc_status_tbl (v_pst_idx).SYSTEM := pi_system;
    vt_proc_status_tbl (v_pst_idx).process_name := pi_process_name;
    vt_proc_status_tbl (v_pst_idx).siteid :=
    vt_fcst_sites_tbl (v_idx_fcst_sites).siteid;
    vt_proc_status_tbl (v_pst_idx).bday := pi_transferday;
    vt_proc_status_tbl (v_pst_idx).is_no := pi_is_no;
    vt_proc_status_tbl (v_pst_idx).rest_status := c_status_unprocessed;
    vt_proc_status_tbl (v_pst_idx).batch_id := v_batch_id;
    v_cntr := v_cntr + 1;
    IF v_cntr = pi_sites_at_a_time
    THEN
    v_batch_id := v_batch_id + 1;
    v_cntr := 0;
    END IF;
    v_odssiteprocessid := NULL;
    END LOOP;
    IF v_pst_idx > 0
    THEN
    BEGIN
    FORALL v_proc_status_tbl_idx IN 1 .. vt_proc_status_tbl.COUNT
    INSERT INTO ods_site_process_status
    VALUES vt_proc_status_tbl (v_proc_status_tbl_idx);
    END;
    ELSE
    v_code := NULL;
    SELECT SUBSTR ( '[M]:0- No Site Available for the '
    || pi_process_name
    || ' Process For '
    || DECODE (pi_process_name,
    c_transform_bmi_ppo, 'IS_NO '
    || pi_is_no,
    'TransferDay ' || pi_transferday
    || '..',
    1,
    125
    INTO v_errm
    FROM DUAL;
    DBMS_OUTPUT.put_line (v_errm);
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform_master',
    v_errm,
    vr_market.marketid,
    'I'
    END IF;
    Thanks in Advance.
    Jagadish
    Edited by: user646716 on Oct 12, 2008 10:08 AM
    Edited by: user646716 on Oct 12, 2008 12:02 PM

    hi aweiden,
    Please find my entire code below.
    what I am trying to achieve is that when my plsql table vt_proc_status_tbl is populated, I want two different rows to be populated for different process names (i.e bmi_ppo and bmi_ai ) and load it into ODS_SITE_PROCESS_STATUS table so that i do not have to alter my forall statement.
    Thanks for the help
    PROCEDURE p_mfcst_transform_master (
    pi_system IN mfcst_ppo.SYSTEM%TYPE,
    pi_is_ no IN mfcst_ppo.is_no%TYPE,
    pi_transferday IN mfcst_ppo.transferday%TYPE,
    pi_sites_at_a_time IN NUMBER,
    pi_process_name IN ods_site_process_status.process_name%TYPE,
    po_status OUT NUMBER,
    po_error OUT VARCHAR2
    AS
    -- Cursor to get sites to be processed for bmi to ppo transformation process
    CURSOR cur_fcst_sites_ppo
    IS
    SELECT DISTINCT siteid
    FROM sci_restaurant
    WHERE hist_load_status in ('L','H')
    AND SYSTEM = pi_system
    ORDER BY siteid;
    -- Cursor to get sites to be processed for bmi to ai transformation process
    -- Note this cursor is based on the system and transfer day
    TYPE sites_tbltype IS TABLE OF cur_fcst_sites_ppo%ROWTYPE
    INDEX BY PLS_INTEGER;
    vt_fcst_sites_tbl sites_tbltype;
    TYPE proc_status_tbltype IS TABLE OF ods_site_process_status%ROWTYPE
    INDEX BY PLS_INTEGER;
    vt_proc_status_tbl proc_status_tbltype;
    v_cnt NUMBER := 0;
    v_cntr NUMBER := 0;
    v_batch_id NUMBER := 1;
    v_pst_idx PLS_INTEGER := 0;
    v_k PLS_INTEGER := 0;
    v_odssiteprocessid ods_site_process_status.odssiteprocessid%TYPE;
    v_exceptionid NUMBER;
    --variable to log exception into sci_exception table
    BEGIN
    --- If sites were identitfied before, skip the rest of the execution
    --- Note that ods_site_process_status holds the status from the prior runs
    po_error := '';
    po_status := 0;
    scimf_common.p_get_market_parameters (NULL,
    pi_system,
    vr_market,
    v_error_out
    IF v_error_out IS NOT NULL
    THEN
    RAISE e_market_not_found;
    END IF;
    IF pi_process_name = c_transform_bmi_ppo
    THEN
    SELECT COUNT (*)
    INTO v_cnt
    FROM ods_site_process_status
    WHERE SYSTEM = pi_system
    AND process_name = pi_process_name
    AND is_no = pi_is_no
    AND ROWNUM < 2;
    ELSIF pi_process_name = c_transform_bmi_ai
    THEN
    SELECT COUNT (*)
    INTO v_cnt
    FROM ods_site_process_status
    WHERE SYSTEM = pi_system
    AND process_name = pi_process_name
    AND rest_status = c_status_processed
    AND ROWNUM < 2;
    ELSE
    v_code := NULL;
    v_errm :=
    SUBSTR ( '[E]:0- Process Name :>'
    || pi_process_name
    || '<Is Not Proper For System:>'
    || pi_system
    || '< and IS_NO :>'
    || pi_is_no
    || '< and TransferDay :>'
    || pi_transferday
    || '<',
    1,
    125
    DBMS_OUTPUT.put_line (v_errm);
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform',
    v_errm,
    vr_market.marketid,
    'I'
    po_error := TO_CHAR (SQLCODE) || ' -Error Message: ' || v_errm;
    po_status := -1;
    -- Log Exception in the log file and come out.
    END IF;
    IF NVL (v_cnt, 0) > 0
    THEN
    IF pi_process_name = c_transform_bmi_ppo
    THEN
    SELECT SUBSTR
    ( ':0- Sites are already identified before for the '
    || pi_process_name
    || ' Process For '
    || DECODE (pi_process_name,
    c_transform_bmi_ppo, 'IS_NO ' || pi_is_no,
    'TransferDay ' || pi_transferday
    || '..'
    || 'proceeding to invoke child scripts',
    1,
    125
    INTO v_errm
    FROM DUAL;
    DBMS_OUTPUT.put_line (v_errm);
    ELSIF pi_process_name = c_transform_bmi_ai
    THEN
    SELECT SUBSTR
    ( '[I]:0- Sites are already identified before for the '
    || pi_process_name
    || ' Process For '
    || DECODE (pi_process_name,
    c_transform_bmi_ai, 'IS_NO ' || pi_is_no,
    'TransferDay ' || pi_transferday
    || '..'
    || 'proceeding to invoke child scripts',
    1,
    125
    INTO v_errm
    FROM DUAL;
    DBMS_OUTPUT.put_line (v_errm);
    END IF;
    ELSIF NVL (v_cnt, 0) = 0
    THEN
    OPEN cur_fcst_sites_ppo;
    FETCH cur_fcst_sites_ppo
    BULK COLLECT INTO vt_fcst_sites_tbl;
    CLOSE cur_fcst_sites_ppo;
    END IF;
    -- Logic to batch the sites to be processed in the batches of
    -- sites derived from the pi_sites_at_a_time parameter
    -- Batch_Id starts with 1 and need to used along with
    -- either is_no (bmi-ppo) and process name or along with
    -- system, bday and process_name (bmi-ai)
    IF pi_sites_at_a_time IS NULL
    THEN
    v_code := NULL;
    v_errm := 'Site At A Time not defined';
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform_master',
    v_errm,
    vr_market.marketid,
    'I'
    po_error := TO_CHAR (SQLCODE) || ' -Error Message: ' || v_errm;
    po_status := -1;
    raise_application_error (-200002, v_errm);
    END IF;
    FOR v_idx_fcst_sites IN 1 .. vt_fcst_sites_tbl.COUNT
    LOOP
    BEGIN
    SELECT seq_ods_site_process_status.NEXTVAL
    INTO v_odssiteprocessid
    FROM DUAL;
    EXCEPTION
    WHEN OTHERS
    THEN
    ROLLBACK;
    DBMS_OUTPUT.put_line ( '[E]:0- Sequence :>'
    || 'seq_ods_site_process_status'
    || ' <Is Invalid>'
    || '<'
    v_errm :=
    SUBSTR ( 'Sequence seq_ods_site_process_status Error:'
    || SQLERRM,
    1,
    125
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform',
    v_errm,
    vr_market.marketid,
    'I'
    po_error :=
    TO_CHAR (SQLCODE) || ' -Error Message: '
    || v_errm;
    po_status := -1;
    raise_application_error (-200002, v_errm);
    END;
    v_pst_idx := v_pst_idx + 1;
    vt_proc_status_tbl (v_pst_idx).odssiteprocessid :=
    v_odssiteprocessid;
    vt_proc_status_tbl (v_pst_idx).SYSTEM := pi_system;
    vt_proc_status_tbl (v_pst_idx).process_name := pi_process_name;
    vt_proc_status_tbl (v_pst_idx).siteid :=
    vt_fcst_sites_tbl (v_idx_fcst_sites).siteid;
    vt_proc_status_tbl (v_pst_idx).bday := pi_transferday;
    vt_proc_status_tbl (v_pst_idx).is_no := pi_is_no;
    vt_proc_status_tbl (v_pst_idx).rest_status := c_status_unprocessed;
    vt_proc_status_tbl (v_pst_idx).batch_id := v_batch_id;
    v_cntr := v_cntr + 1;
    IF v_cntr = pi_sites_at_a_time
    THEN
    v_batch_id := v_batch_id + 1;
    v_cntr := 0;
    END IF;
    v_odssiteprocessid := NULL;
    END LOOP;
    IF v_pst_idx > 0
    THEN
    BEGIN
    FORALL v_proc_status_tbl_idx IN 1 .. vt_proc_status_tbl.COUNT
    INSERT INTO ods_site_process_status
    VALUES vt_proc_status_tbl (v_proc_status_tbl_idx);
    EXCEPTION
    WHEN OTHERS
    THEN
    ROLLBACK;
    v_error_count := SQL%BULK_EXCEPTIONS.COUNT;
    DBMS_OUTPUT.put_line
    ( '[E]:0- Bulk Insert Fail using FORALL Number of Failure:>'
    || v_error_count
    || '<'
    FOR v_i IN 1 .. v_error_count
    LOOP
    v_errm :=
    SUBSTR
    ( '[E]:Error Insert into ODS_SITE_PROCESS_STATUS table '
    || 'Insert Error: '
    || v_i
    || ' Array Index: '
    || SQL%BULK_EXCEPTIONS (v_i).ERROR_INDEX
    || SQLERRM
    (-SQL%BULK_EXCEPTIONS (v_i).ERROR_CODE),
    1,
    125
    DBMS_OUTPUT.put_line (v_errm);
    END LOOP;
    v_code := NULL;
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform_master',
    v_errm,
    vr_market.marketid,
    'I'
    po_error :=
    TO_CHAR (SQLCODE) || ' -Error Message: '
    || v_errm;
    po_status := -1;
    END;
    ELSE
    v_code := NULL;
    SELECT SUBSTR ( '[M]:0- No Site Available for the '
    || pi_process_name
    || ' Process For '
    || DECODE (pi_process_name,
    c_transform_bmi_ppo, 'IS_NO '
    || pi_is_no,
    'TransferDay ' || pi_transferday
    || '..',
    1,
    125
    INTO v_errm
    FROM DUAL;
    DBMS_OUTPUT.put_line (v_errm);
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform_master',
    v_errm,
    vr_market.marketid,
    'I'
    END IF;
    END IF;
    COMMIT;
    po_status := NVL (po_status, 0);
    EXCEPTION
    WHEN e_market_not_found
    THEN
    ROLLBACK;
    v_code := NULL;
    v_errm := SUBSTR ('[E]:Error Market Not Found ' || SQLERRM, 1, 125);
    scimf_common.write_log (v_code, --Log error into the LOGFILE
    'E',
    'p_mfcst_transform_master',
    v_errm,
    vr_market.marketid,
    'I'
    raise_application_error (-200001,
    'Market parameter not found for system'
    || pi_system
    po_error := TO_CHAR (SQLCODE) || ' -Error Message: ' || SQLERRM;
    po_status := -1;
    WHEN OTHERS
    THEN
    ROLLBACK;
    DBMS_OUTPUT.put_line ( '[E]:0-ERROR :-- '
    || ' --SQLCODE: '
    || SQLCODE
    || ' -Error Message: '
    || SQLERRM
    po_error := TO_CHAR (SQLCODE) || ' -Error Message: ' || SQLERRM;
    po_status := -1;
    END;

  • Trying to create a Histogram type/object for aggregate functions

    Hi,
    I am trying to create an aggregate function that will return a histogram
    type.
    It doesn't have to be an object that is returned, I don't mind returning
    a string but I would like to keep the associative array (or something
    else indexed by varchar2) as a static variable between iterations.
    I started out with the SecondMax example in
    http://www.csis.gvsu.edu/GeneralInfo/Oracle/appdev.920/a96595/dci11agg.htm#1004821
    But even seems that even a simpler aggregate function like one strCat
    below (which works) has problems because I get multiple permutations for
    every combination. The natural way to solve this would be to create an
    associative array as a static variable as part of the Histogram (see
    code below). However, apparently Oracle refuses to accept associate
    arrays in this context (PLS-00355 use of pl/sql table not allowed in
    this context).
    If there is no easy way to do the histogram quickly can we at least get
    something like strCat to work in a specific order with a "partition by
    ... order by clause"? It seems that even with "PARALLEL_ENABLE"
    commented out strCat still calls merge for function calls like:
    select hr,qtr, count(tzrwy) rwys,
    noam.strCat(cnt) rwycnt,
    noam.strCat(tzrwy) config,
    sum(cnt) cnt, min(minscore) minscore, max(maxscore) maxscore from
    ordrwys group by hr,qtr
    Not only does this create duplicate entries in the query result like
    "A,B,C" and "A,C,B" it seems that the order in rwycnt and config are not
    always the same so a user can not match the results based on their
    order.
    The difference between my functions and functions like sum and the
    secondMax demonstrated in the documentation is that secondMax does not
    care about the order in which it gets its arguments and does not need to
    maintain an ordered set in order to return the correct results. A good
    example of a built in oracle function that does care about all its
    arguments and probably has to maintain a similar data structure to the
    one I want is the PERCTILE_DISC function. If you can find the code for
    that function (or something like it) and forward a reference to me that
    in itself would be very helpful.
    Thanks,
    K.Dingle
    CREATE OR REPLACE type Histogram as object
    -- TYPE Hist10 IS TABLE OF pls_integer INDEX BY varchar2(10),
    -- retval hist10;
    -- retval number,
    retval noam.const.hist10,
    static function ODCIAggregateInitialize (sctx IN OUT Histogram)
    return number,
    member function ODCIAggregateIterate (self IN OUT Histogram,
    value IN varchar2) return number,
    member function ODCIAggregateTerminate (self IN Histogram,
    returnValue OUT varchar2,
    flags IN number) return number,
    member function ODCIAggregateMerge (self IN OUT Histogram,
    ctx2 IN Histogram) return number
    CREATE OR REPLACE type body Histogram is
    static function ODCIAggregateInitialize(sctx IN OUT Histogram) return
    number is
    begin
    sctx := const.Hist10();
    return ODCIConst.Success;
    end;
    member function ODCIAggregateIterate(self IN OUT Histogram, value IN
    varchar2)
    return number is
    begin
    if self.retval.exist(value)
    then self.retval(value):=self.retval(value)+1;
    else self.retval(value):=1;
    end if;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateTerminate(self IN Histogram,
    returnValue OUT varchar2,
    flags IN number)
    return number is
    begin
    returnValue := self.retval;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateMerge(self IN OUT Histogram,
    ctx2 IN Histogram) return number is
    begin
    i := ctx2.FIRST; -- get subscript of first element
    WHILE i IS NOT NULL LOOP
    if self.retval.exist(ctx2(i))
    then self.retval(i):=self.retval(i)+ctx2.retval(i);
    else self.retval(value):=ctx2.retval(i);
    end if;
    i := ctx2.NEXT(i); -- get subscript of next element
    END LOOP;
    return ODCIConst.Success;
    end;
    end;
    CREATE OR REPLACE type stringCat as object
    retval varchar2(16383), -- concat of all value to now varchar2, --
    highest value seen so far
    static function ODCIAggregateInitialize (sctx IN OUT stringCat)
    return number,
    member function ODCIAggregateIterate (self IN OUT stringCat,
    value IN varchar2) return number,
    member function ODCIAggregateTerminate (self IN stringCat,
    returnValue OUT varchar2,
    flags IN number) return number,
    member function ODCIAggregateMerge (self IN OUT stringCat,
    ctx2 IN stringCat) return number
    CREATE OR REPLACE type body stringCat is
    static function ODCIAggregateInitialize(sctx IN OUT stringCat) return
    number is
    begin
    sctx := stringCat('');
    return ODCIConst.Success;
    end;
    member function ODCIAggregateIterate(self IN OUT stringCat, value IN
    varchar2)
    return number is
    begin
    if self.retval is null
    then self.retval:=value;
    else self.retval:=self.retval || ',' || value;
    end if;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateTerminate(self IN stringCat,
    returnValue OUT varchar2,
    flags IN number)
    return number is
    begin
    returnValue := self.retval;
    return ODCIConst.Success;
    end;
    member function ODCIAggregateMerge(self IN OUT stringCat,
    ctx2 IN stringCat) return number is
    begin
    self.retval := self.retval || ctx2.retval;
    return ODCIConst.Success;
    end;
    end;
    CREATE OR REPLACE FUNCTION StrCat (input varchar2) RETURN varchar2
    -- PARALLEL_ENABLE
    AGGREGATE USING StringCat;

    GraphicsConfiguration is an abstract class. You would need to subclass it. From the line of code you posted, it seems like you are going about things the wrong way. What are you trying to accomplish? Shouldn't this question be posted in the Swing or AWT forum?

  • Dynamic creation of variables and alv grid output/internal table

    Dear Experts
    I am stuck in an inventory ageing report which is to be done year wise. the scenario is as follow.
    selection screen i enter the year 2011 or 2010 or 2009.
    the output should show me 2011-2007 or 2010-2007 or 2009-2007. the alv grid should always start from 2007 and end at the year that is entered in the selection screen.
    Now how can i create a dynamic variables to store the values of the corresponding yr and also how can i create a dynamic internal table to store these values.
    Thanks & Regards
    Zamir Parkar

    Hi Zamir,
    if you are new to ABAP you may leave old and buggy techniques behind.
    If you want to create the table dynamically, please do not use l_alv_table_create=>create_dynamic_table because it is limited and always triggers a possibly unwanted database commit.
    You better use RTTS dynamic runtime type services, i.e. check the example for [Creating Flat and Complex Internal Tables Dynamically using RTTI|http://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI].
    As done here, leave all outdated ALV technologies behind and start with CL_SALV_TABLE. It is following the object-oriented approach and does not need a field catalog.
    You will get used to field-symbols that can be compared to the data referenced by a pointer. For dynamic fields, you may build the field names dynamically, i.e.
    DATA:
          lo_structdescr         TYPE REF TO cl_abap_structdescr,
          lo_typedescr           TYPE REF TO cl_abap_typedescr,
          lo_tabledescr          TYPE REF TO cl_abap_tabledescr,
          lr_data                TYPE REF TO data,
          lt_comp_all            TYPE cl_abap_structdescr=>component_table,
          lv_index               TYPE numc2.
        FIELD-SYMBOLS:
          <any>                  TYPE ANY,
          <component>            TYPE LINE OF abap_component_tab,
           <table>                TYPE table.
        DO nnn TIMES.
          lv_index = sy-index.
          lo_typedescr   =  cl_abap_typedescr=>describe_by_name( <name of data element> ).
          APPEND INITIAL LINE TO lt_comp_all ASSIGNING <component>.
          <component>-type ?= lo_typedescr.
          CONCATENATE 'YEARVAL' lc_underscore lv_index INTO <component>-name.
          <component>-as_include  = abap_true.
          CONCATENATE lc_underscore lv_index INTO <component>-suffix.
        ENDDO.
    * create description object for structured type
        lo_structdescr = cl_abap_structdescr=>create( lt_comp_all ).
    *  create table description object for this
        lo_tabledescr = cl_abap_tabledescr=>create(
                        p_line_type  = lo_structdescr
                        p_table_kind = cl_abap_tabledescr=>tablekind_std
                        p_unique     = abap_false ).
    * create data object
        CREATE DATA lr_data TYPE HANDLE lo_tabledescr.
    ASSIGN lr_data->* to <table>.
    This is a fragment. Please adapt to your needs.
    Regards,
    Clemens

  • To create a deep structure for dynamic internal table.

    Hello
    My ALV has fields which are defined dynamically during execution.
    so, i did it in the following way,
    Declared Field symbolds, DREF and fieldcatalog as,
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
                  <fs_dyntable>.
    DATA:   dref_dyntab    TYPE REF TO data,
            dref_dynwa     TYPE REF TO data.
    DATA: ts_fieldcatalog TYPE lvc_t_fcat.
    DATA: wa_fieldcatalog TYPE lvc_s_fcat.
    Updated Fieldcatalog dynamically as,
    *function module to read segment structure
        CALL FUNCTION 'SEGMENT_READ'
          EXPORTING
            segmenttyp           = v_segment_name
          TABLES
            segmentstructure     = ts_seg_structure
          EXCEPTIONS
            no_authority         = 1
            segment_not_existing = 2
            OTHERS               = 3.
        IF sy-subrc <> 0.
          CASE sy-subrc.
            WHEN '1'.
              MESSAGE e024.
              STOP.
            WHEN '2'.
              MESSAGE e025 WITH v_segment_name.
              STOP.
            WHEN OTHERS.
              MESSAGE e023.
          ENDCASE.
        ENDIF.
    *FETCH FIELDS FROM STRUCTURE OF SEGMENT AND CREATE FIELDCATALOG FOR
    EACH FIELD OF SEGMENT (DYNAMIC FIELD CATALOG)
        LOOP AT ts_seg_structure INTO wa_seg_structure.
          ADD 1 TO v_counter.
          wa_fieldcatalog-fieldname = wa_seg_structure-fieldname.
          wa_fieldcatalog-col_pos   = v_counter.
          wa_fieldcatalog-ref_table = wa_seg_structure-segtyp.
          APPEND wa_fieldcatalog TO ts_fieldcatalog.
          CLEAR wa_fieldcatalog.
        ENDLOOP.
    and generated dynamic internal table using fieldcatalog as,
    *--Method to get the structure of table using fieldcatalog.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ts_fieldcatalog
        IMPORTING
    *--Variable of type REF TO DATA.
          ep_table        = dref_dyntab.
      IF sy-subrc <> 0.
        MESSAGE e023.
      ENDIF.
    *--Dynamic internal tables required when show segments selected
      IF p_selseg IS NOT INITIAL.
        ASSIGN dref_dyntab->* TO <t_dyntable>.
    *--Create dynamic work area and assign to FS
      CREATE DATA dref_dynwa LIKE LINE OF <t_dyntable>.
        ASSIGN dref_dynwa->* TO <fs_dyntable>.
    And then i populated this <t_dyntable> which is being passed as data-table to method
    CL_GUI_ALV_GRID => SET_TABLE_FOR_FIRST_DISPLAY
    for ALV grid Display along with above used filedcatalog ts_fieldcatalog.
    Things are fine till here, but now i have the requirement to edit selected rows of the ALV display..
    As you might be aware, we need a field
            TS_STYLEROW  TYPE lvc_t_styl, (i.e, a field of type 'h' and we can say as an internal table inside an internal table or else as a deep structure)
    in the output internal table <t_dyntable> to meet our requirement.
    My issue is about declaring one such field of type 'h' in this dynamically created internal table ''<t_dyntable>".
    I tried in the following way by adding one such field to fieldcatalog :
    *Field for Styling
      ADD 1 TO v_counter.
      wa_fieldcatalog-fieldname   = 'TS_STYLEROW'.
      wa_fieldcatalog-tabname     = 'TS_STYLE'.
      wa_fieldcatalog-col_pos     = v_counter.
      wa_fieldcatalog-no_out      = 'X'.
      wa_fieldcatalog-inttype     = 'h'.      " I even mentioned this
      APPEND wa_fieldcatalog TO ts_fieldcatalog.
      CLEAR  wa_fieldcatalog.
    But this is creating a field of type 'C' in the table <t_dyntable> instead of what i was expecting
    Guyz and respected,
    Please advice me with the solution or ur ideas....
    Note : The overall requirement is create a deep structure for dynamically generated internal table.
    Your help is highly appreciated and unforgettable..!!!!!!!

    hi,
    Dynamic append
    Dynamic internal table
    Dynamic internal table
    dynamic columns in ALV
    Variant for dynamic selection
    thanks

  • Define variable a ROWTYPE based on a table name passed as a parameter

    I am trying to write a procedure that processes rows for tables of differing structures. Table_name is passed as an IN parameter to the procedure. I define a cursor within the function that is defined by a SELECT * FROM table_name. I also need to define two variables, l_this_row and l_prev_row. I need to define them as table_name%ROWTYPE. Of course, table_name is a VARCHAR2 that contains the name of a table, whereas Oracle is expecting an actual table name in the declaration. How can I define these variables to make something like the code shown below compile and work properly? I am using Oracle 10gR2.
    DEFINE PROCEDURE foo(table_name IN VARCHAR2) IS
    l_this_row table_name%ROWTYPE;
    l_prev_row table_name%ROWTYPE;
    l_cursor SYSREFCURSOR;
    BEGIN
    OPEN l_cursor FOR
    'SELECT * FROM '
    || table_name
    || ' ORDER BY '
    || get_pk_col_name_for_table(table_name)
    || ', version_num'; --version_num is guaranteed to be a valid column name in every table, although the other column names vary in name, quantity, and type per table.
    LOOP
    FETCH l_cursor INTO l_this_record;
    EXIT WHEN l_cursor%NOTFOUND;
    -- dynamic comparison of l_this_record and l_prev_record and conditional processing based on the comparison occurs here
    l_prev_record := l_this_record;
    END LOOP;
    END;

    Billy  Verreynne  wrote:
    Well, one method is to keep the SQL projection consistent across the number of dynamic SQLs being dealt with. With the projection being consistent, your code does not need to guess what the row structure the column returns.Unfortunately, what I need to compare is almost everything except the primary keys. So one table might contain addresses and another might contain invoice headers. There's no way to get them into the same structure.
    Billy  Verreynne  wrote:
    This approach can also be done in a generic fashion - dealing with an arbitrary number of columns per row. This dynamic structure is more flexible, but also increases the complexity of the code that has to deal with this. For example:
    create or replace type TStrings is table of varchar2(4000);Now SQLs can be created to pass any number of columns to the code to process:
    select TStrings( empid, ename, jobid, date_employed, date_of_birth ) from emp order by empidThe code then uses the Count method of the TStrings type to determine the number of columns passed and processes that.Then the problem becomes having to specify all the column names. I need to figure them out dynamically, as in "SELECT column_name FROM user_tab_cols WHERE column_name NOT IN ('ID', 'PREV_ID', 'NEXT_ID')". It would, of course, be best if I didn't have to populate each array element with an individual SELECT in its own EXECUTE IMMEDIATE statement. That would certainly slow things down. If I were trying to write this using ADO.NET, I could reference something like table_name(row_index).columns(ix) without having to know any of the column names, and I could exclude columns by name using a reference like table_name.columns(column_index).name. (I don't recall the exact syntax, but it is something reasonably close to that.) But PL/SQL doesn't seem to have anything close to this.
    Ideally, I want to get it to where I can do something like this in a private function:
    FOR ix IN 1..TStrings.Count LOOP
       IF this_row(ix) <> last_row(ix) THEN
          RETURN FALSE;
       END IF;
    END LOOP;
    RETURN TRUE;
    Billy  Verreynne  wrote:Last comment. I have to echo what the others said. This is not optimal. Dealing with variant/dynamic structures and processing rows using PL/SQL (in a slow-by-slow fashion) does not scale well. Scalability and performance comes from processing data sets using SQL.I completely understand. I'm a big fan of replacing a lot of code with one SQL statement, but that just won't work for this problem.

Maybe you are looking for

  • Archlinux on toshiba portege p2000 (2000)

    Hi, I just got toshiba portege 2000 from my employer with windows xp on it. I would really like to install my favourite system (archlinux) on it, but I have no idea how. The ways I excluded are: 1: CD instalation. The only cd-rom I have is on pcmcia,

  • Spry Accordion and jQuery UI Accordion for Widget Browser

    I have Dreamweaver CS5 and used the spry accordion for a left menu. I then used the widget browser and added jQuery UI accordion. But there appears to be a conflict in that the spry accordion is not displaying the white font on hover, instead using t

  • H323 redundancy between routers

    I have 2 2800 series routers with E1 circuits on both, i can place calls on both gateways without any issues. If i pull the E1 circuit on one router, but still have IP connectivity to it from the callmanager, the route list route group will not forwa

  • Cannot print correctly from either Preview or Adobe Professional.

    Documents either do not print or print highly enlarged and in landscape mode. The same documents print perfectly from other macs. I have deleted my printers and recreated them and nothing changed. Any suggestions would be greatly appreciated. Thanks,

  • Can Someone Please Help With A Java App.

    A while back, I had a program that I was working on, while taking Java in a Web Design & Development course -- this was back in 1999 -- not having the mindset of a programmer I failed that part of the course misrably. I had to do the following progra