Stored procedures and dynamic SQL

From: Peter Derrick <pld_at_tpg.tpg.oz.au>
Date: 1996/02/13
Message-ID: <31204C88.3EFE_at_tpg.tpg.oz.au>#1/1


Dear PL/SQL experts

We are currently developing packages for our application and have struck the following problems with procedures and dynamic SQL. Any help on the following would be much appreciated. Replies either by e-mail or to the newsgroup.

Thanks in advance

Peter Derrick

/*

        /* Here is the problem!! */
    dbms_sql.parse(cid, ?FORMAT?? , dbms_sql.v7);

        val := dbms_sql.execute(cid);   
        dbms_sql.close_cursor(cid);

EXCEPTION
   WHEN OTHERS THEN
        dbms_sql.close_cursor(cid);
                raise;

END exec_create_table_sp;
/*
  • Call format: exec exec_create_table_sp('sp_name', 'arg');
    *
  • I have tried using the exec command and using bind but
  • to no avail.
    *
  • When I make the call, I get a SQL syntax error. HELP??
    */
/* **************************************************** 
  • PROBLEM 2: creating a table within a sp by passing it a table name.
    *
  • Problem here is that although we can create the table
  • outside of this call, it gives us an error when try
  • to create it within this sp. I believe the actual error
  • is not the 'heart' of the problem and only a side effect.
    */
    CREATE OR REPLACE PROCEDURE exec_create_table_sp(tname IN VARCHAR2) AS cid INTEGER; val integer; BEGIN cid := dbms_sql.open_cursor;

    dbms_sql.parse(cid, 'CREATE TABLE ' || tname ||

                        ' (myname   varchar2(50) NOT NULL)'
                                        , dbms_sql.v7);

    val := dbms_sql.execute(cid);
    dbms_sql.close_cursor(cid);
EXCEPTION
   WHEN OTHERS THEN

        dbms_sql.close_cursor(cid);
        raise;

END exec_create_table_sp;  

/*

Call as: exec create_table('blob');

result: ORA-01031: insufficient privileges

                ORA-06512: at "TST.EXEC_CREATE_TABLE_SP", line 14
                ORA-06512: at line 1

*/ Received on Tue Feb 13 1996 - 00:00:00 CET

Original text of this message