Bulk collect into the record type

Sorry for the stupid question - I do something really simple wrong here, but can not understand. I want to choose a few rows from a table in a cursor, then in bulk it collect in a folder. I'll possibly extended the record to include additional fields that I will select return of functions, but I can't get this simple test case to run...

PLS-00497 is the main error.

Thanks in advance.
create table test (
id number primary key,
val varchar2(20),
something_else varchar2(20));

insert into test (id, val,something_else) values (1,'test1','else');
insert into test (id, val,something_else) values (2,'test2','else');
insert into test (id, val,something_else) values (3,'test3','else');
insert into test (id, val,something_else) values (4,'test4','else');

commit;

SQL> declare
  2   cursor test_cur is
  3   (select id, val
  4   from test);
  5
  6   type test_rt is record (
  7     id   test.id%type,
  8     val      test.val%type);
  9
 10   test_rec test_rt;
 11
 12  begin
 13    open test_cur;
 14    loop
 15      fetch test_cur bulk collect into test_rec limit 10;
 16       null;
 17     exit when test_rec.count = 0;
 18    end loop;
 19    close test_cur;
 20  end;
 21  /
    fetch test_cur bulk collect into test_rec limit 10;
                                     *
ERROR at line 15:
ORA-06550: line 15, column 38:
PLS-00497: cannot mix between single row and multi-row (BULK) in INTO list
ORA-06550: line 17, column 21:
PLS-00302: component 'COUNT' must be declared
ORA-06550: line 17, column 2:
PL/SQL: Statement ignored

You must declare an array based on your registration type.

DECLARE
   CURSOR test_cur
   IS
         SELECT
            id,
            val
         FROM
            test
   ;
type test_rt
IS
   record
   (
      id test.id%type,
      val test.val%type);
   type test_rec_arr is table of test_rt index by pls_integer;
   test_rec test_rec_arr;
BEGIN
   OPEN test_cur;
   LOOP
      FETCH
         test_cur bulk collect
      INTO
         test_rec limit 10;
      NULL;
      EXIT
   WHEN test_rec.count = 0;
   END LOOP;
   CLOSE test_cur;
END;
 31  /

PL/SQL procedure successfully completed.

Elapsed: 00:00:00.06
ME_XE?

Notice that the difference is...

   type test_rec_arr is table of test_rt index by pls_integer;
   test_rec test_rec_arr;

Tags: Database

