oracle - pl/sql insert multiple rows using for loop variable seen as not declared -


i've following anonymous block declared variable:

declare tst number(9) :=0; begin vcnt in 1..1000 loop tst := vcnt; insert samp_tab values(:tst,'a'); end loop; end; 

i want insert table value of counter row in every cycle of loop, using variable counter value in insert value. when execute code, oracle returns:

 bind variable "tst" not declared  anonymous block completed. 

how fix code?

if want refer local variable, don't prefix colon

declare   tst number(9) :=0; begin   vcnt in 1..1000   loop     tst := vcnt;     insert samp_tab values(tst,'a');   end loop; end; 

this assumes samp_tab table 2 columns, first being numeric , second being string. practice, want list columns inserting explicitly-- makes code more self-documenting , means won't create errors later if adds new columns table later have default values.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -