Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2010
    Posts
    26

    Unanswered: Error while inserting thru shell script

    Hi,
    When i execute the below comand on UNIX command prompt it works fine
    pq5 @ /home/qshbnn9/EDDq$ db2 -x "insert into PQ5.INCNT values(328,'EDD',8838,'1',20)"
    DB20000I The SQL command completed successfully.
    But I put this statement in a flat file
    flat file 1.txt contains three lines like
    db2 connect to dq5d
    db2 -x "insert into PQ5.INCNT values(328,'EDD',8838,'1',20)"
    db2 connect reset

    I executed from shel script like below
    while read stmt
    do
    $stmt
    done < 1.txt

    I get the below error
    Database Connection Information

    Database server = DB2/AIX64 9.5.4
    SQL authorization ID = PQ5
    Local database alias = DQ5D

    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 ",'EDD',
    8838,'1',20)"". Expected tokens may include: "JOIN <joined_table>".
    SQLSTATE=42601
    DB20000I The SQL command completed successfully

    Please help on this to resolve it.

    Thanks
    Surjya

  2. #2
    Join Date
    Jan 2010
    Posts
    335
    If you change your script to
    db2 -vx "insert into PQ5.INCNT values(328,'EDD',8838,'1',20)"
    you would see the following output:
    "insert into PQ5.INCNT values(328,'EDD',8838,'1',20)"
    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 "'EDD',
    8838,'1',20)"". Expected tokens may include: "JOIN <joined_table>".
    SQLSTATE=42601

    The Quotes are part of the SQL-Statement which causes the error. If you remove the quotes in the flat-file it works.

    Imho the better way is to change your flat-file to
    connect to dq5d
    insert into PQ5.INCNT values(328,'EDD',8838,'1',20)
    connect reset
    and use db2 -f 1.txt

    or

    connect to dq5d;
    insert into PQ5.INCNT
    values(328,'EDD',8838,'1',20);
    connect reset;

    with db2 -tf 1.txt if the statements are longer than 1 row.

    nvk

  3. #3
    Join Date
    Jan 2010
    Posts
    26
    Thanks a lot, it works for me.

Posting Permissions

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