If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Error while inserting thru shell script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-10, 20:30
surjyakp surjyakp is offline
Registered User
 
Join Date: Jan 2010
Posts: 26
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
Reply With Quote
  #2 (permalink)  
Old 02-11-10, 03:38
nvk@vhv nvk@vhv is offline
Registered User
 
Join Date: Jan 2010
Posts: 294
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
Reply With Quote
  #3 (permalink)  
Old 02-11-10, 09:18
surjyakp surjyakp is offline
Registered User
 
Join Date: Jan 2010
Posts: 26
Thanks a lot, it works for me.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On