Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Table variable as IN parameter to populate a table in oracle Stored procedure

3174129Mar 16 2016 — edited Mar 16 2016

Mostly I avoid table variables as input parameters for a stored procedure. Because I do not know how to handle them, but in this case I have no other option. I have a requirement where hundreds of records will be passed on to database from Oracle Agile PLM. What I have to do is to populate a table from the input records/list. For accomplishing this I have developed an object type and then a table type out of that object type.

    CREATE OR REPLACE TYPE TEST_USER.MD_TYPE AS OBJECT

                      (QUERY_REF VARCHAR2 (1000 BYTE),

                       COL_NAME VARCHAR2 (100 BYTE),

                       COL_LENGTH VARCHAR2 (50 BYTE),

                       COL_SEQ NUMBER)

    /

    CREATE OR REPLACE TYPE TEST_USER.MD_TYPE_TABLE  AS TABLE OF  MD_TYPE

    /

Stored Procedure:

    CREATE OR REPLACE PROCEDURE SP_TEST2

    (

      P_MD_TABLE IN MD_TYPE_TABLE,

      p_success OUT number

    )

    IS

   

    BEGIN

   

      INSERT INTO MDATA_TABLE

      (

    QUERY_REF ,

                       COL_NAME ,

                       COL_LENGTH ,

                       COL_SEQ

     

      )

        SELECT  ea.*

        FROM  TABLE(P_MD_TABLE) ea;

       

        p_success :=1;

        EXCEPTION

        WHEN OTHERS THEN

        p_success := -1;

    END SP_TEST2;

The problem is I do not know how to populate the table MDATA_TABLE from the incoming data. And the procedure compiles without any errors. I have not tested this procedure.

Any help please.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2016
Added on Mar 16 2016
5 comments
8,504 views