• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use For loop in SQL query

 
Suraj Jadhav
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to Insert rows into database, for that I am trying to use WHILE/FOR loop in SQL. The query snippet that I am using is as below.



Database Version: IBM DB2 9.7

I am using Toad 4.0 as SQL editor for executing the command. The problem is that I am getting various syntax errors.

Does any body know how to do insertion using While/For loop?

Thanks in advance.
Suraj




 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you trying to write a database procedure/function?
or is this inside toad?

can you tell us the syntax errors you are getting as that would greatly help us.
 
Suraj Jadhav
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have not written any function/procedure for this as I just wanted to insert the data for testing purpose. I am getting following error.

Error: DB2 Database Error: ERROR [42601] [IBM][DB2/NT] SQL0104N An unexpected token "END-OF-STATEMENT" was found following "er Integer Default 0". Expected tokens may include: "<psm_semicolon>". LINE NUMBER=1. SQLSTATE=42601

I even tried removing the declaration line but still no luck.

Thanks
Suraj
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after my 5 mins of googling, I have spotted this difference in the examples to your example they begin

BEGIN ATOMIC


Nope I was wrong, the atomic is just telling it how to roll back.

Your syntax looks perfect so something in toad is not happy, is my guess.
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're trying to execute it as pure SQL.

You need to create the stored procedure, then execute it using SQL.

WP
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic