variable for table name in stored procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ishakteyran
    New Member
    • Jul 2007
    • 8

    variable for table name in stored procedure

    hi all;
    i am using a db2 database on RAD platform and need to generate tables (names of them will be determined by users.) so i thought i can do this with a stored procedure which takes the table name as input. but i live difficulty with usimg the table name ..

    create procdure proc1 (IN inName VARCHAR(30))
    BEGIN
    Create TAble inName(this is table name variable) (and the rest of the table definition..)
    END

    the code snippet above did not work then i tried to use the input variable after @ character but it did not work also..

    any suggestions to achieve this?

    thank you all.. :)
  • sakumar9
    Recognized Expert New Member
    • Jan 2008
    • 127

    #2
    You can try following code:

    Code:
    CREATE PROCEDURE  proc1 (IN inName VARCHAR(30))
    BEGIN
        DECLARE param VARCHAR(1000);
    
            SET param = 'Create Table ' || inName || '(a INT)';
    
            PREPARE s1 FROM param;
            EXECUTE s1;
    
    END@

    Regards
    -- Sanjay

    Comment

    Working...