Similar Questions

  • bulk collect into the collection of objects

    create or replace type typ_obj as an object
    (l_x number (10),)
    l_y varchar2 (10),
    LZ varchar2 (10)
    );

    Create the type typ_obj_tt is table of the typ_obj;

    / / DESC insert_table;
    c_x number (10)
    C_P number (10)

    temp2_table / / DESC
    doJir number (10)
    c_y varchar2 (10)
    c_z varchar2 (10)

    procedure prc_x (p_obj_out ON typ_obj_tt)
    is
    cursor c1
    is
    Select t1.c_x,
    T2.c_y,
    T2.c_z
    Of
    insert_table t1,
    temp2_table t2
    where
    ....
    ;
    Start
    Open c1;
    collect the fetch c1 into loose in p_obj_out;
    Close c1;

    end;

    raises the error

    can you tell
    How to enter data in this object of type of output table

    Thanks in advance... any help will be much appreciated...

    PL do not spam the forums with topics in double - bulk collect into the collection of objects

  • Bulk collect into the statement

    Hi all

    I'm trying to copy data using the database link.

    I'm using the Oracle 11 g on Windows.

    I check the data in the source table and it exists. When I run under block it is running successfully but do return no data in the target database.

    SET SERVEROUTPUT ON

    DECLARE

    TYPE of t_bulk_collect_test_1 IS the TABLE OF NT_PROP % ROWTYPE;

    l_tab1 t_bulk_collect_test_1;

    CURSOR c_data1 IS

    SELECT *.

    OF NT_PROP@dp_copy;

    BEGIN

    OPEN c_data1.

    LOOP

    EXTRACTION c_data1

    LOOSE COLLECTION l_tab1 LIMIT 10000;

    commit;

    WHEN OUTPUT l_tab1.count = 0;

    END LOOP;

    CLOSE C_data1;

    END;

    /

    Could you get it someone please let me know what is the error in this code.

    Thanks in advance

    Bulk operation will not improve performance. Your code is a good example to show how to write code that is a performance nightmare. I'm sorry to say this, but it's the truth.

    Static SQL is the fastest way to do it. As you will transfer the data via a DB connection it will be certain overhead. But the block is not the solution for it. Make a simple INSERT INTO... SELECT... Beh It's the best way to do what you want.

  • Bulk collect into a Table nested with Extend

    Hi all
    I want to get all the columns of the table emp and dept. So I use bulk collect into the concept of nested table.

    *) I wrote the function in three different ways. EX: 1 and 2 (DM_NESTTAB_BULKCOLLECT_1 & DM_NESTTAB_BULKCOLLECT_2) does not give the desired result.
    *) It only gives the columns of the EMP table. That means it takes DEPT & columns of the EMP table, but it only gives columns of table EMP.
    ) I think, there is something problem with nested table Extend.
    ) I want to know infested.
    Can we use bulk collect into a table nested with extend?
    If it is yes then fix the below codes (EX: 1 & EX: 2) and can you explain me please?


    Codes are given below *.

    CREATE OR REPLACE TYPE NEST_TAB IS TABLE OF THE VARCHAR2 (1000);

    EX: 1:
    ----
    -Bulk collect into a Table nested with Extend-
    CREATE or replace FUNCTION DM_NESTTAB_BULKCOLLECT_1
    RETURN NEST_TAB
    AS
    l_nesttab NEST_TAB: = NEST_TAB();
    BEGIN
    FOR tab_rec IN (SELECT table_name
    From user_tables
    WHERE table_name IN ('EMP', 'Department')) LOOP
    l_nesttab.extend;

    SELECT column_name
    bulk collect INTO l_nesttab
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name
    ORDER BY column_id;
    END LOOP;

    RETURN l_nesttab;
    EXCEPTION
    WHILE OTHERS THEN
    LIFT;
    END DM_NESTTAB_BULKCOLLECT_1;

    SELECT *.
    TABLE (DM_NESTTAB_BULKCOLLECT_1);

    OUTPUT:
    -------
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO

    * Only the EMP table columns are there in the nested table.
    -----------------------------------------------------------------------------------------------------

    EX: 2:
    -----
    -Bulk collect in the nested with Extend based on County - Table
    CREATE or replace FUNCTION DM_NESTTAB_BULKCOLLECT_2
    RETURN NEST_TAB
    AS
    l_nesttab NEST_TAB: = NEST_TAB();
    v_col_cnt NUMBER;
    BEGIN
    FOR tab_rec IN (SELECT table_name
    From user_tables
    WHERE table_name IN ('EMP', 'Department')) LOOP
    SELECT MAX (column_id)
    IN v_col_cnt
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name;

    l_nesttab. Extend (v_col_cnt);

    SELECT column_name
    bulk collect INTO l_nesttab
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name
    ORDER BY column_id;
    END LOOP;

    RETURN l_nesttab;
    EXCEPTION
    WHILE OTHERS THEN
    LIFT;
    END DM_NESTTAB_BULKCOLLECT_2;

    SELECT *.
    TABLE (DM_NESTTAB_BULKCOLLECT_2);

    OUTPUT:
    -------
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO

    * Only the EMP table columns are there in the nested table.
    -------------------------------------------------------------------------------------------

    EX: 3:
    -----

    -Collect in bulk in a nested Table to expand aid for loop.
    CREATE or replace FUNCTION DM_NESTTAB_BULKCOLLECT_3
    RETURN NEST_TAB
    AS
    l_nesttab NEST_TAB: = NEST_TAB();
    TYPE local_nest_tab
    THE VARCHAR2 ARRAY (1000);
    l_localnesttab LOCAL_NEST_TAB: = LOCAL_NEST_TAB();
    NUMBER x: = 1;
    BEGIN
    FOR tab_rec IN (SELECT table_name
    From user_tables
    WHERE table_name IN ('EMP', 'Department')) LOOP
    SELECT column_name
    bulk collect INTO l_localnesttab
    Of user_tab_columns
    WHERE table_name = tab_rec.table_name
    ORDER BY column_id;

    BECAUSE me IN 1.l_localnesttab. COUNTING LOOP
    l_nesttab.extend;

    L_NESTTAB (x): = L_LOCALNESTTAB (i);

    x: = x + 1;
    END LOOP;
    END LOOP;

    RETURN l_nesttab;
    EXCEPTION
    WHILE OTHERS THEN
    LIFT;
    END DM_NESTTAB_BULKCOLLECT_3;

    SELECT *.
    TABLE (DM_NESTTAB_BULKCOLLECT_3);

    OUTPUT:
    ------
    DEPTNO
    DNAME
    LOC
    EMPNO
    ENAME
    JOB
    MGR
    HIREDATE
    SAL
    COMM
    DEPTNO

    * Now, I got the desired result set. DEP. and columns of the Emp Table are in the nested Table.




    Thank you
    Ann

    COLLECTION BULK cannot add values to an existing collection. It can only crush.

  • Subsequentes IN BULK COLLECT in the collection truncates existing lines?

    T_tab_prds TYPE IS the % TYPE my_cursor TABLE;

    v_tab_prds t_tab_prds;

    OPEN my_cursor;
    Fetch the my_cursor COLLECT in BULK IN v_tab_prds;
    NARROW My_cursor

    another session can change/remove lines

    OPEN my_cursor;
    Fetch the my_cursor COLLECT in BULK IN v_tab_prds; -V_tab_prds VA be zapped before second READING or lines will be mixed? I have to
    -manually remove lines of v_tab_prds before the second EXTRACTION?
    NARROW My_cursor

    I answered Yes initially "later in BULK collect into collection truncate existing lines. Then I noticed "another session can change or remove rows" in your message. The collection is in the object memory with PL/SQL unit scope, it is stated in which is obviously not covered by sessions. So even if the collection belongs to the same unit of PL/SQL (package, SP, etc.) in different sessions, it's a different chunk of memory. So the final answer is:

    Later in BULK COLLECT in the collection to the breast within the same instance of PL/SQL unit truncates existing lines. But obviously subsequent TO BULK COLLECT into the collection in another session won't affect collection in the first session.

    SY.

    Published by: Solomon Yakobson, October 13, 2009 14:20

  • Using bulk collect into with assistance from the limit to avoid the TEMP tablespace error run out?

    Hi all

    I want to know if using bulk collect into limit will help to avoid the TEMP tablespace error run out.

    We use Oracle 11 g R1.

    I am assigned to a task of creating journal facilitated for all tables in a query of the APEX.

    I create procedures to execute some sql statements to create a DEC (Create table select), and then fires on these tables.

    We have about three tables with more than 26 million records.

    It seems very well running until we reached a table with more than 15 million record, we got an error says that Miss tablespace TEMP.

    I googled on this topic and retrieve the tips:

    Use NO LOG

    Parallel use

    BULK COLLECT INTO limited

    However, the questions for those above usually short-term memory rather than running out of TEMPORARY tablespace.

    I'm just a junior developer and does not have dealed with table more than 10 million documents at a time like this before.

    The database support is outsourced. If we try to keep it as minimal contact with the DBA as possible. My Manager asked me to find a solution without asking the administrator to extend the TEMP tablespace.

    I wrote a few BULK COLLECT INTO to insert about 300,000 like once on the development environment. It seems.

    But the code works only against a 000 4000 table of records. I am trying to add more data into the Test table, but yet again, we lack the tablespace on DEV (this time, it's a step a TEMP data)

    I'll give it a go against the table of 26 million records on the Production of this weekend. I just want to know if it is worth trying.

    Thanks for reading this.

    Ann

    I really need check that you did not have the sizes of huge line (like several K by rank), they are not too bad at all, which is good!

    A good rule of thumb to maximize the amount of limit clause, is to see how much memory you can afford to consume in the PGA (to avoid the number of calls to the extraction and forall section and therefore the context switches) and adjust the limit to be as close to that amount as possible.

    Use the routines below to check at what threshold value would be better suited for your system because it depends on your memory allocation and CPU consumption.  Flexibility, based on your limits of PGA, as lines of length vary, but this method will get a good order of magnitude.

    CREATE OR REPLACE PROCEDURE show_pga_memory (context_in IN VARCHAR2 DEFAULT NULL)

    IS

    l_memory NUMBER;

    BEGIN

    SELECT st. VALUE

    IN l_memory

    SYS.v_$ session se, SYS.v_$ sesstat st, SYS.v_$ statname nm

    WHERE se.audsid = USERENV ('SESSIONID')

    AND st.statistic # nm.statistic = #.

    AND themselves. SID = st. SID

    AND nm.NAME = 'pga session in memory. "

    Dbms_output.put_line (CASE

    WHEN context_in IS NULL

    THEN NULL

    ELSE context_in | ' - '

    END

    || 'Used in the session PGA memory ='

    || To_char (l_memory)

    );

    END show_pga_memory;

    DECLARE

    PROCEDURE fetch_all_rows (limit_in IN PLS_INTEGER)

    IS

    CURSOR source_cur

    IS

    SELECT *.

    FROM YOUR_TABLE;

    TYPE source_aat IS TABLE OF source_cur % ROWTYPE

    INDEX BY PLS_INTEGER;

    l_source source_aat;

    l_start PLS_INTEGER;

    l_end PLS_INTEGER;

    BEGIN

    DBMS_SESSION.free_unused_user_memory;

    show_pga_memory (limit_in |) "- BEFORE"); "."

    l_start: = DBMS_UTILITY.get_cpu_time;

    OPEN source_cur.

    LOOP

    EXTRACTION source_cur

    LOOSE COLLECTION l_source LIMITED limit_in;

    WHEN l_source EXIT. COUNT = 0;

    END LOOP;

    CLOSE Source_cur;

    l_end: = DBMS_UTILITY.get_cpu_time;

    Dbms_output.put_line (' elapsed time CPU for limit of ')

    || limit_in

    || ' = '

    || To_char (l_end - l_start)

    );

    show_pga_memory (limit_in |) "- AFTER");

    END fetch_all_rows;

    BEGIN

    fetch_all_rows (20000);

    fetch_all_rows (40000);

    fetch_all_rows (60000);

    fetch_all_rows (80000);

    fetch_all_rows (100000);

    fetch_all_rows (150000);

    fetch_all_rows (250000);

    -etc.

    END;

  • Dynamic SQL with in bulk in the record type

    Oracle 10.2 g

    I received this Tom

    [http://asktom.oracle.com/pls/apex/f?p=100:11:0:NO:]

    I'm able to do this without dynamic SQL, but my requirement is to do it in dynamic SQL
     create table t1 ( x int, y int );
    
     insert into t1 select rownum, rownum+1 from all_users where rownum <= 5;
    
     create table t2 ( x int, y int, z int );
    
     declare
                type array is table of t1%rowtype;
                l_data array;
        begin
                select * bulk collect into l_data from t1;
      
                forall i in 1 .. l_data.count
                
                       execute immediate 'insert into (select x, y from t2) values :x' using l_data(i);
        end;
     
    Error at line 1
    ORA-06550: line 9, column 90:
    PLS-00457: expressions have to be of SQL types
    ORA-06550: line 9, column 20:
    PL/SQL: Statement ignored
    There is a work around in 11g, but can we do something in 10g?



    Thank you
    HESH.

    HESH wrote:

    but following does not.

    declare
    type array is table of t1%rowtype;
    l_data array;
    begin
    select * bulk collect into l_data from t1;
    
    forall i in 1 .. l_data.count
    
    execute immediate 'insert into (select x, y from t2) values :x' using l_data(i);
    end;
    

    I want just a dynamic SQL code for the insert with FORALL statement would adopt as well as collections.

    Doesn't make much sense.

    Extract you the data from the SQL engine in the table of the record type. If the output data that cursor SQL must be read in the SQL engine and copied into the memory of PL/SQL engine.

    Then, you send that VERY SAME DATA back to the SQL engine to be used by a SQL insert cursor.

    Where is the logic behind the extraction of data from SQL in a PL/SQL table structure and then push this same structure table on the SQL engine database? What is the purpose to send data on a detour of underperforming and non-scalale through the PL/SQL engine?

    You have any justification (technical or functional wise) to back up this absurd approach?

    Why this can be achieved using a single SQL cursor that does both the choice (extraction) and (in bulk) insertion - using the plain old INSERT... SELECT structure?

    And if the insert is variable, then what? Create a dynamic INSERT... SELECT cursor and execute it (using bind values). This simple... Right?

  • Using the slider for and BULK COLLECT INTO

    Hi all
    in this case we prefer to use the cursor AND the cursor with the LOOSE COLLECTION? The following contains two block this same query where used FOR the slider, the other is using COLLECT LOOSE. The task that is running better given in the existing? How do we measure performance between these two?

    I use the example of HR schema:
    declare
    l_start number;
    BEGIN
    l_start:= DBMS_UTILITY.get_time;
    dbms_lock.sleep(1);
    FOR employee IN (SELECT e.last_name, j.job_title FROM employees e,jobs j 
    where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name)
    LOOP
      DBMS_OUTPUT.PUT_LINE ('Name = ' || employee.last_name || ', Job = ' || employee.job_title);
    END LOOP;
    DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    END;
    /
     
    declare
    l_start number;
    type rec_type is table of varchar2(20);
    name_rec rec_type;
    job_rec rec_type;
    begin
    l_start:= DBMS_UTILITY.get_time;
    dbms_lock.sleep(1);
    SELECT e.last_name, j.job_title bulk collect into name_rec,job_rec FROM employees e,jobs j 
    where e.job_id=j.job_id and  e.job_id LIKE '%CLERK%' AND e.manager_id > 120 ORDER BY e.last_name;
    for j in name_rec.first..name_rec.last loop
      DBMS_OUTPUT.PUT_LINE ('Name = ' || name_rec(j) || ', Job = ' || job_rec(j));
    END LOOP;
    DBMS_OUTPUT.put_line('total time: ' || to_char(DBMS_UTILITY.get_time - l_start) || ' hsecs');
    end;
    /
    In this code, I put a timestamp in each block, but they are useless, since they both launched virtually instantaneous...

    Best regards
    Val

    (1) bulk fired fresh primary use is to reduce the change of context between sql and pl sql engine.
    (2), you should always use LIMIT when it comes with bulk collect, this does not increase the load on the PGA.
    (3) and the ideal number of BOUNDARY lines is 100.

    Also if you really want to compare performance improvements between the two different approaches to sql pl try to use the package of runstats tom Kyte

    http://asktom.Oracle.com/pls/Apex/asktom.download_file?p_file=6551378329289980701

  • Get help in BULK COLLECT IN the treatment

    the following gives me PLS-00302 error: component 'R_MDATA' must be declared

    ---------------------------------------------

    declare

    error_1555 exception;

    pragma exception_init (error_1555,-1555);

    number num.

    -set the record

    TYPE RJ_RECORD is RECORD (r_rowr_mdata BLOB ROWID);

    -set the table based on the file type

    TYPE RJ_LIST_T IS TABLE OF RJ_RECORD

    INDEX BY PLS_INTEGER;

    -our structure will be bulk collect into

    l_List RJ_LIST_T;

    sql_str varchar2 (2000);

    cursor ovs_tab is SELECT table_name from user_tables;

    Start

    for c_rec in ovs_tab LOOP

    sql_str: = ' select rowid, m_data of ' | c_rec.table_name;

    run immediately sql_str

    COLLECTION in BULK IN l_list;

    for indx in 1.l_list. COUNTY

    LOOP

    Start

    NUM: = dbms_lob.instr (l_list. R_MDATA(indx), hextoraw ('889911')) ;  -He does not like r_mdata

    exception

    When error_1555 then

    -Insert in the values of corrupted_lob_data (l_list.rj_rowid (indx), c_rec.table_name);

    -commit;

    dbms_output.put_line (' corrupt tab = ' | c_rec.table_name);

    end;

    END LOOP;

    end loop;

    end;

    /

    change l_list.r_mdata (indx)

    TO

    .r_mdata l_list (indx)

    Each table has a column named m_data?

  • bulk collect into with limit

    Hi all
    I was reading [http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:5918938803188] of Tom Kyte site on bulk collect within limits. The code uses the % notfound cursor to exit the recovery loop. What I do in this situation is using exists, method of table rather than cursor attribute.
    create or replace procedure p1 is
    type num_list_type is table of number index by pls_integer;
    num_list num_list_type;
    
    cursor c1 is select temp from test;
    
    begin
    open c1;
    loop
      fetch c1 bulk collect into num_list limit 2;
      if num_list.exists(1)=false then
        exit;
      end if;
      for i in num_list.first..num_list.last 
      loop
        dbms_output.put_line(num_list(i));
      END LOOP;
    end loop;
    
    end;
    Since when I do this:
    exit wen c1%notfound  
    It will close when the cursor retrieves only less than the limit, leaving a few rows. If the code works properly.
    Question:
    1. is the Exit statement properly, is there another way (I'm a little skeptical because I'm not using the cursor)?
    2 How to decide on the size limit based on what we have in the hardware settings and oracle? All of the guidelines?
    3 - is the best practice when it comes with the cursor and several lines that still use bulk collect into?

    Best regards
    Val

    Valerie Debonair wrote:
    Hi all
    I was reading [http://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:5918938803188] of Tom Kyte site on bulk collect within limits. The code uses the % notfound cursor to exit the recovery loop. What I do in this situation is using exists, method of table rather than cursor attribute.

    create or replace procedure p1 is
    type num_list_type is table of number index by pls_integer;
    num_list num_list_type;
    
    cursor c1 is select temp from test;
    
    begin
    open c1;
    loop
    fetch c1 bulk collect into num_list limit 2;
    if num_list.exists(1)=false then
    exit;
    end if;
    for i in num_list.first..num_list.last
    loop
    dbms_output.put_line(num_list(i));
    END LOOP;
    end loop;
    
    end;
    

    Since when I do this:

    exit wen c1%notfound  
    

    It will close when the cursor retrieves only less than the limit, leaving a few rows. If the code works properly.
    Question:
    1. is the Exit statement properly, is there another way (I'm a little skeptical because I'm not using the cursor)?
    2 How to decide on the size limit based on what we have in the hardware settings and oracle? All of the guidelines?
    3 - is the best practice when it comes with the cursor and several lines that still use bulk collect into?

    Best regards
    Val

    Hello

    1. Yes, in above code statement EXIT will work correctly. The other way is % NOTFOUND CURSOR attribute usage.
    2. There is no precise way to decide the size limit.
    3 depends on number of records. If you have a lot of records always use LIMIT that improves performance.

    After reading the link that was posted by Blu, I am to edit this post.

    1. do not use CURSOR attribute when you use collections within a cursor. Use methods of collection such as COUNT or EXIST etc.

    @Blu,

    Thanks much for the link.

    Thank you
    Suri

    Published by: Suri on January 26, 2012 20:38

  • objects and the record type

    Hello experts.

    create type emp2_obj is object
    (
    objno number
    ,
    objname varchar2
    (20),
    objdept number
    );

    create type emp2_objarr is table of emp2_obj;

    and

    type emp2_rec is record
    (
    recno number
    ,
    recname varchar2
    (20),
    recdept number
    );

    create type emp2_recarr is table of emp2_rec ;

    Objects and types of records are created similar and have the same similar object.  Is it only advisable to use registration type if you use a collection in PL/SQL type... Please advice

    user13328581 wrote:

    the only reason why I ask is because he asked during an interview

    -Objects and the types of records are created similar and have the same similar object.  Is it only advisable to use registration type if you use a collection in PL/SQL type... Please advice

    Not at all.  You can use record types used with collection types outside.  They are a group concept.  If you want to group a set of values together (including fields), you can use a record.  It may be convenient.  You can send documents around proc and functions.

    Be aware that the record types are limited to procedures, functions, anonymous blocks and packages (i.e. PL/SQL), while the types of objects are stored in the dictionary of data as a separate Oracle objects (they can also have methods, the records may not).  Object types can be used in SQL, as said sol.beach types of records (outside of the intelligent pipeline situations) is for PL/SQL.

  • How to use the record type as a parameter IN PL/SQL procedure or package

    Hi people,

    I need help on the record as the OUT parameter type. I am able to get out a single line as a parameter, but not getting do not idea how to get a multi ranks as output parameter.

    I have the code that works very well for a single line. Please see CODE1.

    But when I try to get several lines, I'm failing to do. Please see the CODE2. I get the error of compilation as


    Error report:

    ORA-06550: line 11, column 35:

    PLS-00487: Invalid reference to the variable "P_NAME.

    ORA-06550: line 11, column 1:

    PL/SQL: Statement ignored

    06550 00000 - "line %s, column % s:\n%s".

    * Cause: Usually a PL/SQL compilation error.

    Any help or a sample execution of script would be really useful.

    Thanks in advance.

    YZ

    --------------------------CODE1------------------------------------------

    -------------------------Package Spec-------------------------------

    CREATE OR REPLACE

    PACKAGE xx_sample_pkg as

    --

    Xx_sample_table_rectype RECORD TYPE IS

    (p_name varchar2 (40))

    number of p_emp_id

    );

    PROCEDURE xx_sample_prc (xx_sample_rec1, OUT xx_sample_table_rectype);

    END xx_sample_pkg;

    ------------------------------Package Body------------------------

    create or replace

    PACKAGE xx_sample_pkg AS BODY

    --

    PROCEDURE xx_sample_prc (xx_sample_rec1 OUT xx_sample_table_rectype) IS

    BEGIN

    SELECT ename, empno

    IN xx_sample_rec1

    FROM scott.emp

    WHERE ename = 'SMITH ';.

    END xx_sample_prc;

    END xx_sample_pkg;

    -------------------------------------------Execute----------------------

    DECLARE

    l_rec_type xx_sample_pkg.xx_sample_table_rectype;

    BEGIN

    dbms_output.put_line ('xx_sample_prc appeal');

    xx_sample_pkg.xx_sample_prc (l_rec_type);

    dbms_output.put_line ('YZ' | l_rec_type.p_name |') '|| l_rec_type.p_emp_id);

    END;

    ---------------------------------------------------------------

    -------------------------CODE2-------------------------------------------

    -------------------------Package Spec-------------------------------

    CREATE OR REPLACE

    PACKAGE xx_sample_pkg as

    --

    Xx_sample_table_rectype RECORD TYPE IS

    (p_name varchar2 (40))

    number of p_emp_id

    );

    PROCEDURE xx_sample_prc (xx_sample_rec1, OUT xx_sample_table_rectype);

    END xx_sample_pkg;

    ------------------------------Package Body------------------------

    create or replace

    PACKAGE xx_sample_pkg AS BODY

    --

    PROCEDURE xx_sample_prc (xx_sample_rec1 OUT xx_sample_table_rectype) IS

    BEGIN

    SELECT ename, empno

    IN xx_sample_rec1

    FROM scott.emp;

    END xx_sample_prc;

    END xx_sample_pkg;

    -------------------------------------------Execute----------------------

    DECLARE

    l_rec_type xx_sample_pkg.xx_sample_table_rectype;

    BEGIN

    dbms_output.put_line ('xx_sample_prc appeal');

    xx_sample_pkg.xx_sample_prc (l_rec_type);

    for l_rec in 1.l_rec_type.p_name.count

    loop

    dbms_output.put_line ('YZ' | l_rec_type.p_name (l_rec) |) » '|| l_rec_type.p_emp_id (l_rec));

    end loop;

    end;

    ---------------------------------------------------------------

    bb8c573a-6ca3-4d7c-90ed-e55c2df67201 wrote:

    But now, my question would be why the record type could not be used? My understanding is missing some concept between use of type type array collection record vs. Please specify.

    Do not confuse the folder with the collection.

    SY.

  • bulk collect into after insertion?

    The INSET below works great!
        insert into GL_Interface_Control_temp
                                       (Set_Of_Books_ID
                                       ,Group_ID
                                       ,JE_Source_Name
                                       ,Interface_Run_ID)
                               values  (
                                        '2'
                                        ,10
                                        ,'TEST_SOURCE'
                                        ,'2'
                                        )
      returning ty_GLI (Set_Of_Books_ID
                       ,Group_ID
                       ,JE_Source_Name
                       ,Interface_Run_ID
                       ,0
                       ,0
                       ,null)
      bulk collect into l_GLI_Tab;
    BUT when combined with an INSERT... SELECT, as follows:
      insert into GL_Interface_Control_temp
                                       (Set_Of_Books_ID
                                       ,Group_ID
                                       ,JE_Source_Name
                                       ,Interface_Run_ID)
                              (select   gi.Set_Of_Books_ID
                                       ,GL_Interface_Control_S.nextval
                                       ,gi.JE_Source_Name
                                       ,GL_Journal_Import_S.nextval
                                from    GL_Interface_temp gi
                                where   gi.Currency_Conversion_Date <= l_Max_Rate_Date
                                and     gi.Set_Of_Books_ID  = v_Set_Of_Books_ID)
      returning ty_GLI (Set_Of_Books_ID
                       ,Group_ID
                       ,JE_Source_Name
                       ,Interface_Run_ID
                       ,0
                       ,0
                       ,null)
      bulk collect into l_GLI_Tab;
    I get the following error:
      *
    ERROR at line 15:
    ORA-00933: SQL command not properly ended
    No idea why?
    Can we not use BULK COLLECT BACK IN with an INSERT SELECT?

    P;

    I'm sorry to tell you that the return clause can only be used with the values clause.

    http://download.Oracle.com/docs/CD/E11882_01/server.112/e10592/statements_9014.htm#i2121671

    Alessandro Bye

  • concatenate the fields of the record type

    Hello

    Is it possible to concatenate the fields of the record type?, example
    declare 
     TYPE customer_sales_rectype IS RECORD
          (campo1 char(3),
          campo2  char(3),
          campo3  char(3));
    
             
      TYPE ZZZ IS RECORD (kkk customer_sales_rectype);
          x customer_sales_rectype;
         
    begin
      x.campo1:='000';
      x.campo2:='aaa';
      x.campo3:='BBB';
    end;
    I have a table
    ID_REPORT NUMBER                                   
    ID_LINE     NUMBER                                  
    DT_FILE  DATE           Y                        
    DS_LINE     VARCHAR2(2048) Y       
    My charly had more than 50 columns and unavoidable to concatenate the columns, example:
    select column001 ,
           ';' PV1,
           COL2,
           COL3
           COL4,
         ';' PV2,....ETC
    FROM MY TABLES
    I think that movement query result in a variable of type record that I would can insert in the table in the column is DS_LINE some transformatcion.

    Is it possible without using COL1 | PV1. COL2. COL3 | COL4 | PV2... etc.


    Thanks in advance
    using 9.2.02

    It's pretty easy to write a function for this. Here's a 'coffee time ': implementation

    create or replace function multi_concat
        (p_args sys.dbms_debug_vc2coll)
        return clob
    as
        rv clob;
    begin
        dbms_lob.createtemporary(rv, TRUE);
        for i in p_args.first .. p_args.last
        loop
            dbms_lob.writeappend(rv, length(p_args(i)), p_args(i));
        end loop;
        return rv;
    end multi_concat;
    /
    

    And the proof of coffee is in the dip of the ring:

    SQL> select multi_concat ( sys.dbms_debug_vc2coll ( ('Red Fish', 'Blue Fish', 1, 'Fish',2,'Fish'))
      2* from dual
    
    MULTI_CONCAT(SYS.DBMS_DEBUG_VC2COLL('REDFISH','BLUEFISH',1,'FISH',2,'FISH'))
    --------------------------------------------------------------------------------
    Red FishBlue Fish1Fish2Fish
    
    SQL> 
    

    I add a member TO_STRING function to your type and use something like the above, implement.

    You can also use the data dictionary to generate a string that connects the attributes of your type with the concatenation operator.

    Cheers, APC

  • Error in passing in the RECORD type in the API

    Gurus,

    Get the following error when I try and change from one type of RECORD in an API. I am in passage correctly?

    Any help is appreciated.

    Thank you
    -Scott



    Here is my error:

    fnd_descr_flex_col_usage_pkg.load_row
    *
    ERROR at line 21:
    ORA-06550: line 21, column 4:
    PLS-00306: wrong number or types of arguments in the call to 'LOAD_ROW '.
    ORA-06550: line 21, column 4:
    PL/SQL: Statement ignored



    Here is my anon block:

    declare
    Who_type RECORD TYPE IS
    (
    created_by NUMBER,
    CREATION_DATE DATE,
    last_updated_by NUMBER,
    last_update_date DATE,
    last_update_login NUMBER
    );
    v_who_type who_type;
    date of v_sysdate;
    Start
    Select sysdate
    in v_sysdate
    Double;
    v_who_type.created_by: = 0;
    v_who_type. CREATION_DATE: = v_sysdate;
    v_who_type.last_updated_by: = 0;
    v_who_type.last_update_date: = v_sysdate;
    v_who_type.last_update_login: = 0;
    fnd_descr_flex_col_usage_pkg.load_row
    (x_application_short_name = > 'SPL',)
    x_descriptive_flexfield_name = > 'HR_LOCATIONS ',.
    x_descriptive_flex_context_cod = > '441',.
    x_application_column_name = > 'ATTRIBUTE5 ',.
    x_who = > v_who_type,
    x_end_user_column_name = > "District."
    x_column_seq_num = > 10,
    x_enabled_flag = > 'Y ',.
    x_required_flag = > 'n',.
    x_security_enabled_flag = > 'n',.
    x_display_flag = > 'Y ',.
    x_display_size = > 50,
    x_maximum_description_len = > 50,
    x_concatenation_description_le = > 25,
    x_flex_value_set_name = > 50 characters,
    x_range_code = > ",
    x_default_type = > ",
    x_default_value = > ",
    x_runtime_property_function = > ",
    x_srw_param = > ",
    x_form_left_prompt = > "District."
    x_form_above_prompt = > "District."
    x_description = > ");

    ...

    sreese wrote:
    Tubby,

    Im not asking for your help with this error. I want to define my own FILE type that mimics the call package so I can spend in my own variables.

    Pretty sure I've described previously, there was a specific question with the answer that you do not understand?

    >

    The problem with this type of recording is that it contains all the 'who' columns that the application requires. When it is called from a package within the schema, the package has no difficulty arising from these data. When you call the package from an anon block, I have to pull my own values.

    You did before declaring a LOCAL record type, then you need to reference to the PACKAGE of type folder, as I showed you... it makes you EF values even as you were in your first post.

    I want to define the RECORD type of the manner in which it has been set to 'fnd_flex_loader_apis.who_type', but using my own variable and passing in the parameter. Make sense?

    Thank you
    Scott

    Hope that helps.

Maybe you are looking for