Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2009
    Posts
    44

    Unanswered: insert row in a dynamically generated table

    hi, Is it possible in a stored procedure, to insert rows in a table that has just been created a few lines above?? I am writing a stored procedure on DB2 and it understandably gives an error on deployment that the "table u r trying to insert values into dsnt exist"

    EXECUTE IMMEDIATE 'Create table xyz(...... )'

    INSERT INTO xyz VALUES(... . .);

    I wud be grateful for any help,

    Regards

  2. #2
    Join Date
    May 2003
    Posts
    113
    Quote Originally Posted by rocker86
    hi, Is it possible in a stored procedure, to insert rows in a table that has just been created a few lines above?? I am writing a stored procedure on DB2 and it understandably gives an error on deployment that the "table u r trying to insert values into dsnt exist"

    EXECUTE IMMEDIATE 'Create table xyz(...... )'

    INSERT INTO xyz VALUES(... . .);

    I wud be grateful for any help,

    Regards
    You will need to put a 'commit' between 'CREATE TABLE' and 'INSERT'

  3. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Quote Originally Posted by rocker86
    hi, Is it possible in a stored procedure, to insert rows in a table that has just been created a few lines above?? I am writing a stored procedure on DB2 and it understandably gives an error on deployment that the "table u r trying to insert values into dsnt exist"

    EXECUTE IMMEDIATE 'Create table xyz(...... )'

    INSERT INTO xyz VALUES(... . .);

    I wud be grateful for any help,

    Regards
    You need to make the insert dynamic also:

    EXECUTE IMMEDIATE 'Create table xyz(...... )'

    execute immediate 'INSERT INTO xyz VALUES(... . .)'

    Andy

  4. #4
    Join Date
    Jul 2009
    Posts
    44
    Thanks a ton that worked..!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •