Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2014
    Posts
    2

    Unanswered: SQL block from the CLI?

    Hi:

    I'm quite new to DB2 but had assumed that it would be possible to write a SQL block and run it from the CLI.

    Specifically, when I first ran in to trouble I dumb'ed my test script down to just the following:

    Code:
    begin
    declare myvar integer
    end
    and saved this as test.sql. Here is what I get when I try to run this from the CLI:

    Code:
    $ db2 -stvf test.sql
    begin
    declare myvar integer
    DB21034E  The command was processed as an SQL statement because it was not a valid Command Line Processor command.  During SQL processing it returned: SQL0104N  An unexpected token "END-OF-STATEMENT" was found following " declare myvar integer".  Expected tokens may include:  "<psm_semicolon>".  LINE NUMBER=2.  SQLSTATE=42601
    This seems pretty basic, so I can only assume that I've got the wrong idea somehow. Are variables only possible in stored procedures? Oh, I'm on DB2 V10.1.3 if that matters (on Linux).

    I'm quite happy to be sent to read docs, but I've exhausted my googling on this one.

    Thanks,
    Paul

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Try this:
    Code:
    begin
    declare myvar integer;
    end@
    Execute with:
    Code:
    db2 -td@ -svf test.sql
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Feb 2014
    Posts
    2
    I suspected it had something to do with how the CLI was interpreting the block. This made sense. My script is all done now, thanks Marcus!

Posting Permissions

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