VARRAY and record Types

Hello


I have types to be defined but do not know how to approach to it


Type name: ASSET_REC_TYPE

Classification: OBJECT

Contains the following columns

Column

Data type

ASSET_NUMBER

VARCHAR2 (120)

Type name: ASSET_REC_TBL

Classification: VARRAY (1000)

On: ASSET_REC_TYPE


How to set the VARRRAY on the top type Record. Please, any help will be necessary

CREATE OR REPLACE TYPE ASSET_REC_TYPE IS OBJECT (asset_numberVARCHAR2(120));

CREATE OR REPLACE TYPE ASSET_REC_TBL IS VARRAY(1000) of ASSET_REC_TYPE;

Gerard

Tags: Database

Similar Questions

  • 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.

  • Using record type and Table and sorting out output

    I use a record type

    • TYPE results_rec is RECORD)
    • table_ varchar2 (40),
    • (1) tank Create_: = '-'.
    • (1) tank read_: = '-'.
    • Char (1) warning: = '-'.
    • Delete_ char (1): = '-');

    and a table of this record

    • Results_tab TYPE IS TABLE of results_rec INDEX OF VARCHAR2 (40);
    • tab_res results_tab;
    • table_indx varchar2 (40);

    And when I add values to this table, I do like that, for example, an entry of functioning drop in table:

    • v_check: = instr2 (v_string_fnc, 'DROP');
    • If v_check > 0 then
    • counter: = counter + 1;
    • delete_flag: = ';
    • v_check: = instr2 (v_string_fnc, 'TABLE', v_check);
    • v_check: = v_check + 6;
    • result_table: = substr (v_string_fnc, v_check);
    • rest_string: = result_table;
    • result_table: = substr (result_table, 0, instr (result_table, ' '));
    • result_table: = rtrim (result_table);
    • table_indx: = result_table;
    • tab_res (table_indx) .table_: = result_table;
    • tab_res (table_indx) .delete_: = delete_flag;

    and similar to all other interventions, but how to get while dbms_output.

    For table_indx in? and now, table_indx is a string value, how to get all the in the output, sorted by ASC .table_ tab_res (table_indx) string?

    Well, tab_res. FIRST returns the first index of tab_res which is a VARCHAR2, while an index of the loop is supposed to be a NUMBER.

    You cannot use FOR... LOOP element, you use WHILE... LOOP, for example

    SQL > SET SERVEROUTPUT ON;

    SQL > DECLARE

    2 TYPE Results_rec IS RECORD)

    3 table_ VARCHAR2 (40),

    4 create_ VARCHAR2 (1): = '-'.

    5 read_ VARCHAR2 (1): = '-'.

    6 warning VARCHAR2 (1): = '-'.

    7 delete_ VARCHAR2 (1): = '-');

    8

    9 results_tab TYPE IS an ARRAY OF results_rec

    10-VARCHAR2 INDEX (40);

    11

    12 results results_tab;

    13

    14 variable_name VARCHAR2 (40);

    BEGIN 15

    16 results ('name_a') .table_: = 'name_a ';

    17 results ('name_a') .create_: = 'x '.

    18

    19 results ("name_b') .table_: = 'name_b;

    20 results ("name_b') .update_: = 'x '.

    21

    22 results ("name_c") .table_: = "name_c";

    23 results ("name_c") .read_: = 'x '.

    24 results ("name_c") .delete_: = 'x '.

    25

    26 nom_de_variable: = results. FIRST;

    27

    28 variable_name IS NOT NULL LOOP

    29

    30 DBMS_OUTPUT. PUT_LINE)

    31 results (variable_name) .table_ | ' ' ||

    32 results (variable_name) .create_ |

    33 results (variable_name) .read_ |

    34 results (variable_name) .update_ |

    35 results (variable_name) .delete_);

    36

    nom_de_variable 37: = results. NEXT (variable_name);

    38 END LOOP;

    39 END;

    40.

    name_a x-

    name_b - x-

    name_c - x - x

    PL/SQL procedure successfully completed.

    SQL >

  • How to declare a formal parameter of a record type and access function?

    declare

    CURSOR c_cur_minc IS SELECT FAMID, MEMBNO, AMTFED, GOVRETX, PRIVPENX, RRRDEDX, GROSPAYX, SLTAXX, SALARYX, SALARYBX OF MINC WHERE FAMID IN (SELECT FAMID FROM MEMBERS WHERE AGE > = 14 AND MINC.) FAMID = MEMBERS. FAMID AND MINC. MEMBNO = MEMBERS. MEMBNO);

    number of v_limit: = 50;

    TYPE minc_rec is RECORD (FAMID MINC. FAMID % TYPE,
    MEMBNO MINC. MEMBNO % TYPE,
    AMTFED MINC. AMTFED % TYPE,
    GOVRETX MINC. GOVRETX % TYPE,
    PRIVPENX MINC. PRIVPENX % TYPE,
    RRRDEDX MINC. RRRDEDX % TYPE,
    GROSPAYX MINC. GROSPAYX % TYPE,
    SLTAXX MINC. SLTAXX % TYPE,
    SALARYX MINC. SALARYX % TYPE,
    SALARYBX MINC. SALARYBX % TYPE);

    TYPE minc_rec_type is TABLE OF THE minc_rec;
    minc_rec_type_tbl minc_rec_type;

    Start

    OPEN c_cur_minc.
    LOOP
    Get the c_cur_minc COLLECT LOOSE minc_rec_type_tbl LIMIT v_limit;
    WHEN minc_rec_type_tbl EXIT. COUNT = 0;
    BECAUSE me in minc_rec_type_tbl. FIRST... minc_rec_type_tbl. LAST
    LOOP
    IF (chk_notnull_blank (minc_rec_type_tbl (i). AMTFED)) THEN
    Setting a DAY MINC SET ANFEDTX = - 2E14 WHERE FAMID = minc_rec_type_tbl (i) .famid AND MEMBNO = minc_rec_type_tbl (i) .membno;
    end if;

    IF (chk_notnull_blank (minc_rec_type_tbl (i). GOVRETX)) THEN
    Setting a DAY MINC SET GOVRETX = - 2E14 WHERE FAMID = minc_rec_type_tbl (i) .famid AND MEMBNO = minc_rec_type_tbl (i) .membno;
    end if;

    END LOOP;
    END LOOP;
    CLOSE C_cur_minc;
    END;


    FUNCTION chk_notnull_blank (?) return a Boolean value is
    Start
    If (? is NOT NULL and? as (-8E14,-7E14,-6E14,-5E14,-4E14,-3E14,-2E14,-1E14,-1E9)) then
    RETURN TRUE;
    on the other
    RETURN FALSE;
    end if;
    END chk_notnull_blank;


    end;

    My question is how to declare a formal FastInventory in a fuction where, in the past the current parameter is a variable of type record type number value?

    Published by: kumar73 on September 21, 2010 11:22

    Published by: kumar73 on September 21, 2010 11:23

    This is a simple function

    CREATE OR REPLACE FUNCTION chk_notnull_blank(inparm IN NUMBER) RETURN NUMBER IS
    BEGIN
    if ( inparm  is NOT NULL and inparm  in ( -8E14, -7E14, -6E14, -5E14, -4E14, -3E14, -2E14, -1E14, -1E9 )) then
    RETURN TRUE ;
    else
    RETURN FALSE ;
    end if;
    END chk_notnull_blank;
    

    Thank you
    AJ

  • How to create a type of record and a pl/sql table of this record type in the database

    Hello
    I want to create a record type, and then I want to create a PL/SQL table in the oracle 9i database.
    I did block PL/SQL.
    But when I'm doing it in the database it throws me a few errors.
    Could you please tell me how can I do?

    Concerning

    user576726 wrote:
    Hello
    I want to create a record type, and then I want to create a PL/SQL table in the oracle 9i database.
    I did block PL/SQL.
    But when I'm doing it in the database it throws me a few errors.
    Could you please tell me how can I do?

    Concerning

    RECORD type is only supported in PL/SQL for SQL, you must use the OBJECT type.

  • Object type and a Type of record

    What is the difference between the type and the type of recording?
    TYPE OBJ_TYP IS OBJECT (
    ENAME VARCHAR2(30),
    EAGE NUMBER(2),
    ESAL NUMBER
    )
    
    TYPE REC_TYP IS RECORD (
    ENAME VARCHAR2(30),
    EAGE NUMBER(2),
    ESAL NUMBER
    )
    The two even looks like me and just I see the difference in keyword. Is there a functional difference to hide?

    PLS, excuse my stupidity.

    Sunny

    The first is a type of object oriented class. It can have custom constructors, methods and can be used as a type of SQL data in the SQL engine - even as the data type for a SQL column in a table SQL.

    This one is a pure (and clear) record structure - similar to the structure record in Pascal/Ada, or as the struct in C/C++. It can only be used in the engine of PL.

  • How to find the audio and recording mixers

    Cannot find Audio Mixers and recording in Windows 7 as I had XP

    My Medion computer purchased recently does not appear to have full audio mixer for volumes or a similar mixer to record levels as I have already in Win XP.

    Is it possible to reproduce pages of mixer teas? I would be grateful for any help on this problem.

    TIA Mike

    Cool Edit 2000 (compatibility issue)

    Hello

    The mixer similar to that of Windows XP volume has been removed in Windows 7.

    Windows 7 has its own volume mixer. Check this link for more information:

    Adjust the sound level on your computer:
    http://Windows.Microsoft.com/en-us/Windows7/adjust-the-sound-level-on-your-computer

    Cool edit 2000 is not compatible with Windows 7. Cool Edit was taken over by Adobe, a few years ago and renamed Adobe Audition. The manufacturer
    offers a paid upgrade to the software.

    Check this link for more information:
    http://www.Microsoft.com/Windows/compatibility/Windows-7/en-us/details.aspx?type=software&p=cool%20Edit%20PRO&v=Adobe&UID=2&pf=0&PI=
    6 & s = Cool % 20Edit % 202000 & os 32-bit =

    Kind regards
    Amal-Microsoft Support.
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • record type

    Hi all

    create the table wages (a number;

    b the number);

    --=================================================

    declare

    type record_salary is record

    (rec_salary % rowtype salary,

    number of rec_num);

    type type_salary_tab is table of the record_salary

    index by pls_integer;

    tab_rec type_salary_tab;

    Start

    Select a, b, sum (b)

    bulk collect into tab_rec

    salary;

    end;

    get an error: expression tab_rec in the list is of the wrong type...

    IF I can create the folder table, and I'm not bulk collect into it so that it uses for?

    Thanks in advance

    Hello

    Please try the below.

    DECLARE

    Record_salary RECORD TYPE IS

    (

    rec_salary NUMBER,

    rec_num NUMBER,

    NUMBER OF SUM_OF_REC

    );

    TYPE type_salary_tab IS TABLE OF THE record_salary

    INDEX BY PLS_INTEGER;

    tab_rec type_salary_tab;

    BEGIN

    SELECT a, b, SUM (b)

    LOOSE COLLECTION tab_rec

    ON treatment

    GROUP BY A, B;

    DBMS_OUTPUT. Put_line (tab_rec. COUNT);

    END;

    1 group by is missing

    2 guy's got that two elements

    3. has changed the type of line to the number in the type declaration

    Kind regards

    Cool

  • Record Type in need help package tests

    Hello

    Please can you help me in the record Type of tests that I defined as:

    I said record Type in the package TEST_PART_PKG

    CREATE OR REPLACE PACKAGE TEST_PART_PKG AS

    TYPE req_line_rec_type () IS RENDERING

    PART_NUMBER VARCHAR2 (100),

    part_line_num NUMBER,

    part_name VARCHAR2 (100),

    part_po_number VARCHAR2 (100),

    un_number NUMBER,

    part_class VARCHAR2 (20).

    part_org_name VARCHAR2 (50));

    TYPE req_line_tbl IS TABLE OF THE req_line_rec_type

    INDEX OF DIRECTORY;

    PROCEDURE update_part_line)

    IN OUT NOCOPY p_req_line_tbl req_line_tbl,

    p_init_msg IN VARCHAR2,

    p_req_line_tbl_out OUT NOCOPY req_line_tbl,

    p_req_line_err_tbl OUT NOCOPY req_line_tbl,

    p_submit_approval IN VARCHAR2,

    x_return_status OUT NOCOPY VARCHAR2,

    x_error_msg OUT NOCOPY VARCHAR2,

    p_commit IN VARCHAR2);

    END;

    I want to test the procedure in the package passing variables but how to approach to it?

    I want to call the procedure packaged using:

    DECLARE

    BEGIN

    TEST_PART_PKG. update_part_line

    END;

    v_req_line_out and v_req_line_err are the parameters, so they do not need initialization, just definition what is the procedure to put something that is.

    We can only guess the purpose of these two parameters. Maybe you need to separate the records updated the destination of those that out wrong for further treatment table and that you are able to present a table of rows to update the destination table, the two parameters must be tables of rows as in general, more a single record can be the source of updated and more than one record can mistake.

    Concerning

    Etbin

  • Return the record type


    Hello

    I have a requirement of the company, where I need to return a record type (OUT parameter) for environment call based on the given input value.

    Suppose that if the value is correct and corresponding record is found in the table then the return values for this key entry. If matching record is found, then return the exception to the calling environment.

    To do this, I created an example of test table and populated records.

    create table plch_test(dept_id number,dept_name varchar2(50),cost_centre number);
    insert into plch_test values(10,'SALES',1010);
    insert into plch_test values(20,'FINANCE',2010);
    insert into plch_test values(30,'MKTG',3010);
    
     
    SQL> select * from plch_test;
       DEPT_ID DEPT_NAME                                          COST_CENTRE
    ---------- -------------------------------------------------- -----------
            10 SALES                                                     1010
            20 FINANCE                                                   2010
            30 MKTG                                                      3010
    
     
     
    

    I wrote a simple block and gave a valid key dept_id (10 in this case) to display costcentre for this dept_id and dept_name I said tow types of records, one for valid record and another exception

    
    

    SQL> DECLARE 
      2  TYPE rec_dept IS RECORD(dept_name varchar2(50),cc number);
      3  l_rec_dept rec_dept;
      4  TYPE rec_exception IS RECORD(err_code number,error_message varchar2(300));
      5  l_rec_exception rec_exception;
      6  BEGIN
      7  SELECT dept_name,cost_centre
      8  INTO l_rec_dept
      9  FROM plch_test
     10  where dept_id=10;
     11  dbms_output.put_line('DEPT_NAME'||' '||l_rec_dept.dept_name||' '||'COSTCENTRE'||' '||l_rec_dept.cc);
     12  EXCEPTION WHEN NO_DATA_FOUND THEN
     13  l_rec_exception.err_code:=sqlcode;
     14  l_rec_exception.error_message:=sqlerrm;
     15  dbms_output.put_line(l_rec_exception.err_code||' '||l_rec_exception.error_message);
     16  END;
     17  .
    SQL> /
    DEPT_NAME SALES COSTCENTRE 1010
    PL/SQL procedure successfully completed.
    SQL> 
    
     
    

    Now for invalid dept_id and expose the message by using exception record type I stated.

    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2  TYPE rec_dept IS RECORD(dept_name varchar2(50),cc number);
      3  l_rec_dept rec_dept;
      4  TYPE rec_exception IS RECORD(err_code number,error_message varchar2(300));
      5  l_rec_exception rec_exception;
      6  BEGIN
      7  SELECT dept_name,cost_centre
      8  INTO l_rec_dept
      9  FROM plch_test
     10  where dept_id=40; --Invalid --data is not present
     11  dbms_output.put_line('DEPT_NAME'||' '||l_rec_dept.dept_name||' '||'COSTCENTRE'||' '||l_rec_dept.cc);
     12  EXCEPTION WHEN NO_DATA_FOUND THEN
     13  l_rec_exception.err_code:=sqlcode;
     14  l_rec_exception.error_message:=sqlerrm;
     15  dbms_output.put_line(l_rec_exception.err_code||' '||l_rec_exception.error_message);
     16* END;
    SQL> /
    100 ORA-01403: no data found
    PL/SQL procedure successfully completed.
    
    

    Now as you can see I need to include this point in a procedure with an input parameter and output must be a record types which will return

    rec_dept if it becomes a key input valid or an exception if she meets a key not valid.

    
    CREATE PROCEDURE test_prc IS(p_in_dept_id IN plch_test.dept_id,p_output ??????
    DECLARE 
    TYPE rec_dept IS RECORD(dept_name varchar2(50),cc number);
    l_rec_dept rec_dept;
    TYPE rec_exception IS RECORD(err_code number,error_message varchar2(300));
    l_rec_exception rec_exception;
    BEGIN
    BEGIN
    SELECT dept_name,cost_centre
    INTO l_rec_dept
    FROM plch_test
    where dept_id=p_ind_dept_id;
    RETURN l_rec_dept;
    EXCEPTION WHEN NO_DATA_FOUND THEN
    l_rec_exception.err_code:=sqlcode;
    l_rec_exception.error_message:=sqlerrm;
    RETURN l_rec_exception;
    END;
    dbms_output.put_line('DEPT_NAME'||' '||l_rec_dept.dept_name||' '||'COSTCENTRE'||' '||l_rec_dept.cc);
    END;
    

    Hope that the explanation above help in imposes the requirement

    Kind regards

    Claudy kotekal

    Return a record which can mean two things is complicated; I'm not an experienced myself pl/sql developer, but this looks like a craft.

    The idea of exceptions under Sir Thomas of Kyte, is that any treatment must be stopped; You should RAISE an exception to the appellant so that he can figure out what to do with it.  What you are saying, this is an exception, but is not a little, cos it's okay, I'll just keep but I will go back to the appellant in any way, but the appellant shall include this registration type is - would it be a record representing a row of the table, or it might be an exception... yuck.

    (a) is it really an exception

    (b) what do you do with it? You he could log into a table, you could write to a file, you can display an error message on the screen

    But really, it's weird to want to pass an exception as return value.

    These are all considerations of design, not really anything to do with the pl/sql language in itself.

    But hard, if you send a record type a successful being found, registration-based stick to it and don't use it to return a record; do not try to do double duty with her flipping something else.  Just save the message put in a table, or print it to the console, or what you want to do with; but as I said, the most important decision is, is this really an exception. And is based on the data model and the expectations of cleanliness of the data etc.

    Think about how you call built-in functions. If you send garbage to a built-in function it does not return successfully, leaving you to figure out whether he succeeded or not by inspecting the return value; It goes kaboom, something bad happened.  That's what your function should do if something bad happens, that is to say, if you get an exception, it should probably go kaboom.

  • PLS-00362: Invalid cursor return type; 'NUMBER' must be a record type

    Hello

    Having a little trouble with the following code example provided to http://www.dba-oracle.com/plsql/t_plsql_cursor_variables.htm:
      1  DECLARE
      2    TYPE t_ref_cursor IS REF CURSOR RETURN NUMBER;
      3    c_cursor  t_ref_cursor;
      4    l_row   NUMBER;
      5  BEGIN
      6    DBMS_OUTPUT.put_line('Strongly typed REF CURSOR using SCALAR type. Expect an error!');
      7    OPEN c_cursor FOR
      8      SELECT COUNT(*) cnt
      9      FROM   cursor_variable_test;
     10    LOOP
     11      FETCH c_cursor
     12      INTO  l_row;
     13      EXIT WHEN c_cursor%NOTFOUND;
     14      DBMS_OUTPUT.put_line(l_row);
     15    END LOOP;
     16    CLOSE c_cursor;
     17* END;
     18  /
      TYPE t_ref_cursor IS REF CURSOR RETURN NUMBER;
                           *
    ERROR at line 2:
    ORA-06550: line 2, column 24:
    PLS-00362: invalid cursor return type; 'NUMBER' must be a record type
    ORA-06550: line 2, column 3:
    PL/SQL: Item ignored
    In the code above, SELECT COUNT (*)... returns a NUMBER. I know it's an aggregation function, but it returns a single value.
    Why can't return a value in a column of a row in a NUMBER?
    How can I change the SQL code so that I can do this?

    Furthermore, I wonder about the use of FETCH with a count (*)... FETCH is supposed to fetch the next row... How it works when you select an aggregate as County?

    Thank you very much
    Jason

    >
    TYPE t_ref_cursor IS REF CURSOR RETURN NUMBER;
    *
    ERROR on line 2:
    ORA-06550: line 2, column 24:
    PLS-00362: Invalid cursor return type; 'NUMBER' must be a record type
    ORA-06550: line 2, column 3:
    PL/SQL: Ignored Element

    In the code above, SELECT COUNT (*)... returns a NUMBER. I know it's an aggregation function, but it returns a single value.
    Why can't return a value in a column of a row in a NUMBER?
    How can I change the SQL code so that I can do this?
    >
    The exception is in line 2: your cursor statement. And the answer is in the text that you access
    >
    The return value of a strongly typed REF CURSOR must be a folder that can be defined using % TYPE % ROWTYPE attributes or record structure.
    >
    You said the CURSOR to return a NUMBER. And as the text says, he must be a 'record '.
    >
    Furthermore, I wonder about the use of FETCH with a count (*)... FETCH is supposed to fetch the next row... How it works when you select an aggregate as County?
    >
    As you said already FETCH retrieves the next line, if any. A query is a request is a request. It returns a result set. A query that uses aggregates returns a result set. A query that does not aggregate returns a result set.

    Your simple COUNT (*) SELECT query returns a result set that consists of a LINE and a line a ONE COLUMN of type NUMBER. Although there is only one column in the result set, what is returned is a RECORD or a LINE. That's why you have to report your data cursor return type a document using the % ROWTYPE or % TYPE attributes or a record structure.

  • Manufacturers of record Type in packages

    I'm having trouble getting this error. Here is an example of my code:
    create or replace
    PACKAGE MyPackage AS
      TYPE MyPerson IS RECORD ( "NAME"  VARCHAR2(255 CHAR) );
      FUNCTION GetPerson RETURN MyPerson;
    END MyPackage;
    create or replace
    PACKAGE BODY MyPackage AS
      FUNCTION GetPerson RETURN MyPerson
      AS
        John MyPerson := MyPerson('John');
      BEGIN
        RETURN John;
      END GetPerson;
    END MyPackage;
    After executing these separately, I get the following errors when executing the BODY of PACKAGE statement:
    Error (6,10): PL/SQL: ignored element
    Error (6.22): PLS-00222: no function with name "MYPERSON" does exist in this scope
    Error (8.5): PL/SQL: statement ignored
    Error (8,12): PLS-00320: the declaration of the type of the expression is incomplete or incorrect
    is there a particular reason, I can't use a type defined in the PACKAGE header?

    Select * from V$ Version:
    database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    "CORE 11.2.0.3.0 Production."
    AMT for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    EDIT: formatting and v$ version

    Published by: 961346 Sep 25, 2012 12:39

    Hello

    MyPerson is a record type, and it is not a collection.
    The collections have constructors.
    Not record.

    Try like this:

    create or replace
    PACKAGE BODY MyPackage AS
     FUNCTION GetPerson RETURN MyPerson
     AS
       John MyPerson;
    
     BEGIN
      john.name := 'John';
       RETURN John;
     END GetPerson;
    END MyPackage;
    

    Kind regards

    Peter

    Published by: Peter vd Zwan Sep 25, 2012 12:56

  • 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?

  • 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 creating service with record type as a return type

    Hi, I tried the following code to get the nth highest sal using the service and the record type.
    CREATE OR REPLACE PACKAGE pack_rec_cur AS
    TYPE rec_type IS RECORD (
     name EMP.ename%TYPE,
     sal EMP.sal%TYPE);
      END;
    The lot above is created
    CREATE OR REPLACE 
      FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
       rec pack_rec_cur.rec_type;
        CURSOR cur_rec IS
          SELECT ename,sal
            FROM emp
             WHERE sal is not null 
              ORDER BY DESC;
    BEGIN
     OPEN cur_rec;
      FOR i IN 1..n LOOP
       FETCH cur_rec into rec;
       EXIT WHEN cur_rec%NOTFOUND;
      END LOOP;
     CLOSE cur_rec;
     RETURN rec;
    END;   
    The above function is errors
    LINE/COL ERROR
    -------- ---------------------------------------
    4/7      PL/SQL: SQL Statement ignored
    7/16     PL/SQL: ORA-00936: missing expression
    SQL> 
    Could you please correct me where I am wrong

    Thank you.

    By clauase missing column name in the order. Is it ename desc?

    CREATE OR REPLACE
      FUNCTION fun_rec_cur(n INT) RETURN pack_rec_cur.rec_type AS
       rec pack_rec_cur.rec_type;
        CURSOR cur_rec IS
          SELECT ename,sal
            FROM emp
             WHERE sal is not null
              ORDER BY ENAME DESC; ---added ename
    BEGIN
     OPEN cur_rec;
      FOR i IN 1..n LOOP
       FETCH cur_rec into rec;
       EXIT WHEN cur_rec%NOTFOUND;
      END LOOP;
     CLOSE cur_rec;
     RETURN rec;
    END;   
    
    ------------
    -OUTPUT
    -----------
    
    SQL> SET SERVEROUT ON
    SQL>
    SQL> DECLARE
      2     rec            pack_rec_cur.rec_type;
      3  BEGIN
      4     rec         := fun_rec_cur (6); --you get the 6th record in order of ename desc
      5     DBMS_OUTPUT.put_line ('ename::' || rec.NAME || '  sal ::' || rec.sal);
      6  END;
      7  /
    ename::MARTIN  sal ::1250
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

Maybe you are looking for