ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

EXECUTE IMMEDIATE won't execute valid SQL command

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • EXECUTE IMMEDIATE won't execute valid SQL command

    Hi,
    I'm struggling to execute a dynamic SQL command. I wrote a small SQL command for testing purposes, which works in ACS:
    Code:
    DECLARE GLOBAL TEMPORARY TABLE SESSION.T1 (C1 VARCHAR(10));
    If I wrap the command in a EXECUTE IMMEDIATE, it fails with the SQLSTATE 42612 and SQLCODE -84. First I thought it might be the explicit naming of the library so I changed SESSION to QTEMP which gives the same error (as it should). Removing the library name also doesn't work and results in the same error. They all fail:
    Code:
    EXECUTE IMMEDIATE 'DECLARE GLOBAL TEMPORARY TABLE SESSION.T1 (C1 VARCHAR(10))';
    EXECUTE IMMEDIATE 'DECLARE GLOBAL TEMPORARY TABLE QTEMP.T1 (C1 VARCHAR(10))';
    EXECUTE IMMEDIATE 'DECLARE GLOBAL TEMPORARY TABLE T1 (C1 VARCHAR(10))';
    Then I thought that you maybe can't execute a DECLARE GLOBAL TEMPORARY TABLE command in a EXECUTE IMMEDIATE command, but according to the documentation it should work:
    EXECUTE IMMEDIATE combines the basic functions of the PREPARE and EXECUTE statements. It can be used to prepare and execute SQL statements that contain neither variables nor parameter markers.


    Am I missing something?
    Thanks in advance

  • #2
    Can you show the source code where you want to execute the DELCARE GLOBAL TEMPORARY TABLE Statement?

    It works in either way in a compound statement, i.e. the following code runs for me correctly in ACS:
    Code:
    Begin
    Execute Immediate 'DECLARE GLOBAL TEMPORARY TABLE T1 (C1 VARCHAR(10))';
    End;
    Birgitta

    Comment

    Working...
    X