DB2 compound sql giving delimiter error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • isubodh
    New Member
    • Jul 2013
    • 2

    #1

    DB2 compound sql giving delimiter error

    I am on DB2/AIX64 9.5.8
    The script is below
    Code:
    DB=test
    SCHEMA=mine
    SCRIPT=`basename $0`
    . ~/db2profile
    db2 -tv +p <<EOQ
    UPDATE COMMAND OPTIONS USING s ON;
    UPDATE COMMAND OPTIONS USING z ON $PWD/$SCRIPT.$DB.log;
    connect to $DB;
    
    Begin Atomic
            For credit_rows as
                select cacc.CUST_ID as caid
                from  $SCHEMA.SS_CUSTACC_B cacc
                where (cacc.CREDIT_NUM between 950 and 999
                or  cacc.CREDIT_NUM between 1950 and 1999 )
                   and cacc.TU_ENABLE_IND = 'Y'
                   order by cacc.CUST_NUM
            Do
                update $SCHEMA.SS_CUSTACC_B ca
                set ca.CREDIT_NUM = 1
                where ca.CUST_ID = credit_rows.caid; 
            End For;
    End     
    EOQ
    When I run this I get error
    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 "D = credit_rows.cai d". Expected tokens may include: "<delim_semicol on>". LINE NUMBER=22. SQLSTATE=42601


    Not sure what delimiter should I set to fix this.
    Can you please help.
  • isubodh
    New Member
    • Jul 2013
    • 2

    #2
    Finally I sort it out using a terminator smart tags as below.

    Code:
    --#SET TERMINATOR @
     Begin Atomic
             For credit_rows as
    -- snip code --- 
                 where ca.CUST_ID = credit_rows.caid; 
             End For;
     End @
    --#SET TERMINATOR ;
    I was trying to use the smart tag SET DELIMITER but TERMINATOR worked. So if anyone has solution using DELIMITER please post a relpy.

    cheers

    Comment

    • Shashank1984
      New Member
      • Jul 2007
      • 26

      #3
      The supported way of calling statements like 'BEGIN ATOMIC END', 'CREATE PROCEDURE', 'CREATE TRIGGER' from CLP is to define an alternate termination character other than the default termination character(;)

      Ref : http://pic.dhe.ibm.com/infocenter/db...69%6e%65%22%20

      Comment

      Working...